Forrest logo
back to the iptables tool

firewall:iptables:ports:block:port

Block a port from incoming traffic.
$ sudo iptables -A INPUT -p tcp --dport ${port_number} -j DROP
try on your machine

This command adds a new rule to the INPUT chain of the iptables firewall. The rule specifies that any incoming TCP packet with a destination port of ${port_number} should be dropped (i.e., not forwarded or processed by the system).

Here's a breakdown of the command:

  • sudo - Run the command with administrative privileges.
  • iptables - The command for managing the Linux kernel's netfilter firewall.
  • -A INPUT - Append a new rule to the end of the INPUT chain.
  • -p tcp - Match packets with the TCP protocol.
  • --dport ${port_number} - Match packets with a destination port number of ${port_number}.
  • -j DROP - If the packet matches the previous conditions, drop (discard) the packet.
This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the iptables tool