Sometimes it is very important to grep only the IP address and the gateway of a specific interface especially if you are automating the network side of your server.
To grep the IP address from an interface : where re1 is my WAN interface
ifconfig re1 | grep "inet " | cut -d\ -f2
To grep the gateway :
netstat -r4n | grep re1 | grep -v 'link' | awk '{print $2}' | head -n1
Leave a Reply