Network Configuration
Last edited
ip link showLinux naming conventions:
# Prefixes
en = ethernet
wl = wirless (802.11)
ww = cellular (WWAN)
# Examples
enpXsY = wired (ethernet), PCI slot X, port Y
enp0s3 = first wired interface
eno1 = onboard ethernet
wlpXsY = wireless, PCI slot X, port Y
wwpXsY = cellular/mobile
# Legacy
ethX = old namingRouting configuration
It may be that no route matches the destination address. In this case, the default route is invoked if one exists. Otherwise, an ICMP “network unreachable” or “host unreachable” message is returned to the sender. On the Internet backbone, the routers do not have default routes. If there is no routing entry for a destination, that destination cannot be reached.
# You can use a dns record for a route
ip route add 10.0.0.0/24 via router1.pawney.netTools
ip route
ip route show # show routes
ip route show default
# Add routes
ip route add default via 10.0.0.1 dev eth0 # optionally specify interface
ip route add default via 10.0.0.1
ip route add default dev eth0
# Remove routes, exact same as add but del
ip route remove default via 10.0.0.1 dev eth0 After any change to a file that controls network configuration at boot time, you may need either to reboot or to bring the network interface down and then up again for your change to take effect.
ifdown interface
ifup interfaceIP command - manually configure networks
Linux systems formerly used the same basic commands for network configuration and status checking as traditional UNIX: ifconfig, route, and netstat. These are still available on most distributions, but active development has moved on to the iproute2 package, which features the commands:
ip(for most everyday network configuration)ss(for examining the state of network sockets).
ip takes a second argument for what object you want to configure
ip link # network interfaces
ip address # binding network addresses to interfaces
ip route # ip routing
# Most of these can be abbreviated
ip ad
ip addr
# Most object understand list and show, which are aliases for each other (same outputs)
ip link show
ip address list
ip route show
# The man pages are divided by sub-command
man ip-link
man ip-route
man ip-addressNetworkManager
In 2004 NetworkManager released and Linux started to migrate over to it
- Designed to be run and managed by users rather than system administrators
- NetworkManager has been widely adopted by Linux distributions
- In an effort to avoid breaking existing scripts and setups, it’s usually made available in parallel to static file configurations
- For servers and desktop systems (not laptops), NetworkManager isn’t necessary and may in fact complicate administration. In these environments, it should be ignored or configured out.
In daily life you won’t normally be setting up network addresses by hand, with ip.
The next sections describe how distributions handle static configuration of the network from the perspective of configuration files.
Debian
| Setup | Default networking | Config |
|---|---|---|
| Desktop (GNOME, KDE, etc.) | NetworkManager | /etc/NetworkManager/ + nmcli |
| Server/CLI-only | Not NetworkManager | /etc/network/interfaces + ifup/ifdown |
| Any system | Can install either | User choice |
# Check what you have:
systemctl status NetworkManager
systemctl status systemd-networkd
# If using ifupdown (no NM):
cat /etc/network/interfaces
sudo vim /etc/network/interfaces
sudo ifup eth0
sudo ifdown eth0
sudo systemctl restart networking
# If using NetworkManager:
nmcli device show
nmcli connection show
nmcli device wifi list
nmcli connection add con-name mynet ifname eth0 type ethernet ip4 192.168.1.100/24Ubuntu
| Setup | Backend | Config |
|---|---|---|
| Desktop (GNOME, etc.) | NetworkManager | /etc/netplan/ + nmcli |
| Server/CLI-only | systemd-networkd | /etc/netplan/ + netplan |
# Check what you have:
netplan status
cat /etc/netplan/00-installer-config.yaml
# Edit config:
sudo vim /etc/netplan/00-installer-config.yaml
# Apply changes:
sudo netplan apply
# Info:
netplan get
ip addr showKey diff from Debian: Ubuntu uses netplan (YAML abstraction) for both, not /etc/network/interfaces. Netplan picks the backend (NM vs systemd-networkd) under the hood.
Ethtool
Query or control network driver and hardware settings.
sudo ethtool enp5s0
sudo ethtool -r # force renegotiation of speedAll these changes are transient, you need to have them run at boot time in /etc/network/interfaces or whichever network manager runs boot scripts.