Yesterday, I needed to get my server’s network information for a Bash script I was writing. Here are the commands so I don’t forget. They were tested using Fedora 12.

Get IP address:
ifconfig eth0 | awk '/inet / {print $2}' | awk -F: '{print $2}

Get MAC address:
ifconfig eth0 | awk '/HWaddr/ {print $5}'

Get network gateway IP address:
route -n | awk '/^0.0.0.0/ {print $2}'

Tagged with:  

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>