The immediate responsibility of every network administrator or engineer is to manage the subnetwork entrusted to him. And in order to understand the current sta...
3v-Hosting Blog
11 min read
Knowing how to obtain the IP address of your Linux server is important for system administrators, software developers, and anyone involved in network management. The concept of IP is fundamental to networking and is essential for network communication, allowing devices to identify and connect to each other. In this article, we will look at several methods for obtaining your IP address in a Linux environment, both internal and external, using various commands and tools.
An internal IP address (also known as a private IP address) is used on a local network and is not routable on the Internet. They are important for internal communication within a network, but they also save a lot of IP addresses by allowing the same IP addresses to be used on different networks. For example, your company's local network is configured with addresses from the 192.168.12.0/24 subnet. Another company has configured exactly the same network with the same IP addresses. These internal addresses are internal because they do not go out to the Internet, and these two companies communicate via an external, public IP address.
Below is a table with IP address blocks that refer to so-called internal addresses.
Table - Comparison of internal subnets
| Subnet (CIDR) | Address range | Typical usage scenarios |
|---|---|---|
| 10.0.0.0/8 | 10.0.0.0 – 10.255.255.255 | Large corporate networks, distributed offices, data centers with extensive subnetting |
| 172.16.0.0/12 | 172.16.0.0 – 172.31.255.255 | Medium-sized company networks, server zones, infrastructure segments requiring flexible subnetting |
| 192.168.0.0/16 | 192.168.0.0 – 192.168.255.255 | Home networks, office VPNs, Wi-Fi segments, small business networks |
They are very easy to remember and understand that if you see one of the addresses from these subnets somewhere, it is an internal address.
The ip command is a universal tool for configuring and managing a network in Linux. It has largely replaced the old ifconfigcommand.
Run the following command in the terminal:
ip addr show
This command displays detailed information about all network interfaces. Find the inet entry under the desired interface (e.g., eth0, wlan0). The output will show the IP address, subnet mask, and other information.
user@host:~# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether f0:c6:f9:ca:d6:c6 brd ff:ff:ff:ff:ff:ff
inet 192.168.12.7/24 brd 192.168.12.255 scope global dynamic noprefixroute ens0
valid_lft 70376sec preferred_lft 70376sec
Although the ifconfig command has been deprecated in favor of the ipcommand, it is still available in many distributions.
Run the following command in the terminal:
ifconfig
This command will display a list of all network interfaces with their corresponding IP addresses. The inet addr field shows the IP address of each interface.
user@host:~# ifconfig
ens0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.12.7 netmask 255.255.255.0 broadcast 192.168.12.255
ether f0:c6:f9:ca:d6:c6 txqueuelen 1000 (Ethernet)
RX packets 358201 bytes 22181271 (0.2 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 331273 bytes 20447094 (0.2 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
The hostname command with the -I option can also be used to display the IP addresses associated with the host.
Run the following command in the terminal:
hostname -I
This command displays all IP addresses assigned to the host, separated by spaces.
user@host:~# hostname -I
192.168.12.7
nmcli is a command-line tool for managing NetworkManager, which is widely used in various Linux distributions.
Run the following command in the terminal:
nmcli device show
This command displays detailed information about all network interfaces managed by NetworkManager, including IP addresses.
user@host:~# ifconfig
GENERAL.DEVICE: ens0
GENERAL.TYPE: wifi
GENERAL.HWADDR: F0:C6:F9:Ca:D6:C6
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: MyWiFi
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/11
IP4.ADDRESS[1]: 192.168.12.7/24
IP4.GATEWAY: 192.168.12.1
IP4.ROUTE[1]: dst = 192.168.12.0/24, nh = 0.0.0.0, mt = 600
IP4.ROUTE[2]: dst = 0.0.0.0/0, nh = 192.168.12.1, mt = 600
IP4.DNS[1]: 192.168.12.1
You can use the ip route command to get the IP address of your primary network interface.
Run the following command in the terminal:
ip route get 1.1.1.1
Replace 1.1.1.1 with any valid IP address. The command will show routing information and the source IP address used to reach the destination.
user@host:~# ip route get 8.8.8.8
8.8.8.8 via 192.168.12.1 dev ens0 src 192.168.12.7 uid 0
Although the ifconfig command is still present in many distributions, it is preferable to use ip in modern systems. This is because the net-tools package, which includes ifconfig, has not been developed for a long time and does not support some of the current network functions. The ip command provides more accurate, detailed, and up-to-date information about network interfaces, routing, link-layer parameters, and connection states.
Using ifconfig is appropriate when you are working on an old system or in a minimal installation where iproute2 is not available. However, in a full-fledged Linux environment and on server distributions, the ip command is the de facto standard and provides a more accurate display of network settings.
The external IP address (also known as the public IP address) is used to identify your device on the Internet. This IP address is routed on the Internet and is assigned by your Internet service provider (ISP).
Curl is a command line tool for transferring data using URLs. It can be used to access web services to obtain your public IP address, such as ifconfig.me.
Run the command in the terminal:
curl ifconfig.me
This command sends a request to ifconfig.me and displays your public IP address.
user@host:~# curl ifconfig.me
94.211.13.25
wget is another command line utility for downloading content from web servers. It can also be used to query your public IP address. Let's look at an example with another web service, icanhazip.com
Run the command in the terminal:
wget -qO- icanhazip.com
This command also extracts the public IP address from ifconfig.me and outputs it to the terminal.
user@host:~# wget -qO- icanhazip.com
94.211.13.25
In fact, there are many services similar to ifconfig.me, and below we have provided a comparison table of such services.
Table - Comparison of external IP address detection services
| Service | Type | Response speed | Additional data |
|---|---|---|---|
| ifconfig.me | HTTP API | Very high | Can return User-Agent, headers, geodata |
| icanhazip.com | HTTP / HTTPS | Very high | Only IP address, minimalistic output |
| api.ipify.org | HTTP / HTTPS API | High | JSON output format, convenient for automation |
| checkip.amazonaws.com | HTTP | High | Reliable service from AWS, returns only IP |
| ipinfo.io/ip | HTTP / HTTPS API | Average | Supports full network and geolocation information |
| myip.opendns.com (via DNS) | DNS query | High | Can be used without HTTP connections and web traffic |
dig (Domain Information Groper) is a powerful utility for searching for information from DNS servers. It can be used to find out your public IP address by querying OpenDNS.
Run the command in the terminal:
dig +short myip.opendns.com @resolver1.opendns.com
This command sends a DNS query to OpenDNS, which responds with your public IP address.
user@host:~# dig +short myip.opendns.com @resolver1.opendns.com
94.211.13.25
The host command is another DNS server lookup utility that can be used to find out your public IP address.
Run the command in the terminal:
host myip.opendns.com resolver1.opendns.com
This command queries OpenDNS and returns your public IP address.
user@host:~# host myip.opendns.com resolver1.opendns.com
Using domain server:
Name: resolver1.opendns.com
Address: 208.67.222.222#53
Aliases:
myip.opendns.com has address 94.211.13.25
If you prefer to work in a graphical interface, most modern Linux distributions allow you to find out your IP address through the standard network settings. Depending on the desktop environment you are using (GNOME, KDE Plasma, or others), the interface may vary slightly, but the logic remains the same: open the network settings and view the information about your current connection.
GNOME is one of the most common desktop environments in Ubuntu, Fedora, and Debian.
To view your IP address, follow these steps:
GNOME automatically updates this data, so the information is always up to date.
KDE Plasma is used in Kubuntu, openSUSE, and Manjaro distributions. The interface is different from GNOME, but the necessary data is found in a similar way:
Plasma provides more detailed information about the connection, including route status and interface activity.
Almost all Linux systems with a graphical environment use NetworkManager, which provides a unified interface for network configuration. In most distributions, all you need to do is:
Here you can see the IP address, MAC address of the interface, and routing parameters.
To determine your external (public) IP address, you can use any web service that displays connection information. For example, just open the website https://2ip.io or a similar resource and your IP will be displayed automatically.
Please note that when using a VPN, proxy, or browser extensions, the data will be different: the service will show the IP address of the intermediate node, not your actual connection. This is important to consider when diagnosing network problems or checking server configurations.
When checking your public IP address, it is important to note that the result displayed may depend not only on your local machine, but also on the infrastructure of your provider or intermediate services. In some situations, IP detection services do not show your actual address, but rather the IP address of the nodes through which the traffic passes.
Several parameters described below can affect the result.
If your traffic is routed through a CDN or proxy service, the external address may belong to the cloud network rather than your server. This is especially important for web projects with Cloudflare's “proxy” mode enabled — the site will be displayed with Cloudflare's IP address rather than the original server's.
Some providers use NAT on their side. In such cases, several clients receive one shared external IP address. Such configurations are typical for mobile networks and some budget plans.
When a VPN or proxy browser (such as Opera's built-in VPN) is enabled, all websites will show the IP address of the server you are connected to, rather than your real address. This can be misleading when diagnosing network issues.
In corporate networks, traffic is often routed through a proxy gateway. In this configuration, the public IP belongs to the corporate node, not to a specific user workstation.
Consider these features before drawing conclusions or configuring network services: sometimes differences in service readings are a normal consequence of network infrastructure operation.
The internal IP address is only used within your local network and does not go out to the Internet. The external IP is assigned by the provider and is accessible from the global network. Between them, there is usually a router that performs address translation (NAT), allowing multiple internal devices to use a single external IP to access the Internet.
The hostname -I command displays all IP addresses assigned to the system. If there are multiple interfaces (Ethernet, Wi-Fi, virtual interfaces, Docker, VPN tunnels), each of them may have its own IP. Therefore, the output often contains multiple values.
The ip command is part of the iproute2 package, which is installed by default in most distributions. If the utility is missing, you can install it manually via the package manager.
Examples:
Debian/Ubuntu: apt install iproute2
RHEL/CentOS/Rocky: yum install iproute
This can happen if your traffic goes through your provider's NAT, VPN, proxy, CDN, or transparent gateways. Also, different services can determine IP at different levels (through HTTP requests or through DNS), which affects the result. Therefore, several different values are not always an error.
In this case, you can only determine the internal IP address assigned by the local network. The commands ip addr, ifconfig, nmcli, and hostname -Iare suitable for this. It is impossible to obtain the external IP without Internet access, as it is only determined by external services or the provider's network registries.
Obtaining a Linux IP address, whether internal or external, is a fundamental task for network management and troubleshooting. The methods discussed in this article provide various ways to access this information using command line tools, graphical applications, or a web browser. Whether you prefer to use the ip command, use web services with curl or wget, or use graphical interfaces, understanding these methods ensures that you can effectively manage network configurations on Linux-based servers and troubleshoot related issues.
Accelerating WordPress at the Nginx level: correct PHP-FPM settings, try_files, static files, caching, Brotli, wp-login protection, and secure headers for stabl...
Effective backup strategies for Docker applications: how to protect volumes, data, and configurations while avoiding common mistakes, and quickly restore servic...
A clear guide to what VPS is used for: real cases, examples for developers, business setups, VPN, CI/CD and more. Learn how to choose the right VPS plan.