Inspect socket details in /proc/net
In this step, you will explore the /proc/net
directory, which provides detailed information about the network stack and network protocols in the Linux kernel. This is where commands like ss
and netstat
get their data.
The /proc
filesystem is a virtual filesystem that provides information about processes and other system information. It's a powerful way to inspect the kernel's internal state.
Inside /proc/net
, you'll find files that contain raw data about network connections. For example, tcp
, udp
, tcp6
, and udp6
contain information about active TCP and UDP sockets (IPv4 and IPv6 respectively).
Let's look at the contents of the tcp
file. Type the following command in your terminal and press Enter:
cat /proc/net/tcp
You will see output that looks something like this:
sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode ref pointer drops
0: 0100007F:0019 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 12345 1 0000000000000000 0
1: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 67890 1 0000000000000000 0
... (more lines)
This output is less human-readable than ss
or netstat
because it's the raw kernel data. Each line represents a TCP socket and contains various fields, including:
sl
: The socket list index.
local_address
: The local IP address and port in hexadecimal format. 0100007F
is the hexadecimal representation of 127.0.0.1
(loopback address), and 0019
is the hexadecimal representation of port 25.
rem_address
: The remote IP address and port in hexadecimal format.
st
: The state of the socket (e.g., 0A
represents LISTEN
).
tx_queue
: The transmit queue size.
rx_queue
: The receive queue size.
uid
: The user ID that owns the socket.
inode
: The inode number of the socket.
You can also view UDP sockets by looking at the /proc/net/udp
file:
cat /proc/net/udp
And for IPv6 sockets, you can check /proc/net/tcp6
and /proc/net/udp6
.
While you won't typically parse these files directly for everyday use, understanding that this is where the network information originates provides deeper insight into how Linux manages network connections. Commands like ss
and netstat
essentially read and format the data from these files for easier understanding.
You have now explored the raw socket information available in the /proc/net
filesystem.
Click Continue to complete the lab.