○ iptablesのインストール 4 Router

*サイトの入口でファイアウォールをつくり、パケットを制御します
*iptables-1.4.8を使用しています
*ADSLスクリプト(fairewall-masq)で設定します
*既存を削除し、オリジナルソースからインストールします
*make はメンテナンスマシンで行っています

**以降はコメントです
*ソースの取得、削除は省略します
*エディタ、ファイラーの操作は省略します
*ソースを展開したら説明文 (英文) を読みましょう
*Enterキーを省略します

*ログイン端末で "#" はroot、"$" は一般ユーザのプロンプトの記号です
*設定ファイルで "#" で始まる行はコメントとして解釈されます

○関連サイト

:iptables-1.4.8.tar.bz2  (http://www.netfilter.org/)

○参照ファイル

パッケージの追加
最初の設定 (Router)

○インストール環境

:OS CentOS 5.5
:selinux permissive
:インストール先 
:作業 /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-rt-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

○selinuxヘの対応 (selinuxを有効にしている場合)

:新規インストールファイルのselinuxラベルを修正

# restorecon -Rv /usr/local



○Firewallingの作業工程

rp-pppoeで制御 iptablesスクリプトで制御
rp-pppoeの設定

firewall-masqの作製

(iptablesの解除)

rp-pppoeの起動
firewall-masqの作製

firewall-masqの実行

iptablesスクリプトでsave

iptables-configの修正

iptablesスクリプトの実行

(rp-pppoeの設定)

○フォワーディング設定

:/etc/sysctl.conf ファイルの修正

*フォワーディング設定

net.ipv4.ip_forward = 1

*指定されたファイルから読み込んだ内容を sysctl 設定にロードします

# sysctl -p



○iptablesの設定 (pppoeで制御する)

rp-pppoeのインストールを参照

○/etc/ppp/firewall-masqの保存

# cp /etc/ppp/firewall-masq /etc/ppp/firewall-masq-ORG

○/etc/ppp/firewall-masqの修正

*ユーザ・グループ・パーミッション (root root 644)
*スクリプトですが、権限がなくてもpppoeスクリプトが読み込んで実行します

firewall-masq (詳細別記)

○iptablesの停止

*iptablesをrpmパッケージでインストールしている場合です

# service iptables stop
# chkconfig --del iptables

○/etc/init.d/pppoeスクリプトを再起動します

# service pppoe restart

○iptablesのチェックをします

*チェーンが組まれたかどうかのチェックです

# iptables -L -n -v | less # iptables -t nat -L -n -v | less

○selinuxのラベルを修正 (selinuxが有効の場合)

# restorecon -Rv /etc
# restorecon -Rv /usr/local



○iptablesの設定 (rpmパッケージの起動スクリプトを使う)

*iptablesを新規インストールした場合は、保存したファイルをもどします

# cd /etc/init.d
# mv iptables-ORG iptables
# chmod 755 iptables
# cd ../sysconfig
# mv iptables-config.rpmsave iptables-config

○firewall-masqの実行と確認

firewall-masq (詳細別記)

*適当なディレクトリでfirewall-masqスクリプトを実行します

# source firewall-masq

*iptablesのチェック

# service iptables status

○設定の保存

*iptablesの設定を保存します

# 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

○rp-pppoeの設定

*iptablesが先に起動するので設定を書き換えないようにFirewallingを解除します

# pppoe-setup

*省略

FIREWALLING
>>> choose a type of firewall (0-2):0

** Summary of what you enterd **
Ethernet Interface:eth1
User name:xxxxxxxxxxxx@ka.il24.net
Active-on-demand:NO
DNS: Do not adjust
Firewalling:NONE

>>>Accept these settings and adjust configuration files(y/N)?y

○selinuxラベルを修正 (selinuxが有効の場合)

# restorecon -Rv /etc
# restorecon -Rv /usr/local

○ Copyright(c) 528p.com All Rights Reserved.