시스템에 iptables가 설치되어 있다면, 이 패키지가 방화벽 기능을 시스템에 제공합니다. iptables가 깔려 있는 경우, 네트워킹 소프트웨어 테스팅 시에 iptables가 패킷을 가로막아 테스트가 온전히 실행되지 못하는 경우가 종종 생깁니다.
이럴 경우 우선 iptables에 무슨 규칙이 반영되어 있는지 알아야 하는데, 기본적으로 다음과 같이 하면 알 수 있습니다.
[root@ns2-3 ns2]# iptables -L --line-numbers
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
2 ACCEPT icmp -- anywhere anywhere
3 ACCEPT all -- anywhere anywhere
4 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ftp
5 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
6 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
행 번호가 출력되도록 했는데, 이렇게 하면 규칙들이 어떤 순서로 배열되어 있는지를 보기가 좀 더 편해집니다. 위의 규칙을 해석하자면, 이미 허용된 플로우에 속한 패킷들, icmp 패킷, 그리고 ftp, ssh에 해당하는 TCP 패킷은 허용되어 있는 상태고, 나머지는 전부 거부됩니다.
같은 subnet에 있는 기계들의 경우, 기본적으로 통신이 가능하도록 하고 싶다고 하면 INPUT 체인의 6번 규칙, 그러니까 REJECT all 에 해당하는 규칙 앞에 두어야 합니다. iptables는 규칙을 위에서 아래로 순서대로 검사하기 때문에, REJECT all 규칙 뒤에 둔 규칙은 쓸모가 없습니다.
[root@ns2-3 ns2]# iptables --insert INPUT 6 -s x.y.0.0/16 -j ACCEPT
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
2 ACCEPT icmp -- anywhere anywhere
3 ACCEPT all -- anywhere anywhere
4 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ftp
5 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
6 ACCEPT all -- x.y.0.0/16 anywhere
7 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
시스템이 재부팅되면 이렇게 설정한 규칙은 사라지기 때문에, 다음과 같이 해 줄 필요가 있습니다.
[root@ns2-3 ns2]# /sbin/service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@ns2-3 ns2]# /sbin/service iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
iptables: Loading additional modules: nf_conntrack_ftp [ OK ]
[root@ns2-3 ns2]#
소중한 의견, 감사합니다. ^^