We can determine Linux system IP address in different ways. IP address is used to communicate over network and can be get and set in different ways. In this tutorial we will use Ubuntu distribution but given examples and commands will work for all of the different Linux distribution like Fedora, CentOS, Debian, Kali, Mint, RHEL etc.
Hostname Command IP Address
hostname
command is mainly used to show or set the system’s host name. But it also provides the IP address of the current system. We will use -I
option for this. This will list all interface IP addresses.
$ hostname -I

Ifconfig Command IP Address
ifconfig
command is very popular and old command used to manage network related configuration in Linux operating system. We can use ifconfig
command easily to get IP address.
$ ifconfig | grep netmask | awk '{print $2}'| cut -f2 -d:

This command provides IP addresses line by line. We have also used awk
and cut
command in order to filter IP address.
If we want to list all interfaces we can use only ifconfig
command like below.
$ ifconfig

Show Specific Interface IP Address with ifconfig Command
We may need to list only specified network interface IP address. So we can specify the name of the interface to the ifconfig
command. In this example we will list IP address of network interface named ens33
.
$ ifconfig ens33

Ip Command IP Address
ip
command is newer network management command provided by most of the Linux distributions. We can use addr
option with show
subcommand to list IP addresses.
$ ip addr show | grep inet | awk '{print $2}' | cut -f2 -d:

As we can see the netmask information also provided.
We can also list all related information without filtering the ip addr
command output.
$ ip addr

Show Specific Interface IP Address with ip Command
As examined previously with ifconfig
command we can also look specific interface IP address with ip address show
command like below. We will just specify the network interface name which is ens33
and dev
option in this example.
$ ip address show dev ens33

Public, WAN or Internet Address
As most of the networks uses private IP address range we may need our real or public IP address which is used in the internet. There are different web services those provides our IP address in a HTTP request. Here is some of them.
$ curl ifconfig.me $ curl icanhazip.com $ curl ipecho.net/plain
