View network connections using the NETSTAT command in Linux

Home > Search > Linux commands
  by

If using a Red Hat distribution, install net-tools.

[root@server1 ~]# yum install net-tools

 

The netstat command without any options will display other 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.

[root@server1 ~]# 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.

[root@server1 ~]# netstat -a
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

 

The -n option can be used to disable reverse DNS, so that only IP addresses are displayed instead of hostnames.

[root@server1 ~]# netstat -n
Active Internet connections (w/o servers)
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.

[root@server1 ~]# netstat -t
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

 

The -u option can be used to only display UDP connection.

[root@server1 ~]# netstat -lu
Active Internet connections (w/o servers)
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.

[root@server1 ~]# netstat -x
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
. . .

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments