![]() |
LINUX |
iptablesのインストール 4 Xen
*xenのファイアウォール (iptables) の設定をします
*iptables-1.4.8をソースからインストールし、設定します
*xend,xendomainsの起動の前に設定します
*ドメイン0の設定です
*make はメンテナンスマシンで行っています
**以降はコメントです
*ソースの取得、削除は省略します
*エディタ、ファイラーの操作は省略します
*ソースを展開したら説明文 (英文) を読みましょう
*Enterキーを省略します
*ログイン端末で "#" はroot、"$" は一般ユーザのプロンプトの記号です
*設定ファイルで "#" で始まる行はコメントとして解釈されます
関連サイト| :iptables-1.4.8.tar.bz2 | (http://www.netfilter.org/) |
参照ファイル
インストール環境| :OS | CentOS 5.5 |
| :kernel | linux-2.6.18-xen |
| :selinux | disabled |
| :インストール先 | |
| :作業 | /usr/src |
| :言語 | LANG=en_US.UTF-8 |
| :ユーザー | rootで実行 |
*メンテナンスの場合は一般ユーザから行います
iptables-1.4.8
旧iptablesの削除*自動起動スクリプトも削除されます
*必要なので、名前を変えて保存します
# cd /etc/init.d # cp iptables iptables-ORG && chmod 644 iptables-ORG # cp ip6tables ip6tables-ORG && chmod 644 ip6tables-ORG # rpm -e iptables iptables-ipv6
iptablesのインストール
# cd /usr/src
# tar jxvf iptables-1.4.8.tar.bz2
# chown -R root:root iptables-1.4.8
# cd iptables-1.4.8
# make distclean
# ./configure CFLAGS="-O2 -march=pentium3" \ CXXFLAGS="-O2 -march=pentium3" \ --enable-devel --enable-libipq
*CFLAGS="-O2 -march=pentium3" (CPU最適化オプション)
*CXXFLAGS="-O2 -march=pentium3" (CPU最適化オプション)
*該当しない場合は指定しない
# make 2>error.log
# make install
# cd ..
# tar jcvf iptables-1.4.8-100521.tar.bz2 iptables-1.4.8/
キャッシュ情報の更新と確認*/usr/local/libの設定がされているなら、ldconfigのみ実行します
# echo /usr/local/lib >> /etc/ld.so.conf.d/usrlocal.conf # ldconfig # ldconfig -p | grep libip
/sbinにシンボリックリンクを作ります# ln -s /usr/local/sbin/iptables /sbin/iptables # ln -s /usr/local/sbin/iptables-restore /sbin/iptables-restore # ln -s /usr/local/sbin/iptables-save /sbin/iptables-save
フォワーディング設定:/etc/sysctl.conf ファイルの修正
*フォワーディング設定
net.ipv4.ip_forward = 1
*指定されたファイルから読み込んだ内容を sysctl 設定にロードします
# sysctl -p
iptablesの設定 (rpmパッケージの起動スクリプトを使う)*iptablesを新規インストールした場合は、保存したファイルをもどします
# cd /etc/init.d # mv iptables-ORG iptables # chmod 755 iptables # cd ../sysconfig # mv iptables-config.rpmsave iptables-config
xen-firewallの実行と確認*適当なディレクトリでxen-firewallスクリプトを実行します
# source xen-firewall
*iptablesのチェック
# service iptables status
設定の保存# service iptables save
*/etc/sysconfig/iptablesファイルとして保存されます
/etc/sysconfig/iptables-configの修正*自動でロードされないモデュールを既述します
IPTABLES_MODULES="ip_conntrack_ftp ip_nat_ftp"
iptablesスクリプトの実行# service iptables start # chkconfig --add iptables
サーバ起動時のfirewall設定の流れiptables起動スクリプトの実行
/etc/sysconfig/iptables,iptables-configが読込まれる
↓
xend,xendomains起動スクリプトの実行
/etc/xen/scripts/vif-bridgeが実行され、
vif-common.shを読み込んで、新しいPHYSDEVチェーンが追加される
vif-common.sh*vif-bridgeスクリプトで読み込まれます
*xendomainsの起動で新しいvifデバイスの設定が追加されます
:/etc/xen/scripts/vif-common.sh
*省略
frob_iptable()
{
if [ "$command" == "online" ]
then
local c="-I"
else
local c="-D"
fi
iptables "$c" FORWARD -m physdev --physdev-in "$vif" "$@" -j ACCEPT \ 2>/dev/null && iptables "$c" FORWARD -m state --state RELATED,ESTABLISHED -m physdev \ --physdev-out "$vif" -j ACCEPT 2>/dev/null
if [ "$command" == "online" ] && [ $? ] then log err "iptables setup failed. This may affect guest networking." fi
}
*省略
bridge接続の確認*xxxxxxxxxxxxの部分にはMACアドレスが入ります
# brctl show
bridge name bridge id STP enabled interfaces
eth0 8000.xxxxxxxxxxxx no vif2.0
vif1.0
peth0
xendomains起動後のiptablesルール*紫色部分 xendomainsの起動で追加された部分
*"service iptables restart"を実行する場合は、"service iptables save"で現況を保存し、
*restart後、手動で/etc/sysconfig/iptables (xendomainsで追加された部分) を修正し、
*サーバ起動時の状態に戻しておく
# Generated by iptables-save v1.4.3.2 on Sat May 23 08:35:07 2009 *nat :PREROUTING ACCEPT [60:4506] :POSTROUTING ACCEPT [67:5122] :OUTPUT ACCEPT [10:796] COMMIT # Completed on Sat May 23 08:35:07 2009 # Generated by iptables-save v1.4.3.2 on Sat May 23 08:35:07 2009 *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [995:269322] :Xen-FORWARD - [0:0] :Xen-INPUT - [0:0] -A INPUT -j Xen-INPUT -A FORWARD -m state --state RELATED,ESTABLISHED -m physdev --physdev-out vif2.0 -j ACCEPT -A FORWARD -m physdev --physdev-in vif2.0 -j ACCEPT -A FORWARD -m state --state RELATED,ESTABLISHED -m physdev --physdev-out vif1.0 -j ACCEPT -A FORWARD -m physdev --physdev-in vif1.0 -j ACCEPT -A FORWARD -j Xen-FORWARD -A Xen-FORWARD -m state --state NEW -m physdev --physdev-in peth0 -j ACCEPT -A Xen-FORWARD -j REJECT --reject-with icmp-host-prohibited -A Xen-INPUT -i lo -j ACCEPT -A Xen-INPUT -p icmp -m icmp --icmp-type any -j ACCEPT -A Xen-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A Xen-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A Xen-INPUT -p tcp -m state --state NEW -m tcp --dport 922 -j ACCEPT -A Xen-INPUT -j REJECT --reject-with icmp-host-prohibited COMMIT # Completed on Sat May 23 08:35:07 2009
![]() |
Copyright(c) 528p.com All Rights Reserved. |

