How do I forward multiple ports using Linux iptables based firewall?
The Linux iptables comes with MATCH EXTENSIONS which can use extended packet matching modules. The multiport match module matches a set of source or destination ports. Up to 15 ports can be specified. A port range (port:port) counts as two ports. It can only be used in conjunction with -p tcp or -p udp options.
Syntax
The syntax is as follows for the destination port:
iptables -A tableName -p tcp --match multiport --dports port1,port2 -j ACCEPT iptables -A tableName -p udp --match multiport --dports port1,port2 -j DROP iptables -A tableName -p protocol --match multiport --dports portRange1:PortRange2 -j ACCEPT
The syntax is as follows for the source port:
iptables -A tableName -p tcp --match multiport --sports port1,port2 -j ACCEPT iptables -A tableName -p udp --match multiport --sports port1,port2 -j DROP iptables -A tableName -p protocol --match multiport --sports portRange1:PortRange2 -j ACCEPT
Examples
The following will accept all traffic from TCP port 80,22,53:
/sbin/iptables -A INPUT -p tcp --match multiport --dports 80,22,53 -j ACCEPT
The following will accept 1024 to 3000 port range:
/sbin/iptables -A INPUT -p tcp --match multiport --dports 1024:3000 -j ACCEPT
Finally, save the changes:
# service iptables save
OR
# iptables-save > /path/to/your/iptables/settings/file
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 0 comments… add one now }