iptables commands

10 commands, each with a one-line explanation. Click a command to copy it, or its title for details.

Commands 10 shown

  • iptables -L INPUT --line-numbers -n -v

    Show INPUT chain rules with packet/byte counters

    linux · network · security

  • iptables -A INPUT -p tcp --dport 443 -j ACCEPT

    Append a rule to accept inbound HTTPS traffic

    linux · network · security

  • iptables -I INPUT 1 -s 203.0.113.5 -j DROP

    Insert DROP rule at position 1 for a specific source IP

    linux · network · security

  • iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

    Enable IP masquerading for outbound traffic (router/NAT)

    linux · network

  • iptables-save > /etc/iptables/rules.v4 iptables-restore < /etc/iptables/rules.v4

    Persist rules across reboots

    linux · network

  • iptables -D INPUT 3

    Remove rule number 3 from the INPUT chain

    linux · network

  • iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m limit --limit 3/min --limit-burst 5 -j ACCEPT

    Allow max 3 new SSH connections per minute

    linux · network · security

  • nft list ruleset

    Show complete nftables configuration

    linux · network · security

  • nft add rule inet filter input tcp dport 8080 accept

    Accept inbound TCP traffic on port 8080 in nftables

    linux · network · security

  • nft flush ruleset

    Delete all nftables rules (caution: drops all firewall rules)

    linux · network · security