Listing IP Addresses of a Server

Posted by Nessa | Posted in ,,, | Posted on June 10, 2007


I hate using the jarbled output of ifconfig to find out what ip addresses are active on a server, so using this complex command will list all the IP addresses of the server in a nice little list:

ifconfig | grep 'inet addr:'| grep -v '' | cut -d: -f2 | awk '{ print $1}'

I specifically use this command for a VPS setup script that I was working on to automatically input the correct server IP into the httpd.conf and named entries on cloned systems, so I don’t have to do it manually. To do this you would just assign the command as a variable, then call that variable with the replace command:

IP=`ifconfig | grep 'inet addr:'| grep -v '' | cut -d: -f2 | awk '{ print $1}'`
cat httpd.conf |replace 123.456.789.123 $IP --httpd.conf

If you want to incorporate this into a PHP script, you just need to use the system() function, assuming your host allows it:

<?php system("ifconfig | grep 'inet addr:'| grep -v '' | cut -d: -f2 | awk '{ print $1}'"); ?>

Be Sociable, Share!

Comments (3)

I hope you dont mind but Ive added your feed to my webmaster search site because i felt alot of the information you provide is relevant for webmasters and will be a good addition to our database.
Keep up the good work

thanks buddy ;)

Welcome friends! ,

Post a comment