Linux Admin Blog

System Administration, Linux, Solaris, Backup, Networking, Security, Mysql, Script, Tips & Tricks

Open ports using IPTABLES

Posted by sanjaydalal4u on July 9, 2009

If you want your machine to respond to requests initiated from elsewhere on the internet you need to open the required ports. You need to know below details first:

1. Service name you want to open up
2. Is it a tcp or udp service?
3. Port number(s) uses by service?

Example:

To enable ssh access to your box from anywhere on for Class A networks, you could use something like

iptables -A allowed -p tcp –dport 22 -s 10.2.0.0/16 -j ACCEPT
iptables -A allowed -p udp –dport 22 -s 10.2.0.0/16 -j ACCEPT

iptables -A allowed -p tcp –dport 22 -s 10.8.0.0/16 -j ACCEPT
iptables -A allowed -p udp –dport 22 -s 10.8.0.0/16 -j ACCEPT

This allows both udp and tcp traffic from either of the two class A networks to access port 22 on your machine.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>