1

If I am listening on :::80, is it listening on all ipv6 or all ipv6+ipv4?

This is my netstat -tln:

tcp        0      0 :::8080                     :::*
  • 4
    Possible duplicate of meaning of Netstat local address column – Olorin Jan 23 at 6:43
  • 3
    @Olorin None of the answers in the question you linked to address the specific question asked (whether the socket listens on only ipv6 or both ipv6 and ipv4). – Johan Myréen Jan 23 at 7:50
  • 1
    @JohanMyréen "The above options show up as:- :::80 ... and translate to:- ... Listen on any IP address (IPv4 or IPv6)" – Olorin Jan 23 at 8:13
  • 3
    @Olorin As I wrote in my answer, the situation is not that clear-cut. – Johan Myréen Jan 23 at 8:18
  • 1
    @JohanMyréen in that case that answer should be edited, no? – Olorin Jan 23 at 8:20
5

A listening socket that is bound to ::, i.e. any address IPv6 address (INADDR6_ANY), may or may not also listen to connections using IPv4. This depends from several things:

  • Some operating systems are what is known as dual stack, and on those operating systems this depends from whether the IPV6_V6ONLY socket option is set on the listening socket (by the program that created the socket). Linux-based operating systems and FreeBSD are examples of such operating systems.

    The default behavior if the option is not explicitly set by a program is OS dependent. On Linux-based operating systems, for example, you can change this default by writing 0 or 1 to /proc/sys/net/ipv6/bindv6only.

  • Some other operating systems are not dual stack, and on those operating systems one cannot ever listen to both IPv6 and IPv4 with a single socket. OpenBSD is one such operating system.

On some operating systems, the output of netstat will tell you whether the socket is dual-stack. FreeBSD's netstat reports dual-stack sockets as tcp46 and udp46 in the first column of the output, for examples.

Thanks for your answer @Johan Myreen I want to improve this answer with examples.

I am testing the ipv6_only behavior with both values.

1.

cat /proc/sys/net/ipv6/bindv6only
0
nc -6 -l 80
#server started
# netstat
tcp6       0      0 :::80                   :::*                    LISTEN     
# nc client
nc localhost 80
test
# server response 
nc -6 -l 80
test
# from ipv6 now
 nc ::1 80
test ipv6
# server response
nc -6 -l 80
test ipv6

2.

cat /proc/sys/net/ipv6/bindv6only
1
# server started
nc -6 -l 80
# connect to ipv4
nc localhost 80
nc: connect to localhost port 80 (tcp) failed: Connection refused
# connect to ipv6 
nc ::1 80 
test ipv6 
# server respose
nc -6 -l 80
test ipv6 

from above results we can see that value of /proc/sys/net/ipv6/bindv6only deciding the behaviour of ipv6 only or ipv6+ipv4

  • 1
    The term dual stack is usually used in a context where you just care about having both IPv4 and IPv6 support and do not care about implementations details such as whether you use one or two sockets to achieve that result. As such what you describe for OpenBSD could still be called dual stack. – rfc2460 Jan 25 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.