|
[ CentOS/セキュリティ ] iptables でファイアウォールを構築します。 インストール †インストール確認 †[root@linux ~]# yum list | grep iptables iptables.i386 1.3.5-1.2.1 installed ←■ インストール済 iptables-ipv6.i386 1.3.5-1.2.1 installed ←■ インストール済(ipv6用) iptables-devel.i386 1.3.5-1.2.1 base [root@linux ~]# rpm -qa | grep iptables iptables-1.3.5-1.2.1 ←■ インストール済 iptables-ipv6-1.3.5-1.2.1 ←■ インストール済(ipv6用) [root@linux ~]# インストール †インストールされていなかった場合、インストールします。 [root@linux ~]# yum -y install iptables ←■ インストール [root@linux ~]# [root@linux ~]# chkconfig iptables on ←■ 自動起動をONにする [root@linux ~]# [root@linux ~]# chkconfig --list iptables ←■ 自動起動の確認 iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@linux ~]# iptables 設定確認 †インストール時にファイアフォールを有効にした場合は以下のコマンドで設定内容が表示されます。 [root@linux ~]# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination RH-Firewall-1-INPUT all -- anywhere anywhere Chain FORWARD (policy ACCEPT) target prot opt source destination RH-Firewall-1-INPUT all -- anywhere anywhere Chain OUTPUT (policy ACCEPT) target prot opt source destination Chain RH-Firewall-1-INPUT (2 references) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT icmp -- anywhere anywhere icmp any ACCEPT ipv6-crypt-- anywhere anywhere ACCEPT ipv6-auth-- anywhere anywhere ACCEPT udp -- anywhere 224.0.0.251 udp dpt:5353 ACCEPT udp -- anywhere anywhere udp dpt:ipp ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ftp ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:smtp REJECT all -- anywhere anywhere reject-with icmp-host-prohibited [root@linux ~]# iptables 設定 †編集前にファイルバックアップ †[root@linux ~]# cp -a /etc/sysconfig/iptables /etc/sysconfig/iptables.org /etc/sysconfig/iptables の編集 †[root@linux ~]# vi /etc/sysconfig/iptables ← viエディタで編集する # Firewall configuration written by system-config-securitylevel # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :RH-Firewall-1-INPUT - [0:0] -A INPUT -j RH-Firewall-1-INPUT -A FORWARD -j RH-Firewall-1-INPUT -A RH-Firewall-1-INPUT -i lo -j ACCEPT -A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT -A RH-Firewall-1-INPUT -p 50 -j ACCEPT -A RH-Firewall-1-INPUT -p 51 -j ACCEPT -A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #■↓ SSH -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 2222 -j ACCEPT #■↓ HTTP -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #■↓ FTP -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 20 -j ACCEPT #■↓ FTP -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT #■↓ SMTP -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT #■↓ POP3 -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT #■↓ HTTPS -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT #■↓ OP25B対策(サブミッションポート) -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 587 -j ACCEPT #■↓ MySQL(使用する場合) -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #■↓ PostgreSQL(使用する場合) -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT #■↓ Webmin(使用する場合) -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 10000 -j ACCEPT -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited COMMIT ポート番号の範囲指定する場合 -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 50000:50005 -j ACCEPT iptables 起動・停止 †起動 †[root@linux ~]# /etc/rc.d/init.d/iptables start ← iptables 起動 iptables ファイアウォールルールを適用中: [ OK ] [root@linux ~]# 停止 †[root@linux ~]# /etc/rc.d/init.d/iptables stop ← iptables 停止 ファイアウォールルールを適用中: [ OK ] チェインポリシーを ACCEPT に設定中filter [ OK ] iptables モジュールを取り外し中 [ OK ] [root@linux ~]# 再起動 †[root@linux ~]# /etc/rc.d/init.d/iptables restart ← iptables 再起動 ファイアウォールルールを適用中: [ OK ] チェインポリシーを ACCEPT に設定中filter [ OK ] iptables モジュールを取り外し中 [ OK ] iptables ファイアウォールルールを適用中: [ OK ] [root@linux ~]# iptables 有効・無効 †iptables を有効にするとは、OSの起動と同時にサービスを起動すること iptables を有効にする †[root@linux ~]# chkconfig iptables on ← iptables サービスを有効 [root@linux ~]# iptables を無効にする †[root@linux ~]# chkconfig iptables off ← iptables サービスを無効 [root@linux ~]# 設定確認 †[root@linux ~]# chkconfig --list iptables iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@linux ~]# 良く使う使用ポート一覧 †
|