付録E.4 Linux環境でのファイアウォール設定方法(iptables,ip6tablesが有効な場合)
ip6tablesが有効な場合は,iptablesの設定とは別にip6tablesの設定が必要です。
ip6tablesの設定を実施する場合は,次の手順にあるコマンドの「iptables」を「ip6tables」に読み替えてください。
- 〈この項の構成〉
(1) 規則を登録する
次のコマンドを実行して,受信の規則を登録します。
iptables△-I△INPUT△-p△tcp△-m△tcp△--dport△<登録するポート番号>△-j△ACCEPT
- (凡例)
-
△:スペース
- 実施例
# iptables -I INPUT -p tcp -m tcp --dport 20281 -j ACCEPT # iptables -I INPUT -p tcp -m tcp --dport 20282 -j ACCEPT
- 注
-
設定したポート番号を指定してください。
(2) 登録した規則を反映する
次のコマンドを実行して,登録した規則を反映します。
service△iptables△save
- (凡例)
-
△:スペース
- 実施例
# service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables: [ OK ]
(3) 登録を確認する
次のコマンドを実行して,指定したポートが許可されていること(ACCEPTになっていること)を確認してください。
iptables△-L
- (凡例)
-
△:スペース
- 実施例
# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:20282 ACCEPT tcp -- anywhere anywhere tcp dpt:20281 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT icmp -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination