MarkBot
IP & AS

How to get the ip address in linux

Autumn Leaves

If we need to view the IP address in Linux, we can use the following methods.

Use the command hostname -I to view the IP address

hostname -I

The results are displayed as:

67.198.205.2

If you do not add the -I parameter, it will be displayed as the hostname of the machine:

hostc35082f9af

To view the IP address of Linux, use the command ifconfig

ifconfig

The results are as follows.

eth0: flags=4163
mtu 1500
        inet 67.198.205.2  netmask 255.255.255.128  broadcast 67.198.205.127
        inet6 fe80::216:3cff:fee8:4645  prefixlen 64  scopeid 0x20
        ether 00:16:3c:e8:46:45  txqueuelen 1000  (Ethernet)
        RX packets 1639018361  bytes 1371502481874 (1.3 TB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1324554334  bytes 1305244190840 (1.3 TB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 885434138  bytes 1153342690161 (1.1 TB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 885434138  bytes 1153342690161 (1.1 TB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

As we can see from the above results, it not only contains the current IP address, gateway, mask and the amount of data transferred, but also shows some information about the loopback.

Use the ip addr show command to view Linux IP address information

ip addr show

The results are the same as above and will not be shown too much here.

Show public IP address

This is the public IP address shown above, but some Linux configurations get the LAN IP address, so if we need to look up the public IP address, here's how to do it.

Get our own public IP address using the following link.

All four of these methods can be used to obtain an IP address for Linux, so give them a try.

Back to top