How To Find IP Address In Linux (Ubuntu, Debian, Mint, CentOS)?

The IP address is the core of the computer networks where we use an IP address in our daily life regularly. When we try to access a web page or a game or a video stream the remote server IP address is used to connect and data transfer.

IP Address Types

IP is a protocol designed to be used in different network environments and provides different IP addressing schemes. One of the most popular IP address types is Public IP Address and Private IP Address.

  • Public IP Address is used inside the internet between clients, servers, modems, routers, etc. It can be also called a MAN or WAN-specific IP address.
  • A private IP Address is used inside the local network or LAN. It is mainly used to access the gateway of the local network and does not use on the internet. Generally, the internet gateway will use its own Public IP Address for transmission over the internet. Also, WiFi, Routers, and modems provide private IP addresses to the LAN clients. The public IP address range is 10.0.0.-10.255.255.255, 172.16.0.0-172.31.255.255 and 192.168.0.0-192.168.255.255.

Find Private IP Address with ifconfig Command

The ifconfig was the most popular network configuration command provided by all major Linux distributions. But recently it is replaced with the ip commands described below. The ifconfig command can be used to print a Private IP address. We will provide the -a parameter which will print the IP addresses assigned to the interfaces.

$ ifconfig -a

Find Private IP Address with ip address Command

The ip address command is a defacto command used to display and manage network-related information like IP address, Default gateway, etc. The “ip address” command can be used to print the private IP address of the current Linux system.

$ ip address

In a more practical way, the address can be shortened as add even a .

$ ip add

$ ip a

Find Private IP Address with ip route Command

The ip route command is used to display and manage the IP routing table. But it can be also used to find the private IP address of the Linux system. In order to print the IP address, we will try to list a route that doesn’t exist which will print the current IP address.

$ ip route get 4.3.2.1 | awk '{print $7}'

Find Private IP Address with hostname Command

The hostname command is used to print host-related information like hostname, computer name, and of course IP address. The hostname command will print the private IP address of the current system. We will also provide the -I parameter.

$ hostname -I

The first IP address is the system IP address but it can be also displayed clearly like below by using the awk command to filter the default gateway IP address which is the second IP address.

$ hostname -I | awk '{print $1}'
Find IP Address with hostname Command

Find Public IP Address with host Command

Host command is a simple tool in order to make DNS queries and similar to the dig command it can be used to find the public IP addresses. We will use the myip.opendns.com resolver1.opendns.com name servers like below.

$ host myip.opendns.com resolver1.opendns.com

The output is like below.

Using domain server:
Name: resolver1.opendns.com
Address: 208.67.222.222#53
Aliases:
myip.opendns.com has address 86.104.14.42
Host myip.opendns.com not found: 3(NXDOMAIN)
Host myip.opendns.com not found: 3(NXDOMAIN)

Find Public IP Address with curl From Command Line

The curl command is used to make requests to the remote URLs via the command line. The curl name comes from “Command Line URL”. The curl command can be used to find the public IP address of the Linux system. There are different websites on the internet that returns the IP address of the client via HTTP or similar protocols. The curl command can be used to display this public IP address via the command line.

$ curl ifconfig.me
$ curl icanhazip.com

By default, the returned IP address will be IPv4 but also if it is enabled and used the IPv6 public IP address can be displayed with the following commands. We will provide the -6 parameter to the curl command in order to use the IPv6 protocol.

$ curl -6 icanhazip.com

Find Public IP Address with wget From Command Line

The wget is a popular command-line tool used to download files for different protocols. Similar to the curl command some websites provide the service which returns our public IP address. We will use icanhazip.com domain to return the public IP address.

$ wget -O - -q https://icanhazip.com

Alternatively use the following wget command.

$ wget -qO- ifconfig.me

Find Public IP Address with dig From Command Line

The dig command is used to find DNS-related information like IP to domain name translation or domain name to IP translation. It can be also used to print the public IP address by using the opendns.com DNS servers. The +short parameter will be provided for the myip.opendns.com to be resolved at @resolver1.opendns.com .

$ dig +short myip.opendns.com @resolver1.opendns.com

Find Private IP Address From XFCE Network Manager

The XFCE is a popular Linux desktop environment that provides the network information from the status bar like below. First, click on the Network Icon like below. Then a menu will be opened where we will click to the Connection Information.

Open XFCE Network Information

The Connection Information screen provides general information like private IP address, Subnet Mask, Default route, etc. By default the IPv4 will be displayed but if enabled the IPv6 will be displayed like below too.

XFCE IP Address (IPv4,IPv6)

Leave a Comment