- How to Get IP Address in Linux
- Basics
- How to Find a Local IP Address in Linux
- How to Find IP Address in Local Network Linux
- How to find External IP Address in Linux
- Wrapping Up
- How to Find or Check Your IP Address in Linux
- Find Your IP Address From the Command Line
- Using the hostname Command
- Using the ip addr Command
- Using the ifconfig Command
- Finding Your IP Address in Linux With a GUI
- How to Find Public IP Address
- What is a Public/Private IP Address?
How to Get IP Address in Linux
Each computer connected to the Internet must have an identifier. In the past, every computer had a unique address that could be used to connect to it. This address is called IP address. Nowadays, most home computers are hidden behind Network Address Translation (NAT), and only servers have public IP addresses.
IP addresses allow computers and servers to communicate with each other on a network. While this is more relevant for servers, it can also be useful for home computers and local networks. In this article, I will explain how to get IP Address in Linux in different ways. I will explain different ways how to find an external IP address which is visible on the Internet and a local address in your local network.
Basics
First of all, let’s take a look at what is an IP address and how it works. There are three types of IP addresses:
- Internal IP address;
- IP address in local network;
- External IP address that is available on the Internet.
The internal IP address or loopback address allows programs to communicate with each other on the same computer using network protocols. For example, a browser can interact with a local web server. Loopback IP address is quite often used in system utilities and it is pretty easy to find it. It is always the same — 127.0.0.1.
In local network, things become a little more complicated. The Internet is not a peer-to-peer network where all computers are connected to each other at the same level, but many separate networks that are connected via routers. If your computer is connected to the Internet using a wired connection, you have a router to which you can connect multiple devices such as a computer, a laptop, and a smartphone. The network created by the router is called a local network, and on that network, the computer has an IP address that you can use to access it from other devices on that network. But for your ISP and the external Internet, all of these devices will have the same IP address — the router address.
Now, let’s have a look at an external IP address. ISP providers unite their clients into a local network so that they all have the same external IP address for the Internet as well as you do this for your home devices. They do this because the Internet is very popular and IP addresses are limited. Today, only servers have white unique white IP addresses, and most other devices are placed by ISPs on one IP with NAT technology. This IP address is considered an external address.
Previously, ISPs gave users dynamic IPs, which were unique and changed when the router was rebooted. They allowed users to access their PC from the Internet with little router configuration. But then, they started using NAT technology to place hundreds of users on the same IP. However, this is not a big issue because it is safer for home PCs as nobody can access them from the Internet. If you want to access your PC over the Internet, you can use VPN or Ngrok.
The NAT technology allows PCs to interact with any server on the Internet, and receive a response from it. But it is impossible to initiate a connection to this computer from the outside because one external IP belongs to hundreds of computers, and the system just does not know which one is being addressed.
As you have realized, your home computer could have an external IP address available to everyone, but this is impractical for at least two reasons. Firstly, it is expensive, and secondly, it is very insecure. This is why connecting your computer to the Internet now looks something like this:
- An external and publicly accessible IP that belongs to your ISP and is used to access the Internet by hundreds of users;
- The IP address of your router in your ISP’s local network. It is not accessible from the Internet, and you probably don’t need it;
- The IP address of your computer in the local (home) network created by the router which you use to connect your devices. This IP address can be used for communication between your local devices;
- The internal IP address of your computer, which is not accessible from the outside and is used only for internal communications within the system.
Now, you know all necessary basics. Let’s have a look at how to get IP address in Linux.
How to Find a Local IP Address in Linux
As mentioned before, the internal IP address is the same for every computer — 127.0.0.1. It works the same way on all operating systems. All IP addresses in the range from 127.0.0.1 to 127.255.255.255 are bound to loopback network interface and are used for local communication within the computer. Additionally, you can access your computer via the localhost domain. You can verify this by running the ping command:
ping -c 3 localhost
How to Find IP Address in Local Network Linux
It is not very difficult to find IP address Linux in a local network. You don’t need any additional services to accomplish this, you can just look up the network connection information with the ip command. Here is the most convenient way to do it:
ip -br a
Here the -br option enables brief mode output and the a command means «addresses management». You should also add the s or show command by syntax, but you can skip it because it is used by default anyway. Here is the full version of the command:
ip —brief address show
When your run this command you will see the list of all network interfaces in the system, their state, and address. Let’s have a look at their description:
- lo — local network interface, which always points to the current computer;
- enp* — wired network interface, stands for Ethernet PCI. The name eth* can also be used.
- wlp* — WiFi wireless network interface, stands for Wireless PCI. The name wlan* can also be used.
In this case, the wired interface has the name enp3s0 and you can see its IP address in the third column. If you want to get an IP address for a specific interface, for example, enp3s0, use the following command:
ip —brief address show enp0s3
Additionally, you can filter only the IP address value with the following command:
ip —brief address show enp0s3 | awk » | cut -d’/’ -f1
IP addresses on the local network must be in the following ranges:
- From 192.168.0.0 to 192.168.255.255
- From 10.0.0.0 to 10.255.255.255
- From 172.16.0.0 to 172.31.255.255
- From 100.64.0.0 to 100.127.255.255
These addresses are reserved for local networks and cannot be used for public access.
You can also use the deprecated ifconfig command. But you must install it first:
sudo apt install net-tools
It displays a lot of information such as: the MAC address, the netmask, and some statistics about the interface performance. The IP address itself is displayed after the word inet:
sudo ifconfig
To display only the IP addresses in the output, you can use the following command:
sudo ifconfig | grep «inet»
How to find External IP Address in Linux
Each website can see your external IP address. You can open a special website, which will look at your IP and tell it to you. There are quite a few of these sites. The easiest way to do this is with your browser, for example, open the website ifconfig.me:
However, this may not always be convenient. Sometimes, it is better to do it with a terminal. Just use the curl or wget command. Here is the list of a few such websites:
wget -qO- ifconfig.me curl ifconfig.me curl ipinfo.io/ip curl ipecho.net/plain curl icanhazip.com curl ipecho.net/plain curl ident.me curl api.ipify.org
To avoid typing a long command every time, you can create an alias using the alias command:
alias getip=»curl ifconfig.me» getip
Don’t forget to add this line to the ~/.bashrc file.
If you want to find IP address of your router in the ISP’s local network, this approach will not help. You can find this information in the router settings or router’s command line.
Wrapping Up
Now, you know how to get IP address in Linux. It’s not as hard as you might think. You can still use the hostname utility with the -I option to get all the network addresses assigned to your computer or you can look up the IP address in NetworkManager GUI or with its console tool nmcli. But the ways described in the article are more versatile and simple. What tool do you use? Write in the comments!
Found a mistake in the text? Let me know about that. Highlight the text with the mistake and press Ctrl+Enter.
How to Find or Check Your IP Address in Linux
An IP address is a codename assigned to a computer on a network. It works as a postal address, ensuring that network traffic is sent to the correct computer.
In this tutorial you will learn how to find your IP address using a Linux operating system.
Find Your IP Address From the Command Line
There are a few different commands you can use to check your IP address. To run these commands, start by opening a terminal window/command line.
Using the hostname Command
One way to check your IP address from the command-line is by using the following command:
The system will display your internal IP address.
Using the ip addr Command
Check your ip address with the ip addr command:
The system will scan your hardware, and display the status for each network adapter you have. Look for an entry that says link/ether. Below it, you should see one of the following:
inet6 fe80::a00:27ff:fe76:1e71/64
The entries will include one for a wired (Ethernet) adapter and a wireless (Wi-Fi) adapter. You may also have an entry for a virtual adapter. Generally, only one entry will have an IP address listed – that is the one you will want.
Note: The number after the slash – /24 and /64 – specifies the size of the network, and it helps with scanning and mapping network size.
Using the ifconfig Command
The third method to find your IP address involves using the ifconfig command. In the command line, enter the following:
The system will display 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: When you check your 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 . If you see that address listed, either you are looking at the wrong line, or you are not connected to the network.
Read phoenixNAP’s ultimate Linux IP command tutorial with 31 examples to learn more!
Finding Your IP Address in Linux With a GUI
If you are using a point-and-click interface to run your Linux system, you can check your IP address by following these steps:
1. Go to the Application menu and type Settings into the search bar.
2. Click on the Settings icon that appears among the results, as in the image below:
3. Next, find the Network tab in the Settings Menu and click on the Advanced Wired Settings icon.
4. This opens a new pop-up window with details on wired settings. Here you can find both your IPv4 address and your IPv6 address.
How to Find Public IP Address
To find your public IP address, reach out to an external website.
If you are using a browser, navigate to:
If you are using a command-line or terminal, use a retrieval command like curl or wget to display the external IP address:
wget -O - -q https://checkip.amazonaws.com
Note: Did you know that when you use curl to connect to an insecure website, the output responds with an error? To resolve it, visit our guide on making curl ignore certificates.
What is a Public/Private IP Address?
Each computer in a network is required to have its own IP address. If two systems have the same IP address, it will generate errors on the network. Most modern networks will detect the problem and prompt you to fix it. However, older networks might get confused, trying to route traffic to both computers.
Most systems will have two different IP addresses:
- Private IP address: This is the address used on the network. Also, it is the one you will want to use for configuring routing tools. On smaller networks, the internal IP address typically starts with 192.168.x.x. It is dynamically assigned to your computer whenever you connect.
- Public IP address: This is the IP address that registers on a website when you visit it. When you connect to a small network, your computer connects to a router using an internal IP address. That router, in turn, connects to a bigger network (like an Internet Service Provider), which has its own IP address system.
Note: Learn everything you need to know about public and private IP addresses in our article Public vs. Private IP Address.
Now you know how to find a private and public IP address in Linux using multiple methods.
Each option strikes a balance between speed and complexity. Now you have the flexibility to choose, if you only need your internal IP address, you can use the hostname method. If you need more detailed information, view our article on 31 Linux IP Commands with examples.