Find out your IP in Linux

April 3rd, 2009 by
T4L

Finding out your PC’s IP in Linux is a simple matter of typing ifconfig in a Terminal shell. But what if you’re behind a router? Thanks to a simple shell script, you can display your IP in the command line by simply invoking the whatismyip command.
Do this:

cd /usr/bin
sudo nano whatismyip

In the new file paste this:

#!/bin/bash
curl -s myip.dk |grep ‘”Box”‘ | egrep -o ‘[0-9.]+’

Close and save the file then make it executable:

sudo chmod +x /usr/bin/whatismyip

Now every thime you type whatismyip the IP assigned to you by your ISP will be printed in the Terminal window.
Original idea here.

About

www.tips4linux.com is a place dedicated to the Linux user. Not only for the advanced but also for novice users who wish to learn how easy life with Linux can be and how customizable the operating system is. Linux can also be used as an OS platform servers and proves to be reliable when it comes […]