Wednesday, April 13, 2011

Linux Tips and Tricks - Display the IPs on interfaces

Using ifconfig

FIBER_ADDR=$(ifconfig $FIBER | grep 'inet addr' | sed 's/^[^:]\+://;s/\([^ \t]\+\).\+$/\1/')
echo $FIBER_ADDR

Same using IP command

ip addr show | awk '/inet[^6]/ { print $2 }' | sed -e 's/\(.\+\)\/.\+/\1/'

No comments:

Post a Comment