Forrest logo
back to the iptables tool

firewall:iptables:ports:allow:port-range

Block traffic on specific port range.
$ sudo iptables -A INPUT -p tcp --dport ${starting_port_number}:${ending_port_number} -j DROP
try on your machine

This command adds a rule to the INPUT chain of the iptables firewall that drops (i.e. rejects) incoming TCP traffic on the port range specified by the variables starting_port_number and ending_port_number.

The sudo command is used to run the iptables command with elevated privileges as a superuser or administrator.

The -A INPUT option specifies that the rule should be appended to the existing rules in the INPUT chain of the firewall.

The -p tcp option specifies that the rule should be applied to TCP traffic.

The --dport option specifies the destination port number(s) that the rule should apply to. The ${starting_port_number}:${ending_port_number} syntax is used to define a range of ports from starting_port_number to ending_port_number.

The -j DROP option specifies that any incoming traffic matching this rule should be dropped and not allowed through the firewall.

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