Knowing the IP address of a Linux system is essential for troubleshooting network connectivity, configuring firewalls, and enabling remote access. It acts as the machine's numeric identity on a local network or across routed segments, allowing services and peers to reach the correct host.
On modern Linux systems, network configuration is exposed through tools from the iproute2 suite, primarily the ip utility, along with helpers such as hostname. These commands read kernel networking state and list IPv4 and IPv6 addresses attached to each interface, including wired, wireless, virtual, and tunnel devices.
IP configuration can change dynamically due to DHCP leases, VPN tunnels, containers, and multiple active interfaces, so output often contains several addresses and both IPv4 and IPv6 entries. The commands below operate in read-only mode and therefore do not alter network settings, but care is still required to choose the correct address for a specific task.
$ whoami root
$ hostname -I 192.0.2.40
The first IPv4 address is commonly the primary LAN address; additional entries may represent Docker or container bridges, VPN interfaces, and IPv6 addresses.
$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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 noprefixroute
valid_lft forever preferred_lft forever
##### snipped #####
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 02:00:00:00:00:10 brd ff:ff:ff:ff:ff:ff
inet 192.0.2.40/24 metric 100 brd 192.0.2.255 scope global dynamic eth0
valid_lft 1780sec preferred_lft 1780sec
inet6 fe80::20/64 scope link
valid_lft forever preferred_lft forever
Focus on inet lines for IPv4 addresses and inet6 lines for IPv6; the interface name appears at the start of each block (for example enp0s3 or wlp2s0).
$ ip -br addr lo UNKNOWN 127.0.0.1/8 ::1/128 ##### snipped ##### eth0 UP 192.0.2.40/24 metric 100 fe80::20/64
The brief format is useful for quick checks or scripts where a single line per interface is easier to parse.
$ ip addr show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 02:00:00:00:00:10 brd ff:ff:ff:ff:ff:ff
inet 192.0.2.40/24 metric 100 brd 192.0.2.255 scope global dynamic eth0
valid_lft 1780sec preferred_lft 1780sec
inet6 fe80::20/64 scope link
valid_lft forever preferred_lft forever
Interface names often follow predictable patterns such as eth0, enp0s3, ens33, or wlp2s0 depending on the hardware and udev naming scheme.
$ ip route get 203.0.113.50
203.0.113.50 via 192.0.2.1 dev eth0 src 192.0.2.40 uid 0
cache
The address shown after src is the IP the system uses to reach the destination, which is typically the main LAN address of the host.
$ ping -c 3 192.0.2.1 PING 192.0.2.1 (192.0.2.1) 56(84) bytes of data. 64 bytes from 192.0.2.1: icmp_seq=1 ttl=128 time=0.244 ms 64 bytes from 192.0.2.1: icmp_seq=2 ttl=128 time=0.656 ms 64 bytes from 192.0.2.1: icmp_seq=3 ttl=128 time=0.784 ms --- 192.0.2.1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2064ms rtt min/avg/max/mdev = 0.244/0.561/0.784/0.230 ms
Successful replies confirm that the interface and IP address are functioning on the network; packet loss or timeouts usually indicate connectivity or routing issues.