Configure the Linux kernel firewall — manage network packet filtering rules.
high risk
iptables-save > /root/iptables.backupBack up the current rules.echo 'iptables-restore < /root/iptables.backup' | at now + 5 minutesAuto-rollback if you lock yourself out (cancel with atrm once verified).iptables manages netfilter rules through chains. INPUT/OUTPUT/FORWARD handle incoming, outgoing, and routed traffic. Rules are evaluated top-to-bottom; first match wins. Save rules with iptables-save before making changes.
| Flag | Meaning |
|---|---|
-A --append | Append a rule to a chain |
-I --insert | Insert a rule at the top (highest priority) |
-D --delete | Delete a specific rule |
-L --list | List all rules in a chain |
-n --numeric | Show numeric IPs without hostname resolution |
-F --flush | Delete all rules from a chain |
iptables -L -nvList all firewall rules with packet/byte counts numerically · explain & risk-check →iptables -A INPUT -p tcp --dport 22 -s 10.0.0.0/8 -j ACCEPTAllow SSH only from private 10.x.x.x range · explain & risk-check →iptables-save > /etc/iptables/rules.v4Save current rules to persist across reboots · explain & risk-check →Before adding restrictive rules on a remote server: `echo 'iptables -F' | at now + 5 minutes` — schedules a flush so you can't permanently lock yourself out.
Reference text is hand-written and may be incomplete — check man iptables for your version. Test destructive commands on a non-production system first.