Identifying TCP and UDP sockets

Use the lsof command, a variant of the netstat -af command to identify TCP sockets that are in the LISTEN state and idle UDP sockets that are waiting for data to arrive.

For example, to display the TCP sockets in the LISTEN state and the UDP sockets in the IDLE state, run the lsof command as follows:
# lsof -i | egrep "COMMAND|LISTEN|UDP"

The output produced is similar to the following:

Command PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
dtlogin
2122
root
5u
IPv4
0x70053c00
0t0
UDP
*:xdmcp
dtlogin
2122
root
6u
IPv4
0x70054adc
0t0
TCP
*:32768(LISTEN)
syslogd
2730
root
4u
IPv4
0x70053600
0t0
UDP
*:syslog
X
2880
root
6u
IPv4
0x70054adc
0t0
TCP
*:32768(LISTEN)
X
2880
root
8u
IPv4
0x700546dc
0t0
TCP
*:6000(LISTEN)
dtlogin
3882
root
6u
IPv4
0x70054adc
0t0
TCP
*:32768(LISTEN)
glbd
4154
root
4u
IPv4
0x7003f300
0t0
UDP
*:32803
glbd
4154
root
9u
IPv4
0x7003f700
0t0
UDP
*:32805
dtgreet
4656
root
6u
IPv4
0x70054adc
0t0
TCP
*:32768(LISTEN)
After identifying the process ID, you can obtain more information about the program by running the following command:
" # ps -fp PID#"

The output contains the path to the command name, which you can use to access the program's man page.