0

Tanenbaum's Computer Networks says

The IP address 0.0.0.0, the lowest address, is used by hosts when they are being booted. It means ‘‘this network’’ or ‘‘this host.’’

[::] is IPv6 version of IPv4's 0.0.0.0.

Questions:

1) When does [::] or 0.0.0.0 mean this network and when this host?

2) When it means this host, does it mean all the network interfaces on this host, or just one specified network interface on this host?

3) Why does [::] allow me to access the mysql server from other hosts in the same LAN? Does it mean this network or this host here? Why is [::] used by mysql server, although the host is not in the case "when they are being booted"?

   $ sudo netstat -ap | grep mysql
   tcp6       0      0 [::]:mysql              [::]:*                  LISTEN      23683/mysqld        
   tcp6       0      0 [::]:33060              [::]:*                  LISTEN      23683/mysqld        
   unix  2      [ ACC ]     STREAM     LISTENING     1169294  23683/mysqld         /var/run/mysqld/mysqld.sock
   unix  2      [ ACC ]     STREAM     LISTENING     1169513  23683/mysqld         /var/run/mysqld/mysqlx.sock
   unix  2      [ ]         DGRAM                    1169211  23683/mysqld

Thanks.

Tim
  • 98,580
  • 191
  • 570
  • 977
  • From my understanding `[::]` and `0.0.0.0` is for local host only unless there is static route or default route set on the network! – Vivek Kanadiya Mar 22 '19 at 15:19
  • https://unix.stackexchange.com/questions/507564/what-do-0-0-0-0-mysql-and-mean-in-netstat-output You completely ignored the answer you've got. And how it's not the case? Doesn't the MySQL server run exactly the same machine with netstat? – 炸鱼薯条德里克 Mar 23 '19 at 00:38
  • @StephenKitt Your link doesn't answer the "this network" part. I am also still not sure about "0.0.0.0 is used only as a source address", so I left a comment there. – Tim Mar 23 '19 at 00:46
  • 0.0.0.0 means a local socket by convention, at least in unixes. It roots in that the `sockaddr.s_addr` part of the `sockaddr_in` struts remain empty (0) in their case. It is a different, deeper thing than `127.0.0.1`, what is simply the IP of the `lo` loopback network interface. – peterh Jun 03 '19 at 06:33

2 Answers2

2

In the netstat output you gave, the "0.0.0.0" and "[::]" don't mean "this host", they mean that the services in question are listening on "all interfaces on this host". Thus, those ports are open for any host to connect to, including the local host.

John
  • 16,759
  • 1
  • 34
  • 43
  • Thanks. "services in question are listening on all interfaces on this host", are such service also listening on those IP addresses which are not bound to any (virtual or physical) network interface? https://unix.stackexchange.com/questions/508007/when-does-an-ip-address-not-need-to-be-assigned-to-a-network-interface – Tim Mar 22 '19 at 16:18
  • In the case of the loopback address and network in the question you referred to, yes. 127.0.0.1 is also referred to as "localhost" or "loopback", meaning "this IP references the host itself". But be careful of extrapolating behavior of any 127.*.*.* address to any other address - the loopback network (127/8) has always behaved very differently. – John Mar 22 '19 at 16:26
  • Thanks. May I ask what Stephen meant by "0.0.0.0 isn’t valid as a destination address, only as a source address"? When mysql server listens at 0.0.0.0, Is it not the destination of a request sent from a mysql client? How can it be used as a source? https://unix.stackexchange.com/a/419881/674 – Tim Mar 22 '19 at 21:01
  • When a service is listening on "0.0.0.0", it is actually listening on "all IPv4 addresses on this host". So no, 0.0.0.0 is not a valid destination address for incoming requests, instead valid destinations are "all extant IPv4 addresses on this machine". – John Mar 24 '19 at 00:14
  • If there is a :::8080, but do not have 0.0.0.0:8080, can we use IPv4 to access the :::8080? – 244boy Jun 03 '19 at 06:45
  • Most of the time, yes. Modern Linux systems will only show ":::8080" when a service is listening on both IPv4 and IPv6 port 8080, and will automatically "forward" the IPv4 connection to the listening IPv6 port (not entirely a technically accurate description, but it gets the meaning across). – John Jun 04 '19 at 11:56
2

Be careful to note the official IP definition in RFC 1122 is this host on this network. This the official definition. However OS specific uses still exist.

Linux's internal use of [::] and 0.0.0.0 are better thought of as "Null" from other areas of computing. Depending on context "null" can mean "nothing", "don't know", "don't care" or occasionally "error". Its meaning is really context sensitive.

IP addresses can be used to represent a network or host. Eg 192.168.1.1 is a host on 192.168.1.0/24. Which it represents entirely depends on what the software was expecting to receive.

When it means this host, does it mean all the network interfaces on this host, or just one specified network interface on this host?

When referring to bound (listening) sockets, it means "don't care" which IP. But that is limited to only the IPs for the current host, so in practice means connections will be accepted on any interface addressed to any IP from the current host.

Philip Couling
  • 17,591
  • 5
  • 42
  • 82
  • If there is a `:::8080`, but do not have `0.0.0.0:8080`, can we use IPv4 to access the `:::8080`? – 244boy Jun 03 '19 at 06:44
  • 1
    By default on most unix-like systems applications listening on :: can also accept IPv4 connections, but this can be overridden by socket options. Windows is the opposite disabled by default but can be enabled by socket options. – plugwash Nov 30 '22 at 16:34