Configuring Linux Network Interfaces
Configuring network interfaces is a fundamental task in Linux system administration. In this section, we will explore the various methods and tools available for managing network interfaces on a Linux system, using Ubuntu 22.04 as the example distribution.
Viewing Network Interfaces
To view the available network interfaces on your system, you can use the ip link show
command:
$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:b1:d5:32 brd ff:ff:ff:ff:ff:ff
This shows that the system has two network interfaces: the loopback interface lo
and the Ethernet interface enp0s3
.
Configuring IP Addresses
To configure an IP address on a network interface, you can use the ip addr
command. For example, to assign the IP address 192.168.1.100/24
to the enp0s3
interface:
$ sudo ip addr add 192.168.1.100/24 dev enp0s3
This will set the IP address and subnet mask for the enp0s3
interface.
Configuring Default Gateway and DNS
In addition to the IP address, you may also need to configure the default gateway and DNS servers for your network. You can do this using the ip route
and resolvectl
commands, respectively:
$ sudo ip route add default via 192.168.1.1
$ sudo resolvectl dns enp0s3 8.8.8.8 8.8.4.4
This will set the default gateway to 192.168.1.1
and the DNS servers to Google's public DNS servers (8.8.8.8
and 8.8.4.4
).
Network Interface Configuration Files
On Ubuntu 22.04, the network interface configuration is typically managed through the /etc/netplan/
directory. You can create or modify the YAML configuration files in this directory to define the network settings for your system.
For example, the following 01-network-manager-all.yaml
file configures the enp0s3
interface with a static IP address, gateway, and DNS servers:
network:
version: 2
renderer: NetworkManager
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
After making changes to the configuration file, you can apply the new settings using the sudo netplan apply
command.