Port Blocking

From DD-WRT Wiki

Revision as of 06:57, 5 January 2008 by Cyph3r (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

This tutorial will show you basic commands for blocking service ports from communicating with your network.

Example:

Web = Port 80
FTP = Port 21

In order to set rules on specific ports, you need to access iptables. You will have greater control accessing the iptables via telnet or SSH. If you feel more comfortable running commands via the routers web interface, then you can do so by logging into your router's Administration/Diagnostics page. Input each of these commands into the Command Shell.

Commands

Port Blocking - Block all users to this port (Example: Port 80):

iptables -I FORWARD 1 -p tcp --dport 80 -j DROP

Port Blocking - Block a SINGLE user to this port (Example: Port 21):

iptables -I FORWARD 1 -s 192.168.1.101 -p tcp --dport 21 -j DROP

List iptables - List the rules in a chain or all chains:

iptables -L

Undo Rule - Delete rule rulenum (1 = first) from chain:

iptables -D FORWARD 1

Flush Rules from iptables - Delete all rules in chain or all chains:

iptables -F

Multiple Ports - Use a semi-colon to separate multiple ports:

iptables -I FORWARD 1 -p tcp --dport 80 -j DROP; iptables -I FORWARD 1 -p tcp --dport 21 -j DROP

Port Range - Use a colon to select a port range (Port 21 through 80 will be closed):

iptables -I FORWARD 1 -p tcp --dport 21:80 -j DROP

External Resources

Iptables command - Lists all avalible commands for use in iptables
PortForward - List of the most commonly used ports