Troubleshooting iptables



Troubleshooting iptables

A number of tools are at your disposal for troubleshooting iptables firewall scripts. One of the best methods is to log all dropped packets to the /var/log/messages file.

Checking the Firewall Logs

You track packets passing through the iptables list of rules using the LOG target. You should be aware that the LOG target:

  • Logs all traffic that matches the iptables rule in which it is located.

  • Automatically writes an entry to the /var/log/messages file and then executes the next rule.

If you want to log only unwanted traffic, therefore, you have to add a matching rule with a DROP target immediately after the LOG rule. If you don't, you'll find yourself logging both desired and unwanted traffic with no way of discerning between the two, because by default iptables doesn't state why the packet was logged in its log message.

This example logs a summary of failed packets to the file /var/log/messages. You can use the contents of this file to determine which TCP/UDP ports you need to open to provide access to specific traffic that is currently stopped.

     #---------------------------------------------------------------
     # Log and drop all other packets to file /var/log/messages
     # Without this we could be crawling around in the dark
     #---------------------------------------------------------------

     ipFigureA OUTPUT -j LOG
     ipFigureA INPUT -j LOG
     ipFigureA FORWARD -j LOG

     ipFigureA OUTPUT -j DROP
     ipFigureA INPUT -j DROP
     ipFigureA FORWARD -j DROP

Here are some examples of the output of this file:

  • Firewall denies replies to DNS queries (UDP port 53) destined to server 192.168.1.102 on the home network

    Feb 23 20:33:50 bigboy kernel: IN=wlan0 OUT=
    MAC=00:06:25:09:69:80:00:a0:c5:e1:3e:88:08:00 SRC=192.42.93.30
    DST=192.168.1.102 LEN=220 TOS=0x00 PREC=0x00 TTL=54 ID=30485
    PROTO=UDP SPT=53 DPT=32820 LEN=200
    

  • Firewall denies Windows NetBIOS traffic (UDP port 138)

    Feb 23 20:43:08 bigboy kernel: IN=wlan0 OUT=
    MAC=ff:ff:ff:ff:ff:ff:00:06:25:09:6a:b5:08:00
    SRC=192.168.1.100 DST=192.168.1.255 LEN=241 TOS=0x00 PREC=0x00
    TTL=64 ID=0 DF PROTO=UDP SPT=138 DPT=138 LEN=221
    

  • Firewall denies Network Time Protocol (NTP UDP port 123)

    Feb 23 20:58:48 bigboy kernel: IN= OUT=wlan0
    SRC=192.168.1.102 DST=207.200.81.113 LEN=76 TOS=0x10 PREC=0x00
    TTL=64 ID=0 DF PROTO=UDP SPT=123 DPT=123 LEN=56
    

The traffic in all these examples isn't destined for the firewall; therefore, you should check your INPUT, OUTPUT, FORWARD, and NAT related statements. If the firewall's IP address is involved, then you should focus on the INPUT and OUTPUT statements

If nothing shows up in the logs, then follow the steps in Chapter 4, "Simple Network Troubleshooting," to determine whether the data is reaching your firewall at all and, if it is not, the location on your network that could be causing the problem.

As a general rule, you won't be able to access the public NAT IP addresses from servers on your home network. Basic NAT testing requires you to ask a friend to try to connect to your home network from the Internet.

You can then use the logging output in /var/log/messages to make sure that the translations are occurring correctly and iptables isn't dropping the packets after translation occurs.

iptables Won't Start

The iptables startup script expects to find the /etc/sysconfig/iptables before it starts. If none exists, then symptoms include the firewall status always being stopped and the /etc/init.d/iptables script running without the typical [OK] or [FAILED] messages.

If you have just installed iptables and have never applied a policy, then you will face this problem. Unfortunately, running the service iptables save command before restarting won't help either. You have to create this file:

     [root@bigboy tmp]# service iptables start
     [root@bigboy tmp]#

     [root@bigboy tmp]# touch /etc/sysconfig/iptables
     [root@bigboy tmp]# chmod 600 /etc/sysconfig/iptables

     [root@bigboy tmp]# service iptables start
     Applying iptables firewall rules: [ OK ]
     [root@bigboy tmp]#