How to get IP Address in Linux?

How to get IP Address in Linux?

3 mins readComment
Updated on Nov 28, 2023 22:41 IST

In Linux, an IP address is essential for network communication. Use terminal commands like ip addr, ifconfig, nmcli, etc., to display the IP addresses for all network interfaces, providing crucial connectivity information for your Linux system.

Table of Content

Recommended online courses

Best-suited Database and SQL courses for you

Learn Database and SQL with these high-rated online courses

– / –
2 months
4.24 K
6 weeks
– / –
15 hours
– / –
– / –
– / –
30 hours
– / –
1 hours
– / –
31 hours
– / –
80 hours

What is an IP Address?

An IP address is a unique numerical label assigned to each device on a network, used for identifying the device and its location in the network.

IP addresses are essential for enabling communication between devices on the internet. They consist of a series of numbers separated by periods (e.g., 192.168.0.1 for an IPv4 address or 2001:0db8:85a3:0000:0000:8a2e:0370:7334 for an IPv6 address). IPv4 addresses, which use a 32-bit format, are more common, while IPv6 addresses, which use a 128-bit format, are becoming increasingly prevalent to accommodate the growing number of internet-connected devices.

Primarily there are two types of IP addresses: public and private.

  1. Public IP addresses are assigned by internet service providers (ISPs) to devices that are directly accessible from the internet. They are unique globally, allowing devices to communicate with each other across different networks. 
  2. Private IP addresses are used within local networks, such as home or office networks, and are not directly accessible from the internet. They enable devices to communicate with each other within the same network, but they cannot be used for direct communication with devices outside the network.

In this article we are going to explore various was of getting Ip Address in Linux.

Difference Between Static IP and Dynamic IP

IPv4 vs IPv6 - Why is IPV4 Getting Replaced by IPv6?

Understanding the Difference between IP Address and MAC Address

Get IP Address From the Command Line

Let’s take a look at various was of getting your p Address using command line in Linux:

Explore: Online Linux Courses and Certfications

Using the hostname Command

This command displays the IP addresses associated with the hostname and is used with the -I option as shown below:


 
hostname -I
Copy code

Output:

Using ifconfig Command

We can also make use of the ifconfigm command to display the network configuration information, including the IP address as shown below:


 
ifconfig
Copy code

Output:

Using ip addr Command

The ip addr command provides comprehensive information about IP addresses and routing.


 
ip addr show
Copy code

Output:

Using nmcli Command

The Network Manager Command-Line Interface can be used to view network-related information, including the IP address.


 
nmcli device show
Copy code

Output:

Using ifconfig.me Command

This command uses the curl utility to fetch your public IP address from the ifconfig.me service.


 
curl ifconfig.me
Copy code

Output:

Using the dig utility command

The below command uses the dig utility to query the resolver1.opendns.com DNS server and retrieve your public IP address.


 
dig +short myip.opendns.com @resolver1.opendns.com
Copy code

Output:

Using wget utility command

The below command uses the wget utility to fetch your public IP address from the ifconfig.me service.


 
wget -qO- ifconfig.me/ip
Copy code

Output:

Get Your IP Address in Linux With GUI

Follow the below steps to get your IP Address in Linux with GUI:

Explore: GUI Courses and Certfications Online

Step 1: Open up settings. 

Step 2: Navigate to the Network tab and click on Advanced Wired Setting icon.

This opens a pop-up window showing wired settings, including your IPv4 and IPv6 addresses.

Conclusion

In this article we have covered multiple ways to get your public and private Ip Address in linux system. We explored both the command line and GUI ways of achieving the same. IP addresses play a crucial role in routing data packets across the internet. When you send a request to a website or any other online service, your device's IP address is included in the data packet. This address helps ensure that the response from the requested server reaches your device accurately. Additionally, IP addresses are used for various purposes, such as geolocation, network troubleshooting, and security measures like IP blocking or filtering.

Contributed By: Raju Kumar

About the Author

This is a collection of insightful articles from domain experts in the fields of Cloud Computing, DevOps, AWS, Data Science, Machine Learning, AI, and Natural Language Processing. The range of topics caters to upski... Read Full Bio