Port Blocking

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 09:12, 17 June 2009 (edit)
Vespian (Talk | contribs)

← Previous diff
Current revision (07:25, 4 December 2019) (edit) (undo)
Atatob (Talk | contribs)
m (Add language list and table of contents)
 
(6 intermediate revisions not shown.)
Line 1: Line 1:
 +{{Languages|Port_Blocking}}
 +
 +__TOC__
 +
This tutorial will show you basic commands for blocking traffic from accessing your network. This tutorial will show you basic commands for blocking traffic from accessing your network.
Line 10: Line 14:
== Commands == == Commands ==
-'''Port Blocking - Block all users to this port (''Example: Port 80''):'''+'''Port Blocking - Block all users to port 80:'''
-:iptables -I FORWARD 1 -p tcp --dport 80 -j DROP+:iptables -I FORWARD -p tcp --dport 80 -j DROP
-'''Port Blocking - Block a SINGLE user to this port (''Example: Port 21''):'''+'''Port Blocking - Block a SINGLE user to port 21:'''
-:iptables -I FORWARD 1 -s 192.168.1.101 -p tcp --dport 21 -j DROP+:iptables -I FORWARD -s 192.168.1.101 -p tcp --dport 21 -j DROP
-'''Port Blocking - Block a RANGE of users to this port (''Example: Port 21''):'''+'''Port Blocking - Block a RANGE of users to port 21 (''not available in most embedded builds''):'''
-:iptables -I FORWARD 1 -s 192.168.1.1-192.168.1.101 -p tcp --dport 21 -j DROP+:iptables -I FORWARD -s 192.168.1.1-192.168.1.101 -p tcp --dport 21 -j DROP
 + 
 +'''Port Blocking - Block a RANGE of users to port 21 based upon a SUBNET:'''
 + 
 +:iptables -I FORWARD 1 -s 192.168.1.0/24 -p tcp --dport 21 -j DROP
'''List iptables - List the rules in a chain or all chains:''' '''List iptables - List the rules in a chain or all chains:'''
Line 34: Line 42:
:iptables -F :iptables -F
-'''Multiple Ports - Use a semi-colon to separate multiple rules, Use a unique rulenum per command (-I FORWARD 1, -I FORWARD 2, -I FORWARD 3):'''+'''Multiple Ports - Create multiple rules:'''
-:iptables -I FORWARD 1 -p tcp --dport 80 -j DROP; iptables -I FORWARD 2 -p tcp --dport 21 -j DROP+:iptables -I FORWARD -p tcp --dport 21 -j DROP
 +:iptables -I FORWARD -p tcp --dport 80 -j DROP
''Or, just use one rule to accomplish the same thing:'' ''Or, just use one rule to accomplish the same thing:''
-:iptables -I FORWARD -p tcp -m multiport --dport 80,21 -j DROP+:iptables -I FORWARD -p tcp -m multiport --dport 21,80 -j DROP
'''Port Range - Use a colon to select a port range (''Port 21 through 80 will be closed''):''' '''Port Range - Use a colon to select a port range (''Port 21 through 80 will be closed''):'''
Line 49: Line 58:
== External Resources == == External Resources ==
[http://portforward.com/cports.htm PortForward] - List of the most commonly used ports<br> [http://portforward.com/cports.htm PortForward] - List of the most commonly used ports<br>
 +
 +[[Category:Traffic moderation]]
 +[[Category:Advanced tutorials]]

Current revision


Contents


This tutorial will show you basic commands for blocking traffic from accessing 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 SSH or Telnet. If you feel more comfortable running commands via the router's web interface, then you can do so by logging into your router's Administration/Diagnostics page. From there you can input your desired commands into the Command Shell.

[edit] Commands

Port Blocking - Block all users to port 80:

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

Port Blocking - Block a SINGLE user to port 21:

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

Port Blocking - Block a RANGE of users to port 21 (not available in most embedded builds):

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

Port Blocking - Block a RANGE of users to port 21 based upon a SUBNET:

iptables -I FORWARD 1 -s 192.168.1.0/24 -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 - Create multiple rules:

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

Or, just use one rule to accomplish the same thing:

iptables -I FORWARD -p tcp -m multiport --dport 21,80 -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

[edit] See Also

Iptables command - Lists all available commands for use in iptables
Telnet/SSH and the Command Line - How to on Telnet and SSH

[edit] External Resources

PortForward - List of the most commonly used ports