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.The modern command is ip:
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.
If you only need the IP:
hostname -I
Prints only IP addresses, space-separated. Perfect for scripts.
The older command, still floating around in tutorials. Not
installed by default on modern Ubuntu. Use ip a and don't look
back.