What are the different ways to get IP Address of our Linux system?

In this article, we will check how to grep the IP address of our system and netmask in a quick way.

1. Using “ip addr” command.
This command also fetches static, dynamic, or wlan ip.

[root@nglinux ~]# ip addr | grep -Po "\d{1,3}.*/24"
192.168.52.138/24
[root@nglinux ~]#

2. Using ifconfig command.

[root@nglinux ~]# ifconfig -a | grep -i 'inet addr'
          inet addr:192.168.52.138  Bcast:192.168.52.255  Mask:255.255.255.0
          inet addr:127.0.0.1  Mask:255.0.0.0
[root@nglinux ~]#

3. Using hostname command

[root@nglinux ~]# hostname -i
127.0.0.1
[root@nglinux ~]# hostname -I
192.168.52.138 
[root@nglinux ~]# 

The above command uses below options:
-i, –ip-address addresses for the hostname
-I, –all-ip-addresses all addresses for the host

Hence, these are three different ways to get IP address of our linux system, the one other way is to check from GUI.

I hope you liked the article.

Please do subscribe to our blog to stay updated for latest articles.

Or, feel free to share any of your comments below.

0 0 votes
Article Rating
Subscribe
Notify of
guest

3 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
manish
manish
5 years ago

very good article..

Rohit
Rohit
Reply to  manish
5 years ago

is there any other way also