12.26.2010

How to see open ports on Linux?

The Communication in between the two computers takes place via ports. Ports are application specific communication channel which has been divided into the ranges:-

1. Well-known Ports(from 0 to 1023)
2. Registered Ports (1024 to 49151)
3. Dynamic/Private Ports(49152 to 65535)

How to see the Open Ports on Linux?

# netstat -anp --tcp --udp | grep LISTEN


How to block incoming ports under Linux?

#iptables -A INPUT -p tcp --destination-port {PORT-NUMBER-HERE} -j DROP

Example;

Blocking HTTP Port 80


#iptables -A INPUT -p tcp --destination-port 80 -j DROP

#service iptables save

Block Incomming Port 80 except for IP Address 10.112.172.137

#iptables -A INPUT -p tcp -i eth1 -s ! 10.112.172.137 --dport 80 -j DROP

Block Outgoing Port

#iptables -A OUTPUT -p tcp --dport {PORT-NUMBER-HERE} -j DROP

Blocking Port 25

#iptables -A OUTPUT -p tcp --dport 25 -j DROP

#service iptables save

 


 



No comments:

Post a Comment