Saturday, September 14, 2013

Netstat Command

Netstat
command displays various network related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships etc.,

1. List All Ports
List all ports using netstat -a
# netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:30037 *:* LISTEN
udp 0 0 *:bootpc *:*

To list all the TCP ports use the following commands

# netstat -at

Find out on which port a program is running

# netstat -ap | grep ssh

Find out which process is using a particular port:

# netstat -an | grep ':80'

Display the kernel routing information using netstat -r

# netstat -r

Display PID and program names in netstat output using netstat -p

# netstat -pt
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 1 0 ramesh-laptop.loc:47212 192.168.185.75:www CLOSE_WAIT 2109/firefox
tcp 0 0 ramesh-laptop.loc:52750 lax:www ESTABLISHED 2109/firefox

No comments:

Post a Comment