The IP address is the number that identifies your machine on a network. Without it, no communication is possible. This guide introduces the essential networking concepts to understand how your Linux system connects to the outside world.
What you will learn
- What an IP address is (IPv4 and IPv6)
- The role of a network interface
- What a gateway, DNS and a port are
- The difference between TCP and UDP
- Display the network configuration with
ip addr
What an IP address is
An IP address identifies a machine connected to a network, and it is unique there: two machines on the same network do not share the same address. There are two versions:
| Version | Format | Example |
|---|---|---|
| IPv4 | 4 numbers separated by dots (0-255) | 192.168.1.10 |
| IPv6 | 8 hexadecimal groups separated by : | fe80::1 |
The IPv6 example seems to have only two groups: the :: stands for a run
of zero groups, and fe80::1 written in full is fe80:0:0:0:0:0:0:1.
Each IP address comes with a mask that says which part designates the network and which part identifies the machine. In CIDR notation:
192.168.1.10/24→ the first 24 bits identify the network (192.168.1.0)- The remaining 8 bits identify the machine (
.10)
The address 192.168.1.10 in these examples belongs to a private range.
On a home or corporate network, addresses most often start with 192.168.x.x,
10.x.x.x or 172.16.x.x to 172.31.x.x. These ranges are not routable on
the Internet: two companies can both use 192.168.1.10 without getting in each
other's way, and the router translates these addresses towards the outside.
Network interfaces
A network interface is the connection point between your machine and the network. Each interface has a name:
| Common name | Type |
|---|---|
lo | Loopback, the machine talks to itself |
eth0 or ens33 | Wired Ethernet interface |
wlan0 or wlp2s0 | Wi-Fi interface |
virbr0, docker0 | Virtual interfaces (VMs, containers) |
To list your interfaces and their addresses:
ip addr show1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 inet 127.0.0.1/8 scope host lo2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 inet 192.168.1.10/24 brd 192.168.1.255 scope global ens33loalways has the address127.0.0.1(that is localhost).ens33has the address192.168.1.10with a/24mask.state UPsays the interface is active; theLOWER_UPflag indicates that the physical link is present (cable plugged in, card connected).
You will still come across ifconfig in many tutorials: the command is
deprecated on modern distributions, and often even missing from the
default installation, since it belongs to the legacy net-tools package. The
current command is ip addr, provided by iproute2, and that is the
one to learn.
Gateway, DNS and port
An IP address is not enough to communicate. Three elements are missing: the gateway, which says where to leave the local network; DNS, which translates names into addresses; and the port, which designates the service targeted on the remote machine. Each has its own failure mode, and knowing which of the three is at fault saves diagnosis time.
The gateway
The gateway is the router through which your machine sends traffic to the outside. It is the "exit door" of your local network.
ip route showdefault via 192.168.1.1 dev ens33 proto dhcp src 192.168.1.10 metric 100192.168.1.0/24 dev ens33 proto kernel scope link src 192.168.1.10 metric 100The default via 192.168.1.1 line gives your gateway. The second one says that
the local network 192.168.1.0/24 is reachable directly through ens33,
without going through the gateway.
DNS
DNS (Domain Name System) translates domain names into IP addresses. When you
type ping google.com, DNS resolves this name to 142.250.x.x.
The /etc/resolv.conf file contains the DNS servers in use:
cat /etc/resolv.confnameserver 192.168.1.1nameserver 8.8.8.8On Ubuntu, you will most often read a single line,
nameserver 127.0.0.53. This is not a mistake: it is the local
resolver of systemd-resolved, which relays queries to the real DNS
servers. Those are displayed with resolvectl status.
Ports
A port is a number (from 1 to 65535) that identifies a service on a machine. Common port examples:
| Port | Service |
|---|---|
22 | SSH |
80 | HTTP |
443 | HTTPS |
53 | DNS |
A service is designated by the pair IP address + port: 192.168.1.10:22 is
the SSH service of this machine. A connection links the client's pair to the
server's pair, which is why one port can serve several clients at the same
time.
TCP and UDP
Two transport protocols coexist:
| Protocol | Characteristic | Typical use |
|---|---|---|
| TCP | Reliable, checks that data arrives in order | Web (HTTP/HTTPS), SSH, e-mail |
| UDP | Fast, no delivery check | DNS, streaming, online games |
As a beginner, remember that most system services use TCP. DNS mainly uses UDP for its quick queries.
Check your network configuration
Here are the essential commands to view the network state of your machine:
-
See your interfaces and IP addresses:
Terminal window ip addr show -
See the default gateway:
Terminal window ip route show -
See the configured DNS servers:
Terminal window cat /etc/resolv.conf -
See the machine name:
Terminal window hostname -
See the state of the interfaces (up or down):
Terminal window ip link showThe
ens33line must containstate UP. A down interface showsstate DOWN: it transmits nothing, even if an address is assigned to it.
Command summary
These five commands are enough to read a machine's network configuration, and none of them changes anything: you can run them one after the other on a production server without risk. Keep this list at hand, it is the starting point of any diagnosis. The Linux networking fundamentals guide covers these notions in detail, with the configuration tool of each distribution.
| Command | Role |
|---|---|
ip addr show | Shows the interfaces and IP addresses |
ip route show | Shows the routes and the gateway |
cat /etc/resolv.conf | Shows the DNS servers |
hostname | Shows the machine name |
ip link show | Shows the state of the interfaces (UP/DOWN) |
In tutorials, you will see shorter forms: ip a for ip addr show, ip r
for ip route show and ip l for ip link show. The ip command accepts an
abbreviation of each object (the ip(8) manual page says that address
can be written addr or simply a), and it runs show when you give no
action. In a script or in documentation, keep the full forms: they can be read
without knowing this rule.
Troubleshooting
The five failures below are common network configuration failures. Read the table from the left column, the observable symptom, since that is all you have when the problem occurs. None of them can be diagnosed from the failing application: you have to go down to the interface, then the route, then DNS, in that order.
| Symptom | Likely cause | Solution |
|---|---|---|
ip link show reports state DOWN for ens33 | Interface disabled, or cable unplugged (no LOWER_UP) | Check the cable, then sudo ip link set ens33 up |
ens33 is UP but ip addr shows no inet line | No address obtained: DHCP failed or the network manager is not configured | Restart the interface configuration (see below the table) |
No gateway in ip route | DHCP configuration failed | Restart the interface configuration with the network manager (see below the table) |
/etc/resolv.conf is empty | The network manager did not write the DNS configuration | Temporarily add nameserver 8.8.8.8 |
ip: command not found | iproute2 package missing | Install it: sudo apt install iproute2 or sudo dnf install iproute |
To restart the configuration of an interface, go through the distribution's
network manager: sudo nmcli device disconnect ens33 then
sudo nmcli device connect ens33 with NetworkManager (RHEL, Fedora), which
briefly cuts the interface, and sudo networkctl reconfigure ens33 with
systemd-networkd (Ubuntu Server). The dhclient command, quoted by many
tutorials, is no longer shipped by RHEL 10.
Key points
- An IP address identifies your machine on the network; the mask delimits the network.
- An interface (
ens33,lo) is the access point to the network. - The gateway is the way out to the Internet, DNS translates names into addresses.
- A port identifies a service (22 = SSH, 80 = HTTP, 443 = HTTPS).
- TCP checks that data arrives in order; UDP favors speed, with no delivery guarantee (this is the case for DNS).
ip addr showandip route showare the two must-know commands.
Knowledge check
Check that the essentials of this guide stuck. The questions cover only what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Test network connectivity
A new full quiz with random questions
Work again only on the questions you missed