Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Linux networking basics

By updated

Improve this page

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:

VersionFormatExample
IPv44 numbers separated by dots (0-255)192.168.1.10
IPv68 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 nameType
loLoopback, the machine talks to itself
eth0 or ens33Wired Ethernet interface
wlan0 or wlp2s0Wi-Fi interface
virbr0, docker0Virtual interfaces (VMs, containers)

To list your interfaces and their addresses:

Terminal window
ip addr show
Output (excerpt)
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
2: 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 ens33
  • lo always has the address 127.0.0.1 (that is localhost).
  • ens33 has the address 192.168.1.10 with a /24 mask.
  • state UP says the interface is active; the LOWER_UP flag 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.

Terminal window
ip route show
Output
default via 192.168.1.1 dev ens33 proto dhcp src 192.168.1.10 metric 100
192.168.1.0/24 dev ens33 proto kernel scope link src 192.168.1.10 metric 100

The 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:

Terminal window
cat /etc/resolv.conf
Output
nameserver 192.168.1.1
nameserver 8.8.8.8

On 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:

PortService
22SSH
80HTTP
443HTTPS
53DNS

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:

ProtocolCharacteristicTypical use
TCPReliable, checks that data arrives in orderWeb (HTTP/HTTPS), SSH, e-mail
UDPFast, no delivery checkDNS, 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:

  1. See your interfaces and IP addresses:

    Terminal window
    ip addr show
  2. See the default gateway:

    Terminal window
    ip route show
  3. See the configured DNS servers:

    Terminal window
    cat /etc/resolv.conf
  4. See the machine name:

    Terminal window
    hostname
  5. See the state of the interfaces (up or down):

    Terminal window
    ip link show

    The ens33 line must contain state UP. A down interface shows state 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.

CommandRole
ip addr showShows the interfaces and IP addresses
ip route showShows the routes and the gateway
cat /etc/resolv.confShows the DNS servers
hostnameShows the machine name
ip link showShows 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.

SymptomLikely causeSolution
ip link show reports state DOWN for ens33Interface 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 lineNo address obtained: DHCP failed or the network manager is not configuredRestart the interface configuration (see below the table)
No gateway in ip routeDHCP configuration failedRestart the interface configuration with the network manager (see below the table)
/etc/resolv.conf is emptyThe network manager did not write the DNS configurationTemporarily add nameserver 8.8.8.8
ip: command not foundiproute2 package missingInstall 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 show and ip route show are 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

6 questions
6 min
70% to pass

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