If using a Red Hat distribution, install net-tools.
[root@server1 ~]# yum install net-tools
The netstat command without any options will display hosts that the local machine is connected to and services on the local machine that are listening.
In this example, under Active Internet Connections, there is an established connection to www.example.com using HTTP. Under Active UNIX domain sockets, LVM is listening.
netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 102.168.0.101:41354 example.com:http ESTABLISHED
. . .
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ACC] STREAM LISTENING 10007 /run/lvm/lvmetad.socket
. . .
The -a option can be used to only display active connections.
netstat -a
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 102.168.0.101:41354 example.com:http ESTABLISHED
The -n option can be used to disable reverse DNS, so that only IP addresses are displayed instead of hostnames.
netstat -n
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 102.168.0.101:41354 12.34.56.78:80 ESTABLISHED
The -t option can be used to only display TCP connections.
netstat -t
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 102.168.0.101:41354 example.com:http ESTABLISHED
The -u option can be used to only display UDP connection.
netstat -lu
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 0.0.0.0:ntp 0.0.0.0:* LISTEN
The -x option can be used to only display Unix connections.
netstat -x
Proto RefCnt Flags Type State I-Node Path
unix 2 [ACC] STREAM LISTENING 10007 /run/lvm/lvmetad.socket
The -p option can be used to include the PID/Program name that is associated with a connection.
netstat -p
Proto Recv-Q Send-Q Local Address Foreign Address PID/Program name
tcp 0 0 102.168.0.101:41354 0.0.0.0:* 12345
. . .
Did you find this article helpful?
If so, consider buying me a coffee over at