If you want to delete a rule in iptables, a good place to start is:
Code:
iptables -L --line-numbers
...output of the above command:
Code:
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 RH-Firewall-1-INPUT all -- anywhere anywhere
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 RH-Firewall-1-INPUT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
Chain RH-Firewall-1-INPUT (2 references)
num target prot opt source destination
1 ACCEPT all -- anywhere anywhere
2 ACCEPT icmp -- anywhere anywhere icmp echo-request
3 ACCEPT ipv6-crypt-- anywhere anywhere
4 ACCEPT ipv6-auth-- anywhere anywhere
5 ACCEPT udp -- anywhere anywhere udp dpt:ipp
6 ACCEPT tcp -- anywhere anywhere tcp dpt:ipp
7 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
8 ACCEPT all -- 192.168.1.0/24 anywhere
9 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
10 ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ndmp
11 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
The first column will list the line numbers for all the rules. You can then use the command:
Code:
[root@server ~]# iptables -D RH-Firewall-1-INPUT 5
where the syntax is "--delete -D
chain rule-number". The above code would delete rule number 5 from the
RH-Firewall-1-INPUT chain. Keep in mind, that you have only removed the rule from memory, so to make that rule deletion permanent, you have to save the set of rules from memory to /etc/sysconfig/iptables with the following command. Always make a backup of the iptables file, before you muck up the rules:
Code:
iptables-save > /etc/sysconfig/iptables
or
Code:
service iptables save
I think what confuses many people is the way RedHat and Fedora set up the firewall. The built-in chain "
INPUT" in the "filter" table, has a policy of "
ACCEPT", but then jumps to a user defined chain, "
RH-Firewall-1-INPUT", which in turn has the "
REJECT" target in the last rule. Anyway, most of the rules live in the RH-Firewall-1-INPUT chain, (default at least), but IPtables tutorials don't reference this particular facet often, if at all.
Code:
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 RH-Firewall-1-INPUT all -- anywhere anywhere
Chain RH-Firewall-1-INPUT (2 references)
num target prot opt source destination
1 ACCEPT all -- anywhere anywhere
~
~
~
11 REJECT all -- anywhere anywhere reject-with icmp-host-prohibited