Search code examples
linuxshelllinux-kerneliptables

failed to apply firewall rules with iptables-restore


Following is the configuration of my iptables,

[root@fabulous ~]# vi /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Mon Dec 23 15:55:09 2013
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m tcp --dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

However, when I restart it, I get error as below, as a notification, the failed line is "COMMIT". Could anyone help to point out where the error is? Thanks in advance.

[root@fabulous ~]# service iptables restart
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules: iptables-restore: line 20 failed
                                                           [FAILED]

Solution

  • I would say that -m TCP is missing in this line:

    -A RH-Firewall-1-INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT
    

    You can usually get some clues applying the rules yourself with iptables-restore:

    iptables-restore < /etc/sysconfig/iptables
    

    EDIT : Spotted it, line 11

    -A RH-Firewall-1-INPUT -p udp -m tcp --dport 53 -j ACCEPT
    

    You're specifying udp proto for the tcp module. You probably meant :

    -A RH-Firewall-1-INPUT -p udp -m udp --dport 53 -j ACCEPT