Skip to content

Linux & shell: Firewall (ufw, firewalld, iptables, nftables)

7 Linux & shell commands: Firewall (ufw, firewalld, iptables, nftables). Click a command to see what each part does.

Index
7 items
Click a command to see what each part does.

Firewall (ufw, firewalld, iptables, nftables)7

  • sudo ufw status verboseFirewall status and rules (Ubuntu ufw)

    What each part does

    1. ufw statusactive or not, and each allow/deny rule
    2. verbosealso default policies and logging level
  • sudo ufw allow <port>/tcpAllow a port (ufw)Caution

    What each part does

    1. ufw allowadd an allow rule (ufw allow from <ip> to any port <port> to restrict the source)
    2. <port>/tcpport and protocol
  • sudo firewall-cmd --list-allFirewall rules (RHEL firewalld)

    What each part does

    1. firewall-cmd --list-allthe default zone's services, ports, rich rules and interfaces
  • sudo firewall-cmd --permanent --add-port=<port>/tcp && sudo firewall-cmd --reloadOpen a port permanently (firewalld)Caution

    What each part does

    1. --permanentsave to config (without it the rule is lost on reload)
    2. --add-port=<port>/tcpopen the port in the default zone (or --add-service=https)
    3. --reloadapply the saved config
  • sudo iptables -L -n -v --line-numbersList iptables rules with counters

    What each part does

    1. -Llist rules of the filter table
    2. -nnumeric, no DNS lookups
    3. -vpacket/byte counters and interfaces
    4. --line-numbersrule numbers, for deleting by number
  • sudo iptables -t nat -L -n -vList NAT rules (port forwards, Docker, Kubernetes)

    What each part does

    1. -t natthe NAT table: DNAT port forwards and MASQUERADE rules
  • sudo nft list rulesetShow the full nftables ruleset

    What each part does

    1. nft list rulesetevery table, chain and rule (newer distros use nftables under firewalld and iptables-nft)

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…