Now that you've seen what a firewall chain listing looks like and what formatting options are available, we'll go through brief lists of INPUT, OUT, and FORWARD rules. The sample rules are representative of some of the rules you'll most likely use yourself. Checking the Input RulesYour input rules are mostly ACCEPT rules when the default policy is DROP. Everything is denied, by default, and you explicitly define what will be accepted. Remember that packets arriving on the INPUT chain are targeted to the local host. The following example contains a representative sample of input acceptance rules: > iptables -v -L INPUT Chain INPUT (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source \ destination 1 4 390 ACCEPT all -- lo any anywhere \ anywhere 2 59 2599 ACCEPT all -- any any anywhere \ anywhere state RELATED,ESTABLISHED 3 0 0 DROP all -- !lo any choke.dmz.lan \ anywhere 4 0 0 DROP all -- !lo any router.private.lan \ anywhere 5 0 0 DROP all -- eth0 any ! .private.lan \ anywhere 6 0 0 ACCEPT udp -- eth0 any .private.lan \ router.private.lan udp spt:1024:65535 dpt:domain state NEW 7 0 0 REJECT tcp -- eth1 any anywhere \ choke.dmz.lan tcp spts:1024:65535 dpt:auth state NEW 8 0 0 ACCEPT udp -- eth0 any jet.private.lan \ 255.255.255.255 udp spt:ntp dpt:ntp state NEW 9 0 0 ACCEPT tcp -- any any anywhere \ anywhere tcp flags:FIN,ACK/FIN,ACK 10 0 0 LOG all -- any any anywhere \ anywhere LOG level warning The default policy for incoming packets is DROP. Denied packets are simply dropped without any notification being returned to the source address. There are 10 rules on the chain:
Checking the Output RulesYour output rules are mostly ACCEPT rules when the default policy is DROP. Everything is blocked, by default. You explicitly define what will be accepted. The following example contains a representative sample of output acceptance rules: > iptables -L OUTPUT Chain OUTPUT (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source \ destination 1 34 3558 ACCEPT all -- any lo anywhere \ anywhere 2 92 12721 ACCEPT all -- any any anywhere \ anywhere state RELATED,ESTABLISHED 3 1 82 ACCEPT udp -- any eth1 choke.dmz.lan \ nameserver.dmz.lan udp spt:domain dpt:domain state NEW 4 0 0 ACCEPT udp -- any eth1 choke.dmz.lan \ nameserver.dmz.lan udp spts:1024:65535 dpt:domain state NEW 5 0 0 ACCEPT tcp -- any eth1 choke.dmz.lan \ nameserver.dmz.lan tcp spts:1024:65535 dpt:domain state NEW 6 2 120 ACCEPT tcp -- any eth0 router.private.lan \ .private.lan multiport dports ssh,http,https,auth,ftp \ tcp spts:1024:65535 flags:SYN,RST,ACK/SYN state NEW 7 0 0 ACCEPT tcp -- any eth1 choke.dmz.lan \ .dmz.lan tcp spts:1024:65535 dpt:ssh state NEW 8 0 0 ACCEPT tcp -- any eth1 choke.dmz.lan \ anywhere multiport dports http,https,auth,ftp,nicname \ tcp spts:1024:65535 flags:SYN,RST,ACK/SYN state NEW 9 0 0 ACCEPT tcp -- any eth1 choke.dmz.lan \ mail.dmz.lan tcp spts:1024:65535 dpt:smtp state NEW 10 0 0 ACCEPT udp -- any eth1 choke.dmz.lan \ timeserver.edu udp spts:1024:65535 dpt:ntp state NEW 11 0 0 ACCEPT icmp -- any eth1 choke.dmz.lan \ anywhere icmp fragmentation-needed 12 0 0 ACCEPT icmp -- any eth0 router.private.lan \ .private.lan icmp echo-request 13 0 0 ACCEPT icmp -- any eth0 router.private.lan \ .private.lan icmp echo-reply 14 0 0 ACCEPT icmp -- any eth1 choke.dmz.lan \ .dmz.lan icmp echo-request 15 0 0 ACCEPT icmp -- any eth1 choke.dmz.lan \ firewall.dmz.lan icmp echo-reply 16 0 0 ACCEPT tcp -- any eth0 router.private.lan \ jet.private.lan tcp dpt:printer state NEW 17 0 0 ACCEPT tcp -- any any anywhere \ anywhere tcp flags:RST/RST 18 0 0 LOG all -- any any anywhere \ anywhere LOG level warning The default policy for the OUTPUT chain is DROP. Denied packets are simply dropped without any notification being returned to the local program. There are 18 rules on the chain:
Checking the Forwarding RulesThe forwarding rules apply to packets passing or being routed through the machine. Forwarded packets are inspected only by the rules defined for the FORWARD chain. These packets are not inspected against rules on the INPUT or OUTPUT chains. If the packet's destination address is something other than the address of the interface on which the packet arrived, the packet is inspected by the FORWARD chain. If the packet matches a FORWARD acceptance rule, the packet is sent out the appropriate interface, after being inspected by any rules defined for the POSTROUTING chains. For the purposes of illustration, the firewall rule pair shown next forwards all TCP connections from the internal network. UDP traffic is not routed. Related ICMP traffic is routed: iptables -A FORWARD -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A FORWARD -i $LAN_INTERFACE -o $EXTERNAL_INTERFACE -p tcp \ -s $INTERNAL_LAN_ADDRESSES -m state --state NEW -j ACCEPT This section is based on a representative sample of forwarding rules. The INPUT and OUTPUT rules are mostly ACCEPT rules when the default policy is DROP. Everything is denied, by default, and you explicitly define what will be accepted: > iptables -v -L FORWARD Chain FORWARD (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source \ destination 1 67 6050 ACCEPT all -- any any anywhere \ anywhere state RELATED,ESTABLISHED 2 0 0 ACCEPT tcp -- eth1 eth0 selected.remote.host \ host1.private.lan tcp spts:1024:65535 dpt:ssh \ flags:SYN,RST,ACK/SYN state NEW 3 0 0 ACCEPT tcp -- eth0 eth1 .private.lan \ mailserver.dmz.lan multiport dports smtp,pop3 tcp spts:1024:65535 \ flags:SYN,RST,ACK/SYN state NEW 4 1 60 ACCEPT tcp -- eth0 eth1 .private.lan \ web-proxy.dmz.lan multiport dports http,https tcp spts:1024:65535 \ flags:SYN,RST,ACK/SYN state NEW 5 1 60 ACCEPT tcp -- eth0 eth1 .private.lan \ anywhere tcp spts:1024:65535 dpts:ssh \ flags:SYN,RST,ACK/SYN state NEW 6 0 0 ACCEPT tcp -- eth0 eth1 .private.lan \ news-server.net tcp spts:1024:65535 dpt:nntp \ flags:SYN,RST,ACK/SYN state NEW 7 0 0 REJECT tcp -- eth1 any anywhere \ .private.lan tcp spts:1024:65535 dpt:auth \ reject-with icmp-port-unreachable 8 0 0 ACCEPT icmp -- any any anywhere \ anywhere icmp fragmentation-needed 9 2 168 ACCEPT icmp -- eth0 eth1 .private.lan \ anywhere icmp echo-request 10 0 0 ACCEPT tcp -- any any anywhere \ anywhere tcp flags:FIN,ACK/FIN,ACK 11 0 0 ACCEPT tcp -- any any anywhere \ anywhere tcp flags:RST/RST 12 0 0 LOG all -- any any anywhere \ anywhere LOG level warning The default policy for the FORWARD chain is DROP. Denied packets are simply dropped without any notification being returned to either the local or the remote program. There are 12 rules on the chain:
In this case, the -v option is generally helpful to see the incoming and outgoing network interface names. eth0 is the internal interface to the .private.lan network. etH1 is the external interface to the .dmz.lan and the Internet beyond. Remember that FORWARD rules are necessary with or without NAT. Also remember that any NAT rules are defined in the nat table. These rules are defined in the default filter table.
|