Error applying iptables rules using iptables-restore
Posted
by John Franic
on Server Fault
See other posts from Server Fault
or by John Franic
Published on 2010-01-08T23:32:59Z
Indexed on
2010/03/14
9:05 UTC
Read the original article
Hit count: 535
Hi I'm using Ubuntu 9.04 on a VPS. I'm getting an error if I apply a iptables rule. Here is what I have done.
1.Saved the existing rules
iptables-save > /etc/iptables.up.rules
Created iptables.test.rules and add some rules to it
nano /etc/iptables.test.rulesnano /etc/iptables.test.rules
This is the rules I added
*filter
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT
# Accepts all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allows all outbound traffic
# You can modify this to only allow certain traffic
-A OUTPUT -j ACCEPT
# Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT
# Allows SSH connections
#
# THE -dport NUMBER IS THE SAME ONE YOU SET UP IN THE SSHD_CONFIG FILE
#
-A INPUT -p tcp -m state --state NEW --dport 22- j ACCEPT
# Allow ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
# log iptables denied calls
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
# Reject all other inbound - default deny unless explicitly allowed policy
-A INPUT -j REJECT
-A FORWARD -j REJECT
COMMIT
After editing when I try to apply the rules by
iptables-restore < /etc/iptables.test.rules
I get the following error
iptables-restore: line 42 failed
Line 42 is COMMIT and I comment that out I get
iptables-restore: COMMIT expected at line 43
I'm not sure what is the problem, it is expecting COMMIT but if COMMIT is there it's giving error. Could it be due to the fact i'm usin a VPS?My provider using OpenVZ for virtualizaton.
© Server Fault or respective owner