Home » Home Server » Commandline IP address lookup in Linux

Commandline IP address lookup in Linux

Commandline IP address lookup

written by Anand June 2, 2010

Commandline IP address lookup is very simple in Linux.

I wrote a small script to do this for me. This is what I did:

nano ipaddr.sh

Enter the following lines into the script:

eip=`wget http://automation.whatismyip.com/n09230945.asp -O - -q`
iip=`ifconfig | grep 'inet addr:'| grep -v '' | cut -d: -f2 | awk '{ pr
int $1}'`
echo "External IP: $eip"
echo "Internal IP: $iip"
exit 0

Made the script executable by the user:

chmod 700 ipaddr.sh

Commandline IP address lookup

Commandline IP Address Lookup

Run the script:


And the output looks like this:

External IP: XX.XX.XXX.XX
Internal IP: 192.168.X.X

The external IP address is the IP address provided by my ISP and shown to the world. The internal IP address is the IP address assigned by my router's DHCP to the network device on my server.

IPVanish VPN Exclusive Offer - only $3.99 per month:
VPN Guides
Windows, Android, Ubuntu
Kodi OpenVPN
♦ Hide your browsing (no logs), Anonymize Streaming and Downloads
♦ Circumvent Geo/Country Restrictions and access worldwide content
♦ Works on Windows, Mac, Linux, Android, iOS, Router, and more
♦ 250 GB of SugarSync Secure storage included
♦ Money back guarantee - Sign Up Now

Related Articles