Is there a command line option to IPTABLES ALL rules for both IPv4 and IPv6 on Linux? I need to save those rule to a file. Make new changes to the iptables and create a diff file? Is that even possible?
Yes, you can list all iptables rules.
IPv4 Iptables ALL rules Linux command
Open the terminal and then type as the root user:
iptables -S
IPv6 Ip6tables ALL rules Linux command
ip6tables -S
How to create a diff file to compare files line by line
Save the rule:
iptables -S > /path/to/current.ipv4.rules.txt
ip6tables -S > /path/to/current.ipv6.rules.txt
Now add a new rule, say:
iptables -A INPUT -s 202.1.2.3 -j DROP
Make a new file:
iptables -S > /path/to/updated.ipv4.rules.txt
ip6tables -S > /path/to/updated.ipv6.rules.txt
Then see it:
diff /path/to/current.ipv4.rules.txt /path/to/updated.ipv4.rules.txt
Take a look at my page:
https://www.cyberciti.biz/faq/how-to-list-all-iptables-rules-in-linux/
1 Like