3 ways to get your IP on a Linux system ?

To know your IP is very important whether you are at home or in office and when it comes to get it on a Linux system some peoples finds it tricky. So I will show you guys 3 easy trick to get your IP.

One
Type this command on your terminal:

$ip a s 

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    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 group default qlen 1000
    link/ether 80:86:8e:9c:b6:a8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.24/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe90::4326:9eff:fe9c:56a6/64 scope link 
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 59:95:39:a9:19:af brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.66/24 brd 192.168.1.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet6 fe70::5655:50ff:fea9:51af/64 scope link 
       valid_lft forever preferred_lft forever

How we read that ?

” 1: ” means the interface number and ” lo ” is the interface name. The “Inet” section is where you got your IP address “127.0.0.1/8”.

In most of Linux machine you will have a loop-back interface and this interface is virtual and it’s normal to have it on your machine don’t worry about that.

“eth0” is the interface where generally there is a wired connection (RJ45) connected and if it happens that you have a second Rj45 connection your will have “eth1” and so on.

For wireless interface it will be denoted as “wlan0” and if you have another WIFI interface you will “wlan1” and so on …

So this is the basics that you should know about. Lets move to the next command :

Two

Type this command in a terminal :

$ ifconfig 
eth0      Link encap:Ethernet  HWaddr 50:86:7e:9c:b8:86  
          inet addr:192.168.1.66  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::4216:7eff:fe9c:b6a6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:178283 errors:0 dropped:170 overruns:0 frame:0
          TX packets:89093 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:229842742 (229.8 MB)  TX bytes:7948564 (7.9 MB)
          Interrupt:19 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:20923 errors:0 dropped:0 overruns:0 frame:0
          TX packets:20923 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:3803242 (3.8 MB)  TX bytes:3803242 (3.8 MB)

wlan0     Link encap:Ethernet  HWaddr 34:35:60:a9:91:af  
          inet addr:192.168.1.69  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::5635:30ff:fea9:11af/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:234997 errors:0 dropped:0 overruns:0 frame:0
          TX packets:132308 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:180199856 (180.1 MB)  TX bytes:17769274 (17.7 MB)

As you can see the result is nearly the same, one which you can see more clearly is the Mac address of the interface : “HWaddr 50:86:7e:9c:b8:86”. Of that is not my real Mac address as its a unique number :D.

Three

Type this on your terminal :

$cat /proc/net/fib_trie

Main:
  +-- 0.0.0.0/4 1 0 0
     |-- 0.0.0.0
        /0 universe UNICAST
     |-- 10.249.10.0
        /24 link UNICAST
        /24 link UNICAST
Local:
  +-- 0.0.0.0/1 1 0 0
     +-- 192.168.1.0/24 1 0 0
        +-- 192.168.1.0/26 2 0 1
           |-- 192.168.1.0
              /32 link BROADCAST
              /32 link BROADCAST
           |-- 192.168.1.66
              /32 host LOCAL
           |-- 192.168.1.96
              /32 host LOCAL
        |-- 192.168.1.255
           /32 link BROADCAST
           /32 link BROADCAST
     +-- 127.0.0.0/8 1 0 0
        +-- 127.0.0.0/31 1 0 0
           |-- 127.0.0.0
              /32 link BROADCAST
              /8 host LOCAL
           |-- 127.0.0.1
              /32 host LOCAL
        |-- 127.255.255.255
           /32 link BROADCAST

Yes I know it is very hard to look for your IP in that kind of output I made a bonus command to make it easier for you to get the ip :

Bonus stage :

$cat /proc/net/fib_trie | grep -B 1 "32 host LOCAL"

           |-- 192.168.1.66
              /32 host LOCAL
           |-- 10.168.1.69
              /32 host LOCAL
--
           |-- 127.0.0.1
              /32 host LOCAL

Hope this helps you guys drop me any questions you have any difficulties or issues.

Article by Ash

“Your eyes can deceive you. Don’t trust them.” – Obi-Wan Kenobi