Reputation: 633
I am trying to get the network mask using bash in that way:
192.168.1.0/x
I tried with:
ip -o -f inet addr show | awk '/scope global/ {print $4}'
but the output is:
192.168.1.123/x
So this way doesn't work for me.
Upvotes: 1
Views: 2583
Reputation: 157967
Since you are masking the last 8 bits, 192.168.1.123/24 is the same as 192.168.1.0/24. If you want the last byte to be 0 for cosmetic reasons, I would use sub()
in awk:
ip -o -f inet addr show | awk '/scope global/{sub(/[^.]+\//,"0/",$4);print $4}'
Upvotes: 5