LESSON · 1 OF 6

IPs and interfaces

IPs and interfaces

Every machine on a network has one or more network interfaces. An interface is a lane the machine uses to send and receive traffic. Most Linux servers have at least two:

  • lo - the loopback, address 127.0.0.1. Traffic that never leaves the machine (one process talking to another on the same box) goes here.
  • eth0 (or ens3, enp0s3, depends on the naming scheme) - the main outbound interface, with the machine's real network address.

Listing interfaces

The modern command is ip:

bash
ip addr show           # long form
ip a                   # short form, same result

You'll see one block per interface. The key line for each is inet <address>/<mask>, which is the IPv4 address:

inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0

10.0.2.15 is the machine's IP on that interface. /24 is the size of the network it belongs to.

Printing just the IP with hostname -I

If you only need the IP:

bash
hostname -I

Prints only IP addresses, space-separated. Perfect for scripts.

What about ifconfig?

The older command, still floating around in tutorials. Not installed by default on modern Ubuntu. Use ip a and don't look back.

Spin up a fresh environment and practice live.
linux-devops-basic · fresh machine · ready in under a minute