0

I assigned IP address 192.168.0.1/24 to eth0 in two ways.

A. Adding 192.168.0.1/24 as usual

# ip addr add 192.168.0.1/24 dev eth0
# ping -c 1 192.168.0.2
PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data.
64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=0.051 ms

--- 192.168.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.051/0.051/0.051/0.000 ms
#

B: Adding 192.168.0.1/32 and adding a /24 route

# ip addr add 192.168.0.1/32 dev eth0
                                        # 192.168.0.2 should not be reachable.
# ping -c 1 192.168.0.2
ping: connect: Network is unreachable
                                        # But after adding a route, it is.
# ip route add 192.168.0.0/24 dev eth0
# ping -c 1 192.168.0.2
PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data.
64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=0.053 ms

--- 192.168.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.053/0.053/0.053/0.000 ms
#

Does this mean that adding an IP address with a prefix is just a shorthand for adding the IP address with /32 prefix and adding a route afterwards?  That is, does the prefix length have no meaning and the real work is done by the route entries?

Or is there any functional difference between the two methods?


Here is another case: the two nodes can reach each other via direct connection (no router in between), but don't share a subnet.

Node 1:

# ip addr add 192.168.0.1/24 dev eth0
# ip route add 192.168.1.0/24 dev eth0
                                        # Finish the config on Node 2
# nc 192.168.1.1 8080 <<< "Message from 192.168.0.1"
Response from 192.168.1.1

Node 2:

# ip addr add 192.168.1.1/24 dev eth0
# ip route add 192.168.0.0/24 dev eth0
                                        # Finish the config on Node 1
# nc -l 0.0.0.0 8080 <<< "Response from 192.168.1.1"
Message from 192.168.0.1
2
  • Your labels say “Node 1” and “Node 2”, and your comments say “Node A” and “Node B”.   I assume/guess “Node 1”=“Node A” and “Node 2”=“Node B”, but I wanted to be sure.   Please edit your question to make it clearer. Feb 13 at 15:33
  • Yes, "Node A" should be "Node 1" and "Node B" should be "Node 2". Thanks. Feb 13 at 15:55

1 Answer 1

2

That is, does the prefix length have no meaning and the real work is done by the route entries?

The subnet mask defines your subnet, and thus also defines what the broadcast address is, and to which broadcast IP packets and which ARP requests your machine replies to. So, there's a difference between you getting a /32 address and setting up your routing tables, and you getting a /24 address.

Note that this isn't specific to Linux at all; that's just how IPv4 works.

2
  • Seems like broadcast is the difference between the two, I can't get broadcast to work if I use /32 prefix or when the two nodes don't share a subnet. Only unicast is working. Feb 13 at 16:01
  • @AkashRawal A /32 prefix defines a network with only one host, so there is no broadcast address that makes sense (how do you broadcast to only yourself?) If the two nodes aren't part of the same network, then there is no shared broadcast domain either.
    – ErikF
    Feb 14 at 1:35

You must log in to answer this question.

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