Tutorial

How to check the IP address in Linux

In this article, we show you how to easily check the IP address of your computer in Linux. This is particularly useful when setting up your computer in a network or if you are having problems with your network connection.

Step 1: Enter the ifconfig command

Once you have opened a terminal session, simply enter the ifconfig command and press enter. This will show you all network interfaces and their current IP addresses.

Step 2: Look for the IP address

In the output of ifconfig, several network interfaces will be displayed. Look for the line that starts with inet. This line contains the IP address of the interface.

For example, if you have an Ethernet connection, the IP address will be displayed under the eth0 interface. If you are connected over WiFi, the IP address will be displayed under the wlan0 interface.

Alternatives to ifconfig

ip addr show

The ip addr show command shows all network interfaces and their IP addresses. Like ifconfig, you can look for the IP address of the desired interface by searching for the line starting with inet.

hostname -I

The ip route get 1.1.1.1 command shows the IP address of the interface used to establish a connection to a specific destination. In this case, the IP address of the interface used to establish a connection to 1.1.1.1 is displayed. You can also use this command with a different IP address or hostname.

ip route get 1.1.1.1

Der Befehl ip route get 1.1.1.1 zeigt die IP-Adresse des Interfaces an, das verwendet wird, um eine Verbindung zu einem bestimmten Ziel herzustellen. In diesem Fall wird die IP-Adresse des Interfaces angezeigt, das verwendet wird,

um eine Verbindung zu 1.1.1.1 herzustellen. Du kannst diesen Befehl auch mit einer anderen IP-Adresse oder einem Hostnamen verwenden.

ip address show

The ip address show command shows the IP addresses of all network interfaces. This is similar to ifconfig and ip addr show, but the ip address show command is often used by systems that use the iproute2 package.

How to display only the IP address

If you want to display only the IP address instead of the entire output of ifconfig, ip addr show, hostname -I, or ip address show, you can use the following commands:

ifconfig [interface] | grep "inet" | awk '{print $2}'

This command works similarly to the ifconfig command mentioned above, but it uses the ip addr show command instead of ifconfig. It only displays the IP address of the specified interface. Simply replace [interface] with the name of the interface whose IP address you want to display (e.g. eth0 or wlan0).

ip addr show [interface] | grep "inet" | awk '{print $2}'

Dieser Befehl funktioniert ähnlich wie der oben genannte Befehl für ifconfig, aber er verwendet den Befehl ip addr show statt ifconfig.

hostname -I | awk '{print $1}'

This command only displays the first IP address in the output of hostname -I. If you have multiple network interfaces, only the IP address of the first interface will be displayed.

ip address show [interface] | grep "inet" | awk '{print $2}'

This command works similarly to the ifconfig and ip addr show commands mentioned above, but it uses the ip address show command instead of ifconfig or ip addr show. It only displays the IP address of the specified interface. Simply replace [interface] with the name of the interface whose IP address you want to display (e.g. eth0 or wlan0).

Example:

ip address show eth0 | grep "inet" | awk '{print $2}'