Thursday, February 2, 2017

Get various networking related parameters by using basic bash command

vifcidr=$(ip -4 -o addr | grep -v '127.0.0.1' | awk '{print $4}’)
Find the cidr

vifbrd=$(ip -4 -o addr | grep -v '127.0.0.1' | awk '{print $6}’)
Find the broadcast address

vifmtu=$(ip -4 -o link | grep -v 'LOOPBACK' | awk '{print $5}’)
Find MTU

vifip=$(echo $vifcidr | awk -F '/' '{print $1 }')
Find IP address based on the cidr found above

vifname=$(ip -4 -o addr | grep -v '127.0.0.1' | awk '{print $2}')
Find the non-loopback interface card

defaultgw=$(ip route | awk '/default / {print $3}')
Find the default gateway ip address

No comments:

Post a Comment