How to Find IP Address Linux [7 Easy Methods]

TL;DR

To find IP address Linux, try these methods:

Private IP Address:

  1. ifconfig Command: Enter ifconfig to display IP addresses under the inet or inet addr section of the respective network interface.
  2. ip Command: Type ip addr show to find IP addresses under the inet or inet6 section of the respective network interface.

Public IP Address:

  1. Curl Command: Run curl -4 ifconfig.me to fetch your public IP address from an external service.
  2. wget Command: Execute wget -qO- --inet4-only ifconfig.me to retrieve your public IP address from an external service.

Explore the article below to learn different methods to Linux find IP addresses on network and common errors with possible solutions.

Finding your IP address on a Linux system is crucial for troubleshooting network issues or setting up a server. In this guide, I’ll show you simple commands and tools like ifconfig, ip addr, hostname, nmcli, curl, and wget to find both private and public IP addresses quickly. You’ll also learn how to troubleshoot common errors that might arise. By the end of this post, you’ll be confident in managing your network settings effectively.

How to Find Private IP Addresses in Linux

To find private IP addresses in Linux, use either the ifconfig or ip addr show command in the terminal. The ifconfig command displays IP addresses under the inet or inet addr section of each network interface, while the ip addr show command lists IP addresses under the inet section.

Continue reading to learn four different methods to Linux command line get IP address:

1. ifconfig Command

The ifconfig command is a widely used networking tool in Linux that provides detailed information about network interfaces. It lets you find the IP address assigned to a specific network interface. Follow these steps to display IP address Linux:

  1. Open the Terminal.
opening terminal 7
  1. Enter the following command: 
ifconfig
  1. Locate the network interface you are interested in (e.g., eth0, wlan0). Look for the inet or inet addr section under the respective interface.
getting IP address using ifconfig in linux

2. ip Command

The ip command is a powerful and versatile networking tool in Linux. It provides advanced capabilities for managing network interfaces and retrieving IP addresses. Follow these steps to find ip address in Linux using ip command:

  1. Launch the Terminal window and type the following command: 
ip addr show
  1. Look for the inet or inet6 section under the respective interface.
displaying IP address using IP command

3. hostname Command

The hostname command provides information about the system’s hostname and related network configurations, including the IP address. It uses hostname resolution mechanisms like DNS or /etc/hosts file to map the hostname to its IP address. Follow these steps:

  1. Access the command line and execute the following command: 
hostname -I
  1. The IP address displayed represents the assigned IP address of your system.
showing ip address using hostname command

4. nmcli Command

The nmcli command provides a command-line interface for NetworkManager, a popular network management tool in Linux. It offers powerful capabilities for managing network connections, including retrieving IP addresses. Here are the steps to do it:

  1. Launch the command window and enter the following command: 
nmcli device show
  1. Look for the IP4.ADDRESS or IP6.ADDRESS section under the respective interface.
showing ip using nmcli command

How to Find Public IP Address in Linux

To find the public IP address in Linux, use either the curl -4 ifconfig.me or wget -qO- --inet4-only ifconfig.me command in the terminal. Both commands fetch your public IP address from an external service and display it directly in the terminal, providing a quick and easy way to identify your external network address.

1. Curl Command

The curl command can be used to interact with various web services. You can fetch your public IP address from an external service using curl. Here are the steps to check IP Linux:

  1. Open the Terminal and run the following command:
curl -4 ifconfig.me 

The IP address 124.29.212.219 is your public IP address.

checking public ip address using curl

2. wget Command

The wget command is another tool for interacting with web services. You can use it to fetch your public IP address from an external service. Follow the instructions to Linux check IP using wget command:

  1. Access your command window and execute the command:
wget -qO- --inet4-only ifconfig.me

The IP address 124.29.212.219 is your public IP address.

checking public ip address using wget

3. Using an Online Service

Online services can quickly provide your public IP address through a web browser. Here is how to do it:

  1. Open your preferred web browser (e.g., Firefox, Chrome).
opening web browser
  1. Go to a reliable IP lookup service such as whatismyipaddress.com or ipinfo.io. The website will display your public IP address.
viewing public ip address on web browser

Troubleshooting Common Issues in Finding IP Address Linux

Common issues are not uncommon when finding IP addresses in Linux. Here are five common problems that you might encounter:

🔍 “No IP address found” Error

This error occurs when attempting to retrieve an IP address in Linux, but no IP address is assigned to the specified network interface. It can happen if the interface is not properly configured, disconnected, or has a network connectivity issue.

To resolve this error, ensure the network interface is active, properly connected, and configured with a valid IP address.

⚠️ “Interface not found” Error

The “Interface not found” error appears when trying to find the IP address of a network interface that does not exist on the system. This error can occur if the interface name is misspelled, the driver is not installed, or the operating system does not recognize the interface.

To resolve this error, verify the correct interface name, ensure the driver is installed, and check if the Linux kernel supports the interface.

🔒 “Permission denied” Error

The “Permission denied” error occurs when the user executing the IP address retrieval command does not have sufficient privileges. This error commonly happens when running the command as a regular user instead of using elevated privileges such as sudo or root access.

To resolve this error, execute the command with the appropriate permissions, ensuring the user has the necessary rights to retrieve network information.

❌ “Invalid command or option” Error

The “Invalid command or option” error appears when using incorrect syntax or unrecognized options while trying to find an IP address in Linux. It can happen if the command is mistyped or if the command does not support the option provided.

To resolve this error, review the command syntax and ensure the correct options are used according to the documentation or help resources.

🌐 “Network unreachable” error

The “Network unreachable” error occurs when attempting to retrieve an IP address from a network that is not accessible or reachable. This error can happen if there is no network connection, the network configuration is incorrect, or there are routing issues.

To resolve this error, check the network connectivity, ensure the network configuration is accurate, and troubleshoot any routing problems that may be preventing access to the network.

Linux Check IP Address: Final Thoughts

In this article, I covered various methods to get IP address Linux, both private and public. I explored tools like ifconfig, hostname, ip addr, nmcli, wget, and curl, along with troubleshooting common errors such as “No IP address found” and “Permission denied.” By following these guides, you’ll efficiently find and manage IP addresses on your system.

For more insights, I suggest reading about:

Frequently Asked Questions

Can I retrieve the IP address of a remote machine using the Linux command line?

Yes, you can retrieve the IP address of a remote machine using the Linux command line. One way to accomplish this is by using the ping command followed by the remote machine’s hostname or IP address. For example, running ping example.com will display the IP address of the remote machine in the output. Additionally, you can use tools like nslookup or dig to query the DNS records and obtain the IP address of a remote machine. These commands provide detailed information, including the IP address associated with a specific hostname or domain.

How can I automate retrieving IP addresses using shell scripts in Linux?

Automating the process of retrieving IP addresses using shell scripts in Linux can be achieved by combining command-line tools and scripting capabilities. One approach is to use the ifconfig or ip command within a script to extract the IP address of a specific network interface. You can redirect the command output to a variable or a file for further processing or logging. You can create a robust automation solution to retrieve IP addresses from multiple machines or interfaces by incorporating loops, conditionals, and parsing techniques in your shell script.

Can I find the IP address of a website or domain name using the Linux command line?

Yes, you can find the IP address of a website or domain name using the Linux command line. The nslookup and dig commands are commonly used for this purpose. For instance, running nslookup example.com will display the IP address associated with the provided domain name. Similarly, using dig example.com will provide detailed information about the DNS records of the domain, including the IP address. These commands can be useful for troubleshooting DNS-related issues, verifying DNS configurations, or simply obtaining the IP address of a specific website or domain.

Ojash

Author

Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.

Akshat

Reviewer

Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Detach Tmux Session: 4 Comprehensive Methods

Next Post

How to Change IP Address Linux [3 Effective Methods]

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next