Helpful Tips (iptables)

Topics · Published 2019-08-24 · Revised 2026-11-23
Reviewed corrections applied locally; pre-review version preserved separately · Joomla source

2,662 Total views across this article’s versions; includes the historical baseline where available.

Here are a few helpful tips related to rule and route testing.

Changes Take Effect Without a Routine Cache Flush

Successful ip route, ip rule, and iptables changes update the running kernel configuration. A cache flush does not reload those settings from disk. Linux removed the old IPv4 route cache in kernel 3.6; do not use ip route flush cache as a routine activation step.

Inspect the affected rules and routes, then test a new connection while keeping recovery access available. Existing connection-tracking or NAT state can make an established connection behave differently from a new one.

Do Not Confuse Flushing with Reloading

A flush is a deletion operation. ip rule flush removes routing policy rules; ip route flush removes selected routes; iptables -F removes rules from the selected table’s chains. They do not activate pending changes.

Use exact deletions when undoing a test. In particular, flushing an iptables chain leaves its policy in place: an empty INPUT chain with a DROP policy can lock out a remote administrator.

mark vs. fwmark: What Is the Difference?

ip rule fwmark and the iptables mark match refer to a packet’s local mark. The MARK target can set it. The mark is kernel metadata, not a field transmitted in the IP packet.

A connection mark is a separate value stored with the tracked connection. CONNMARK --save-mark copies a packet mark to that connection mark; CONNMARK --restore-mark copies it back to a packet. That copying is not automatic. The conntrack match reads tracked connection state; it does not itself assign a mark.

Persisting Routes, Rules, and Tables Across Reboots

Running firewall and routing state is separate from the configuration that recreates it after a reboot or network reconnect. Network managers normally restore addresses and their associated routes; custom routes, policy rules, and firewall rules need an appropriate persistent configuration too.

rt_tables supplies optional names for numeric routing-table IDs. It neither stores routes nor recreates policy rules. Follow Persistence: Making iptables Changes Stick for the distinction between firewall and routing startup work.

References: ip-route(8), ip-rule(8), iptables, and MARK, CONNMARK, and conntrack extensions.