This guide will walk you through the steps to check or find IP address in Linux using
hostname commands from command line interface and graphical user interface. In addition, you will also learn how to display only IPv4 or IPv6 addresses with example commands.
Before getting into the topic, let us have a brief look at what IP address is, and its versions.
What is IP Address?
An IP address is an unique numerical representation assigned to each device connected to a computer network. IP stands for Internet Protocol.
IP address is mainly used to identify a device and communicate with it from other devices on the local area network (LAN) and on the Internet (WAN).
There are two IP versions available:
- Internet Protocol version 4 (IPv4 in short)
- Internet Protocol version 6 (IPv6).
A typical IPv4 address is a string of numbers separated by a dot (period). Here is an example of IPv4:
A typical IPv6 address is string of alphanumeric characters. So, It consists of both numbers and characters like below:
The IP addresses are not random numbers. They are allocated and managed globally by the Internet Assigned Numbers Authority (IANA), a division of the Internet Corporation for Assigned Names and Numbers (ICANN).
Hope you got the basic idea of IP address and the organization behind it. Now let us go ahead and see how to get IP address in Linux system from command line using
hostname commands. First, let us look into the
1. Find IP address in Linux from Command line interface (CLI) using ip command
ip utility is a command line network configuration tool that makes use of the full range networking of features available in modern Linux kernels. It replaces the earlier and now deprecated
ifconfig program. With
ip command, we can examine a Linux system's network interfaces and routing table.
1.1. Display IP address of all network interfaces
To find IP address of all attached network interfaces in a Linux machine, run
ip command with
addr argument like below:
$ ip addr
$ ip a
This command will display the current IP assignments to all the network interfaces in the system:
1: lo: mtu 65536 qdisc noqueue state UNKNOWN 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: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:8f:05:11 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe8f:511/64 scope link valid_lft forever preferred_lft forever
As you see in above output, my Alpine Linux system has two network interfaces, namely
lo is the loopback interface, a virtual interface that the system uses to "talk to itself". And the second interface called
eth0, is the Ethernet interface.
You will see the presence of a valid IP address in the
inet field in the above output. As per the output, the IPv4 address of
10.0.2.15 and IPv6 is
For systems using Dynamic Host Configuration Protocol (DHCP), a valid IP address in this field will verify that the DHCP is working.
In recent Linux distributions, the name of the network interfaces might be
enp0s3. If you have wireless interface card, you will see something like
wlp9s0 in the output.
Did you notice the the word "UP" in the first line for each interface? It indicates that the network interface is enabled.
1.2. Display IP address of specific network interface
When you run
ip addr command without any options, it will show you the network details of all interfaces in the system. You can, however, explicitly specify a particular network interface name to view its IP details only:
$ ip addr show dev eth0
This command will show IP details of
eth0 interface only:
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:8f:05:11 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe8f:511/64 scope link valid_lft forever preferred_lft forever
1.3. Print only basic IP information in a tabular format
Instead of displaying all network details, we can show only brief output with
$ ip -br a
This option prints only basic information in a tabular format for better readability.
lo UNKNOWN 127.0.0.1/8 ::1/128 enp0s3 UP enp0s8 UP 2409:4072:9b:47f0:a00:27ff:fe10:7cc1/64 fe80::a00:27ff:fe10:7cc1/64 enp0s9 UP 2409:4072:9b:47f0:a00:27ff:fe5d:6128/64 fe80::a00:27ff:fe5d:6128/64 br0 UP 192.168.225.52/24 fe80::a00:27ff:fe8a:5294/64 virbr0 DOWN 192.168.122.1/24 virbr0-nic DOWN
This option is currently only supported by
ip addr show and
ip link show commands.
1.4. Display IP addresses in color
ip command has an option to add colors to the IP addresses. It is helpful to distinguish IP addresses from other parts in the output.
To configure color output, use
$ ip a -c
This option will show each details in the output in different color.
1.5. Display IPv4 addresses only
As you may noticed in the previous outputs, the
ip command gets you both IPv4 and IPv6 details. You can also display only IPv4 addresses or IPv6 addresses.
To print only the IPv4 addresses, use
$ ip -4 a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 5: br0: mtu 1500 qdisc noqueue state UP group default qlen 1000 inet 192.168.225.52/24 brd 192.168.225.255 scope global br0 valid_lft forever preferred_lft forever 6: virbr0: mtu 1500 qdisc noqueue state DOWN group default qlen 1000 inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever
1.6. Display IPv6 addresses only
To print only the IPv4 addresses, use
$ ip -6 a
1: lo: mtu 65536 state UNKNOWN qlen 1000 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 3: enp0s8: mtu 1500 state UP qlen 1000 inet6 2409:4072:9b:47f0:a00:27ff:fe10:7cc1/64 scope global mngtmpaddr noprefixroute valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe10:7cc1/64 scope link valid_lft forever preferred_lft forever 4: enp0s9: mtu 1500 state UP qlen 1000 inet6 2409:4072:9b:47f0:a00:27ff:fe5d:6128/64 scope global mngtmpaddr noprefixroute valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe5d:6128/64 scope link valid_lft forever preferred_lft forever 5: br0: mtu 1500 state UP qlen 1000 inet6 fe80::a00:27ff:fe8a:5294/64 scope link valid_lft forever preferred_lft forever
1.7. Print ip command output in JSON format
You can use
$ ip -j a
1.8. Show IP information in human readable format
-human-readable option allows you to show output statistics with human readable values followed by suffix.
$ ip -h a
For more details, check man pages.
$ man ip
2. Display IP address in Linux using hostname command
A hostname is a alphanumeric label assigned to a node in-order to identify it on the network. In Linux, the
hostname command allows you to show or set a system's hostname, and show network addresses of all network interfaces in the host system.
To display IP addresses of all attached network interface cards in Linux, run
hostname command with
$ hostname -I
192.168.225.52 192.168.122.1 2409:4072:9b:47f0:a00:27ff:fe10:7cc1 2409:4072:9b:47f0:a00:27ff:fe5d:6128
You now learned about two commands to check IP address information from Terminal in Linux. As you can see, all of the aforementioned steps are for commandline interface (CLI) only. The following section shows how to get IP address details from a graphical environment.
3. Get IP address in Linux from Graphical user interface (GUI)
Finding IP address differs depending upon the desktop environment (DE) you use. The steps provided below are tested in Ubuntu GNOME desktop.
In the Dash menu, type Settings and click on it to open.
Next, choose network type (Wifi or Wired) you are currently using.
If you are connected to a Wired network, click on Network button in the left pane of the Settings window. On the right pane, click the Advanced network settings gear button.
Note: My system is not connected with any wired networks, so it shows - Cable unplugged. If you're connected with wired network, you will see Connected message.
If your system is connected to a Wireless network, click on Wi-Fi button in the left pane of the Settings window. On the right pane, click the Advanced network settings gear button.
Once you clicked on the Advanced network settings gear button, the following window will open. Under the Details tab, you can find the IP address details.
Hope this helps.
- How To Configure Static IP Address In Linux And Unix
- How To Configure IP Address In Ubuntu 18.04 LTS
- How To Configure Static And Dynamic IP Address In Arch Linux
- How To Assign Multiple IP Addresses To Single Network Card In Linux
- How To Find Out Public IP Address From Command Line On Linux
- Display Network Information In Linux Using What IP Tool
- How To Find The Geolocation Of An IP Address From Commandline
Featured image by Jorge Guillen from Pixabay.