5

I am looking at the output of lsof -i and I am getting confused! For example, the following connection between my java process and the database shows as IPv6:

[me ~] % lsof  -P -n -i :2315 -a -p xxxx
COMMAND  PID USER   FD   TYPE     DEVICE SIZE/OFF NODE NAME
java    xxxx   me   93u  IPv6 2499087197      0t0  TCP 192.168.0.1:16712->192.168.0.2:2315 (ESTABLISHED)

So the output type is IPv6 but it clearly shows an IPv4 address in the NAME column. Furthermore, the connection was configured with an IPv4 address! (In this example, 192.168.0.2)

Thanks very much for any insight!

1 Answer 1

6

In Linux, IPv6 sockets may be both IPv4 and IPv6 at the same time. An IPv6 socket may also accept packets from an IPv4-mapped IPv6 address.

This feature is controlled by the IPV6_V6ONLY socket option, whose default is controlled by the net.ipv6.bindv6only sysctl (/proc/sys/net/ipv6/bindv6only). Its default is 0 (i.e. it's off) on most Linux distros.

This could be easily reproduced with:

[prompt] nc -6 -l 9999 & nc -4 localhost 9999 &
[4] 10892
[5] 10893
[prompt] lsof -P -n -i :9999
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nc      10892    x    3u  IPv6 297229      0t0  TCP *:9999 (LISTEN)
nc      10892    x    4u  IPv6 297230      0t0  TCP 127.0.0.1:9999->127.0.0.1:41472 (ESTABLISHED)
nc      10893    x    3u  IPv4 296209      0t0  TCP 127.0.0.1:41472->127.0.0.1:9999 (ESTABLISHED)
[prompt] kill %4 %5

The client socket is IPv4, and the server socket is IPv6, and they're connected.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .