13

I'm converting my scripts from old net-tools:

ifconfig eth0 192.168.2.1 netmask 255.255.255.0

to iproute2:

ip link set eth0 up
ip addr add 192.168.2.1/24 dev eth0

and I notice that the new commands do not set the broadcast address by default.

What was:

1: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 1c:6f:65:c5:d6:d7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.1/24 brd 192.168.2.255 scope global eth0

is now:

1: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 1c:6f:65:c5:d6:d7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.1/24 scope global eth0

I can add the broadcast address to ip addr command, but I wonder if it is needed at all? First of all, how and where is this broadcast address used? What might break if it is not set? Second of all, it looks like the routing table still has the correct entries by default:

# ip route show table local dev eth0 scope link
broadcast 192.168.2.0  proto kernel  src 192.168.2.1 
broadcast 192.168.2.255  proto kernel  src 192.168.2.1 

I cannot even test it because nowadays no one replies to ping -b.

neirbowj
  • 289
  • 2
  • 9
Powerman
  • 555
  • 1
  • 4
  • 12

3 Answers3

5

There is no need to set the broadcast address manually, it is determined automatically from the IP network and subnet mask.

mgorven
  • 30,036
  • 7
  • 76
  • 121
  • 2
    It seems to me like you're right to say "there is no need to set the broadcast address", as it can always be infered from the netmask and ip. But on some systems (I tried on Ubuntu in a docker container), it can happen that the broadcast addr is not set. And I am therefore wondering why such a field exists in an interface definition. In other words, why can I `$ ip addr 192.168.0.4/16 broadcast 1.2.3.4 dev ` at all? The broadcast addr should not be a field, but always computed, right? – JonasVautherin Nov 03 '17 at 09:36
  • 1
    Doesn't answer the questions: how and where is this broadcast address used? What might break if it is not set? – claymation Sep 15 '18 at 19:27
3

The correct answer for the question is: ip addr add 192.168.2.1/24 brd + dev eth0

This is how iproute2 defines the broadcast address for the network interface.

  • 1
    Well, it's 8 years since I've asked the question. :) And all that time it works ok without configuring broadcast address. – Powerman Dec 04 '20 at 07:21
1

In my environment if I do not set the broadcast address I can ping the new IP from all resources within the local "physical" subnet, e.g. every device directly connected to my switch. However, I cannot ping the new IP from any device connected to my wireless router, which the switch is plugged into. By adding the broadcast address, the wireless router detects the new IP and all devices see each other regardless of how they are connected. This might be dependent on the manufacturer of the equipment I use/my individual topology, but was indeed necessary.

Dan
  • 11
  • 1