| 144 | }}} |
| 145 | * IPv6 |
| 146 | {{{ |
| 147 | # vim ip6tables.sh |
| 148 | }}} |
| 149 | {{{ |
| 150 | #!sh |
| 151 | #!/bin/sh |
| 152 | |
| 153 | /sbin/ip6tables -F |
| 154 | /sbin/ip6tables -X |
| 155 | /sbin/ip6tables -P INPUT ACCEPT |
| 156 | /sbin/ip6tables -P OUTPUT ACCEPT |
| 157 | /sbin/ip6tables -P FORWARD ACCEPT |
| 158 | |
| 159 | /sbin/ip6tables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT |
| 160 | /sbin/ip6tables -A INPUT -p icmp -j ACCEPT |
| 161 | /sbin/ip6tables -A INPUT -i lo -j ACCEPT |
| 162 | |
| 163 | /sbin/ip6tables -A INPUT -p tcp -m state --state NEW -m multiport --dports 22,25,53,587,993,80,443 -j ACCEPT |
| 164 | /sbin/ip6tables -A INPUT -j REJECT --reject-with icmp6-port-unreachable |
| 165 | /sbin/ip6tables -A FORWARD -j REJECT --reject-with icmp6-port-unreachable |
| 166 | }}} |
| 167 | {{{ |
| 168 | # chmod u+x ip6tables.sh |
| 169 | # ./ip6tables.sh |
| 188 | # ip6tables -L -n |
| 189 | Chain INPUT (policy ACCEPT) |
| 190 | target prot opt source destination |
| 191 | ACCEPT all ::/0 ::/0 state RELATED,ESTABLISHED |
| 192 | ACCEPT icmp ::/0 ::/0 |
| 193 | ACCEPT all ::/0 ::/0 |
| 194 | ACCEPT tcp ::/0 ::/0 state NEW multiport dports 22,25,53,587,993,80,443 |
| 195 | REJECT all ::/0 ::/0 reject-with icmp6-port-unreachable |
| 196 | |
| 197 | Chain FORWARD (policy ACCEPT) |
| 198 | target prot opt source destination |
| 199 | REJECT all ::/0 ::/0 reject-with icmp6-port-unreachable |
| 200 | |
| 201 | Chain OUTPUT (policy ACCEPT) |
| 202 | target prot opt source destination |
161 | | 1. 設定内容をファイルに保存する |
162 | | {{{ |
163 | | # mkdir /etc/iptables |
164 | | # iptables-save > /etc/iptables/iptables.rules |
165 | | }}} |
166 | | 1. ↑で保存したファイルを、起動時に読み込み、終了時に保存し直すよう設定する |
167 | | {{{ |
168 | | # vim /etc/network/interfaces |
169 | | }}} |
170 | | {{{ |
171 | | #!sh |
172 | | # 最終行に追加 |
173 | | pre-up iptables-restore < /etc/iptables/iptables.rules |
174 | | post-down iptables-save -c > /etc/iptables/iptables.rules |
175 | | }}} |
176 | | 1. 再起動し、設定内容を確認 |
177 | | {{{ |
178 | | # reboot |
179 | | }}} |
180 | | {{{ |
181 | | $ sudo su - |
182 | | # iptables -L -n |
183 | | Chain INPUT (policy ACCEPT) |
184 | | target prot opt source destination |
185 | | ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED |
186 | | ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 |
187 | | ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 |
188 | | ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW multiport dports 22,25,53,587,993,80,443 |
189 | | REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited |
190 | | |
191 | | Chain FORWARD (policy ACCEPT) |
192 | | target prot opt source destination |
193 | | REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited |
194 | | |
195 | | Chain OUTPUT (policy ACCEPT) |
196 | | target prot opt source destination |
| 205 | 1. iptables-persistent をインストールし、iptables の設定を保存する |
| 206 | {{{ |
| 207 | # apt install iptables-persistent |
| 208 | }}} |
| 209 | * ipv4, ipv6 の設定を保存するか尋ねられるので、両方 Yes にしておく |
| 210 | 1. 保存内容を確認 |
| 211 | {{{ |
| 212 | # cat /etc/iptables/rules.v4 |
| 213 | # Generated by iptables-save v1.6.0 on Fri Apr 28 17:47:41 2017 |
| 214 | *filter |
| 215 | :INPUT ACCEPT [0:0] |
| 216 | :FORWARD ACCEPT [0:0] |
| 217 | :OUTPUT ACCEPT [234:24432] |
| 218 | -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT |
| 219 | -A INPUT -p icmp -j ACCEPT |
| 220 | -A INPUT -i lo -j ACCEPT |
| 221 | -A INPUT -p tcp -m state --state NEW -m multiport --dports 22,25,53,587,993,80,443 -j ACCEPT |
| 222 | -A INPUT -j REJECT --reject-with icmp-port-unreachable |
| 223 | -A FORWARD -j REJECT --reject-with icmp-port-unreachable |
| 224 | COMMIT |
| 225 | # Completed on Fri Apr 28 17:47:41 2017 |
| 226 | # cat /etc/iptables/rules.v6 |
| 227 | # Generated by ip6tables-save v1.6.0 on Fri Apr 28 17:47:41 2017 |
| 228 | *filter |
| 229 | :INPUT ACCEPT [0:0] |
| 230 | :FORWARD ACCEPT [0:0] |
| 231 | :OUTPUT ACCEPT [106:10896] |
| 232 | -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT |
| 233 | -A INPUT -p icmp -j ACCEPT |
| 234 | -A INPUT -i lo -j ACCEPT |
| 235 | -A INPUT -p tcp -m state --state NEW -m multiport --dports 22,25,53,587,993,80,443 -j ACCEPT |
| 236 | -A INPUT -j REJECT --reject-with icmp6-port-unreachable |
| 237 | -A FORWARD -j REJECT --reject-with icmp6-port-unreachable |
| 238 | COMMIT |
| 239 | # Completed on Fri Apr 28 17:47:41 2017 |