LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   is it possible to move iptables rules up or down? (https://www.linuxquestions.org/questions/linux-networking-3/is-it-possible-to-move-iptables-rules-up-or-down-4175422393/)

m4rtin 08-16-2012 07:18 AM

is it possible to move iptables rules up or down?
 
If I execute "iptables -L -n" I can see all the rules in all the chains. Is it possible to change the order of rules using the iptables utility? For example move certain rule up from the bottom? Or is the only way to achieve this by editing the firewall configuration file? In Cisco IOS it's a good practice to add rules with sequence numbers which allows one later to easily insert rules before a certain rule.

acid_kewpie 08-16-2012 08:01 AM

you can use the "-I INPUT ##" option to insert at a specific point.

m4rtin 08-17-2012 09:36 AM

Quote:

Originally Posted by acid_kewpie (Post 4755558)
you can use the "-I INPUT ##" option to insert at a specific point.

Thanks! This works beautifully. However, is there a way to list rule numbers in a chain? It would be more convenient to insert rules to chains if for example "iptables -t filter -L INPUT" would print rule number in front of each rule :rolleyes: I'm using iptables v1.4.12.1

nikmit 08-17-2012 09:41 AM

Use the --line-numbers option.
iptables -t filter -L INPUT --line-numbers


All times are GMT -5. The time now is 01:32 PM.