Delete single iptables rules

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
Printed from: http://rackerhacker.com/2007/02/09/delete-single-iptables-rules/ .
© Major Hayden 2012.

7 Comments   »

  • jj says:

    where do you find the chain number and name?

  • robotslacker says:

    @ij:

    The number is the row number of the item when you list them using:

    iptables --list

  • Major Hayden says:

    ij: Try iptables -vnL --line-numbers

  • klovn says:

    THANKS! saved me alot of time :)

  • Techy says:

    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

  • LV says:

    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.

  • noahrama says:

    This is the best way to view chain numbers

    iptables -L INPUT --line-numbers

    you can also substitute with OUTPUT etc

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this