You can delete them based on what they’re doing:
iptables -D INPUT -s 127.0.0.1 -p tcp --dport 111 -j ACCEPT |
Or you can delete them based on their number and chain name:
iptables -D INPUT 4 |
You can delete them based on what they’re doing:
iptables -D INPUT -s 127.0.0.1 -p tcp --dport 111 -j ACCEPT |
Or you can delete them based on their number and chain name:
iptables -D INPUT 4 |
where do you find the chain number and name?
@ij:
The number is the row number of the item when you list them using:
iptables –list
ij: Try iptables -vnL –line-numbers
THANKS! saved me alot of time :)
Hi,
Thanks for sharing your knowledge. I wish you all the very best in all your endeavours.
By the way, I like your simplicity and versatalileness.
I am also a system admin but mostly jack of all master of none kinda thing.
warm regards,
Raghu
Thank you for the post.
I have a question, do you think it’s possible to create a list where many IP addresses can be entered and the rule above checks the list or do I have to add each IP address individually.
I hope my question makes sense.
This is the best way to view chain numbers
iptables -L INPUT –line-numbers
you can also substitute with OUTPUT etc
Thanks for the Trick This helps me alot
And you have to use “-t nat” if your rule was configured for nat.
example:
sudo iptables -t nat -A OUTPUT -p tcp –dport 80 -j DNAT –to-destination 1.1.1.1:5555
sudo iptables -t nat -D OUTPUT 1
After deleting a rule, when i restart iptables that rule come again….please suggest
Mukesh,
You’ll probably need to save your rules to a file first. If you’re on Red Hat or CentOS, just use “service iptables save”.
Thanks. Straight to the point and it Works.
Hi All,
I am creating a static nat rule in iptables using the command
iptables -t nat -I POSTROUTING 1 -j SNAT -p ip -s 1.1.1.10/32 –to-source 2.2.2.30-2.2.2.30 -o eth2
After executing the above command i am able to observe the source translation happening and also it is listed in the iptables nat list.
After I remove the rule by executing the below command
iptables -t nat -D POSTROUTING -j SNAT -p ip -s 1.1.1.10/32 –to-source 2.2.2.30-2.2.2.30 -o eth2
The entry in the iptables nat is deleted, but i am still able to observe the source translation happening from 1.1.1.10 to 2.2.2.30.
Please suggest what i need to do to delete the entry completely from the nat table or did i missed something.
Thanks in advance.
Regards,
Sumanta.