Viewing all iptables rules

  • Is there a way to view iptables rules in a bit more detail?

    I recently added masquerade to a range of IPs:

    iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE
    service iptables save
    service iptables restart

    Which has done what I want it to, but when I use:

    iptables -L

    I get the same output as I normally get:

    Chain INPUT (policy ACCEPT)
    target    prot opt source        destination
    Chain FORWARD (policy ACCEPT)
    target    prot opt source        destination
    Chain OUTPUT (policy ACCEPT)
    target    prot opt source        destination

    How can I see the rules including the ones I add? (system is CentOS 6)

  • When using the -L, --list option to list the current firewall rules, you also need to specify the appropriate Netfilter table (one of filter, nat, mangle, raw or security). So, if you’ve added a rule for the nat table, you should explicitly specify this table using the -t, --table option:

    iptables --table nat --list

    Or using the options short form:

    iptables -t nat -L

    If you don’t specify a specific table, the filter table is used as the default.

    For faster results, it can be useful to also include the -n, --numeric option to print numeric IP addresses instead of hostnames, thus avoiding the need to wait for reverse DNS lookups.

    You can get even more information by including the -v, --verbose option.

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM