I'm writing a bash function which adds ip routes such as the following:
ip route add table 128 to 192.168.1.0/24 dev eno1
To get the current netmask, I can do ip -f inet -o addr show dev eno1
which will give me a value such as 192.168.1.123/24
, but this is not accepted by ip
. The unmasked bits need to be zero, e.g. 192.168.1.0/24
.
How do I most easily change the unmasked bits of the netmask to zero in bash?
As mentioned in the comments ipcalc or sipcalc will both do it for you.
e.g.
or