SG iptables Command Generator

34 views
SanchitGurukul Networking & Security Tools

iptables Command Generator

Build firewall, forwarding and NAT commands with validation, explanations and practical examples.

Linux Firewall
Remote-server warning: a wrong firewall rule can immediately disconnect SSH or expose services. Keep a second session open, test rules before saving, and confirm console access.

1. Choose rule type

2. Match traffic

3. Optional controls

Generated command

Ready
# Select options and generate a command.

Command explanation

Your rule explanation will appear here.

Policy and rule-management commands

Persistence: iptables rules are normally lost after reboot unless saved through your distribution's firewall service, such as iptables-persistent or netfilter-persistent.

Practical examples

Select an example to load every relevant field into the generator.

How iptables evaluates rules

  1. A packet enters a table and chain appropriate to its path.
  2. Rules are tested from top to bottom.
  3. The first terminating target such as ACCEPT, DROP or REJECT decides the result.
  4. If no rule matches, the chain policy applies.

Common chains

ChainPurpose
INPUTTraffic destined for the local machine.
OUTPUTTraffic generated by the local machine.
FORWARDTraffic routed through the machine.
PREROUTINGPackets before the routing decision; commonly DNAT.
POSTROUTINGPackets after routing; commonly SNAT or MASQUERADE.

Important safety practices

  • Allow established traffic before applying restrictive default policies.
  • Allow your current SSH source before changing INPUT to DROP.
  • Use -C to check for duplicates before appending automation-managed rules.
  • List numbered rules before deletion: sudo iptables -L INPUT --line-numbers -n -v.
  • For modern systems, verify whether iptables uses the nftables backend.

Your feedback matters

Was this post helpful?

2 reactions