Sobes.tech
Junior

How can you view current connections?

sobes.tech AI

Answer from AI

Using the netstat utility:

# Show all connections (active and passive)
netstat -a

# Show only listening sockets
netstat -l

# Show TCP connections
netstat -t

# Show UDP connections
netstat -u

# Show PID and process name (requires root privileges)
netstat -p

# Combining flags for a more comprehensive view
netstat -tunlp

Using the ss utility (preferable for modern systems due to higher performance):

# Show all connections
ss -a

# Show only listening sockets
ss -l

# Show TCP connections
ss -t

# Show UDP connections
ss -u

# Show PID and process name
ss -p

# Combining flags
ss -tunlp

Using the contents of the /proc/net/ directory:

Connection information is available in files like /proc/net/tcp, /proc/net/udp, and others in this directory.

# View raw TCP connection data
cat /proc/net/tcp

This method requires manual interpretation of data presented in hexadecimal format. The netstat and ss utilities provide more convenient and readable output.