Kiến Thức Linux

How to Find Your IP Address in Linux

Tutorial on how to find your IP address on Linux.

Introduction

An IP address is a sequence of numbers assigned to each computer to identify its logical location within a network. Devices in a network must have unique IP addresses to ensure traffic is routed accurately and delivered to the correct computer.

IP addresses are the first piece of information system administrators look for when managing and troubleshooting networked systems.

Find out how to retrieve your IP address using the Linux command line or GUI.

Tutorial on how to find your IP address on Linux.Tutorial on how to find your IP address on Linux.

Prerequisites

Finding Private IP Addresses in Linux

Private IPs function within a local network and are not directly exposed to the internet. Knowing the private IP address is necessary when configuring advanced network settings, local servers, printers, and other devices on the same internal network.

Access the Linux command line and use one of the commands below to find your private IP address.

Note: The examples in this article are presented using Ubuntu 22.04.

Using ip Command

The ip command is a standard utility for network management in Linux systems. Use the following command to check the system’s private IP address:

ip a

The system will scan hardware and display the status of each network adapter. The entries include one for a wired (Ethernet) adapter and a wireless (Wi-Fi) adapter. You may also have an entry for a virtual adapter.

The inet line shows the IPv4 address assigned to that interface. In this example, the private IPv4 for the Ethernet interface is:

10.0.2.15

The IPv6 address for the same interface is under the inet6 line:

fe80::a00:27ff:fe76:1e71
Check IP in Linux using ip command.Check IP in Linux using ip command.

The numbers after the slash, /24 and /64, specify the length of the network prefix, and help determine how the IP address space is partitioned into networks and subnets.

Using hostname Command

The Linux hostname command is used to configure the system’s hostname but can also retrieve IP address information.

Note: The output of hostname commands can vary depending on the Linux distribution and local network settings. The ip command provides a more consistent overview of IP information across different distributions.

Enter the following command to retrieve your private IP address:

hostname -I
Checking the private IP in Linux using the hostname command. Checking the private IP in Linux using the hostname command.

In this example, the Ubuntu 22.04 system displays the private IPv4 address.

Using ifconfig Command

The third method to find your IP address involves using the ifconfig command.

Important: ifconfig has been deprecated in favor of the ip command in many Linux distributions, but it is still available on some systems or can be installed separately.

Enter the following command to check the private IP address on your system:

ifconfig
The ifconfig command in Linux displaying IP address information.The ifconfig command in Linux displaying IP address information.

The system displays all network connections, including connected, disconnected, and virtual. Look for the one labeled UP, BROADCAST, RUNNING, MULTICAST to find your IP address. This lists both IPv4 and IPv6 addresses.

Note: While checking the IP address, you may notice the term Loopback. This refers to an IP address that returns traffic to the same computer. Usually, the loopback address is 127.0.0.1.

Using GUI

If using a point-and-click interface to navigate the Linux system, you can check your IP address by following these steps:

1. Open the Application menu.

2. Type settings into the search bar.

3. Click Settings.

Access network setting in Linux GUI.Access network setting in Linux GUI.

4. Open the Network tab.

5. Click the Advanced Wired Settings icon.

Access advanced network settings in Linux GUI.Access advanced network settings in Linux GUI.

6. This opens a new pop-up window with details on wired settings.

check ip address in wired detailscheck ip address in wired details

Both the IPv4 and IPv6 addresses are listed.

Finding Public IP Address in Linux

Before connecting to a network, computers connect to a router using a local IP address. The router, in turn, connects to a bigger network (like an Internet Service Provider) with its own IP address system. This is the IP address registered on a website when you visit it.

Note: Learn everything you need to know about public and private IP addresses in our article Public vs. Private IP Address.

Using IP Lookup Websites

You can reach out to an external service to find your public IP address. Use a browser to navigate to one of the following online IP lookup tools:

Public IP returned in browser after online lookup.Public IP returned in browser after online lookup.

The websites typically display the public IP address within the browser.

Alternatively, use command-line tools like curl, wget, or dig to display the external IP address. More information is in the sections below.

Using curl

The curl command is primarily used to transfer data over various network protocols. It can also retrieve a system’s public IP address. Enter the following command to display the system’s public IP from icanhazip.com:

curl -s https://icanhazip.com
Lookup public IP address in Linux using the curl command.Lookup public IP address in Linux using the curl command.

The system returns the public IP address in the terminal.

Note: Did you know that when you use curl to connect to an insecure website, the output responds with an error? To resolve this issue, visit our guide on making curl ignore certificates.

Using wget

The wget command retrieves files from the internet, including IP addresses. Use the following command to check your public IP from the Amazon AWS website:

wget -O - -q https://checkip.amazonaws.com
Lookup public IP address in Linux using the wget command.Lookup public IP address in Linux using the wget command.

The IPv4 address in this example is 172.245.175.109.

Using dig

The dig command gathers and displays DNS information. You can use dig to find out the public IP address of your system by querying an external DNS server. The following command asks the OpenDNS resolver for the public IP address of your system:

dig +short myip.opendns.com @resolver1.opendns.com
Lookup public IP address in Linux using the dig command.Lookup public IP address in Linux using the dig command.

The +short option simplifies the output and only displays the IP address.

Conclusion

The guide showed how to find a private and public IP address in Linux using the command line, graphical interface, and external IP lookup services.

It is challenging to remember every single Linux network command at a moment’s notice. Keep our downloadable Linux network commands cheat sheet handy whenever you need a swift refresher.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !