Find your IP address in Linux

Good information found on https://www.linuxtrainingacademy.com/determine-public-ip-address-command-line-curl/

Let’s do the same thing with the ip command. To view IP addresses, use ip addr show. Like ifconfig, you can specify an interface.

$ ip addr show
1: lo: <loopback,up,lower_up> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:43:84:6c brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.236/24 brd 192.168.122.255 scope global eth0
    inet6 fe80::5054:ff:fe43:846c/64 scope link 
       valid_lft forever preferred_lft forever
$ ip addr show eth0
2: eth0: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:43:84:6c brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.236/24 brd 192.168.122.255 scope global eth0
    inet6 fe80::5054:ff:fe43:846c/64 scope link 
       valid_lft forever preferred_lft forever
$ ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -f1 -d'/'
192.168.122.236
</broadcast,multicast,up,lower_up></broadcast,multicast,up,lower_up></loopback,up,lower_up>

Displaying the public IP address

If you want to know the public IP address of a Linux server, you can send an HTTP request to one of the following web servers.

  • http://ifconfig.me
  • http://www.icanhazip.com
  • http://ipecho.net/plain
  • http://indent.me
  • http://bot.whatismyipaddress.com
  • https://diagnostic.opendns.com/myip
  • http://checkip.amazonaws.com
  • http://whatismyip.akamai.com

If the Linux system is connected directly to the internet, the public and private IP addresses will be the same. However, in most cases they differ. Here is an example using the curl command.

$ curl ifconfig.me
216.239.32.10
$ curl icanhazip.com
216.239.32.10
$ curl ipecho.net/plain
216.239.32.10
$ curl ident.me
216.239.32.10
$ curl bot.whatismyipaddress.com
216.239.32.10
$ curl https://diagnostic.opendns.com/myip
216.239.32.10
$ curl http://checkip.amazonaws.com
216.239.32.10
$ curl http://whatismyip.akamai.com
216.239.32.10