117 | | # /sbin/iptables -F |
118 | | # /sbin/iptables -X |
119 | | # /sbin/iptables -P INPUT ACCEPT |
120 | | # /sbin/iptables -P OUTPUT ACCEPT |
121 | | # /sbin/iptables -P FORWARD ACCEPT |
122 | | # /sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT |
123 | | # /sbin/iptables -A INPUT -p icmp -j ACCEPT |
124 | | # /sbin/iptables -A INPUT -i lo -j ACCEPT |
125 | | # |
126 | | # /sbin/iptables -A INPUT -p tcp -m state --state NEW -m multiport --dports 22,25,53,587,993,80,443 -j ACCEPT |
127 | | # /sbin/iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited |
128 | | # /sbin/iptables -A FORWARD -j REJECT --reject-with icmp-host-prohibited |
| 117 | $ sudo su - |
| 118 | # vim iptables.sh |
130 | | 2. 設定内容を確認 |
| 120 | {{{#sh |
| 121 | #!/bin/sh |
| 122 | |
| 123 | /sbin/iptables -F |
| 124 | /sbin/iptables -X |
| 125 | /sbin/iptables -P INPUT ACCEPT |
| 126 | /sbin/iptables -P OUTPUT ACCEPT |
| 127 | /sbin/iptables -P FORWARD ACCEPT |
| 128 | |
| 129 | /sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT |
| 130 | /sbin/iptables -A INPUT -p icmp -j ACCEPT |
| 131 | /sbin/iptables -A INPUT -i lo -j ACCEPT |
| 132 | |
| 133 | /sbin/iptables -A INPUT -p tcp -m state --state NEW -m multiport --dports 22,25,53,587,993,80,443 -j ACCEPT |
| 134 | /sbin/iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited |
| 135 | /sbin/iptables -A FORWARD -j REJECT --reject-with icmp-host-prohibited |
| 136 | }}} |
| 137 | {{{ |
| 138 | # chmod u+x iptables.sh |
| 139 | # ./iptables.sh |
| 140 | }}} |
| 141 | 1. 設定内容を確認 |
149 | | 3. 設定内容をファイルに保存し、起動時にそのファイルを読みこむようにする (「方法1」を選択) |
150 | | 4. 再起動し、設定内容を確認 |
| 160 | 1. 設定内容をファイルに保存する |
| 161 | {{{ |
| 162 | # mkdir /etc/iptables |
| 163 | # iptables-save > /etc/iptables/iptables.rules |
| 164 | }}} |
| 165 | 1. ↑で保存したファイルを、起動時に読み込み、終了時に保存し直すよう設定する |
| 166 | {{{ |
| 167 | # vim /etc/network/interfaces |
| 168 | }}} |
| 169 | {{{#sh |
| 170 | # 最終行に追加 |
| 171 | pre-up iptables-restore < /etc/iptables/iptables.rules |
| 172 | post-down iptables-save -c > /etc/iptables/iptables.rules |
| 173 | }}} |
| 174 | 1. 再起動し、設定内容を確認 |
| 175 | {{{ |
| 176 | # reboot |
| 177 | }}} |
| 178 | {{{ |
| 179 | $ sudo su - |
| 180 | # iptables -L -n |
| 181 | Chain INPUT (policy ACCEPT) |
| 182 | target prot opt source destination |
| 183 | ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED |
| 184 | ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 |
| 185 | ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 |
| 186 | ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW multiport dports 22,25,53,587,993,80,443 |
| 187 | REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited |
| 188 | |
| 189 | Chain FORWARD (policy ACCEPT) |
| 190 | target prot opt source destination |
| 191 | REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited |
| 192 | |
| 193 | Chain OUTPUT (policy ACCEPT) |
| 194 | target prot opt source destination |
| 195 | # |
| 196 | }}} |