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
.
There is no need to set the broadcast address manually, it is determined automatically from the IP network and subnet mask.
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.
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.