109.2 Persistent network

Tech Tutorial: 109.2 Persistent Network Configuration #

Introduction #

In this tutorial, we will explore how to manage the persistent network configuration of a Linux host. Network configuration is critical in ensuring that your Linux systems are connected and functioning properly in a networked environment. Understanding how to configure network settings that persist across reboots is essential for system administrators.

We will cover the necessary utilities and commands needed to configure and manage the network interfaces persistently. By the end of this guide, you should have a solid understanding of how to handle network configurations on a Linux system.

Key Knowledge Areas #

  • Understanding network configuration files
  • Using command-line tools to manage network settings
  • Services and daemons for network configuration
  • Techniques for troubleshooting network issues

Utilities: #

  • ifconfig
  • ip
  • netplan
  • nmcli
  • systemd-networkd

Step-by-Step Guide #

1. Configuring Network Using ifconfig #

The ifconfig utility is one of the most common tools used for network interface configuration. It is part of the net-tools package.

Example: #

To display all interfaces, which might be in use or not:

ifconfig -a

To configure an IP address on an interface:

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up

To disable an interface:

sudo ifconfig eth0 down

2. Using the ip Command #

The ip command is part of the iproute2 package and is used to show and manipulate routing, network devices, interfaces, and tunnels.

Examples: #

To display all interfaces:

ip link show

To set an IP address:

sudo ip addr add 192.168.1.100/24 dev eth0

To bring an interface up:

sudo ip link set eth0 up

To bring an interface down:

sudo ip link set eth0 down

3. Managing Network with Netplan #

Netplan is a utility for easily configuring networking on a linux system. You simply create a YAML description of the required network interfaces and what each should be configured to do.

Configuration Example: #

Create or edit a file in /etc/netplan/ (e.g., 01-netcfg.yaml):

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

Apply the configuration:

sudo netplan apply

4. Using nmcli for Network Management #

nmcli is a command-line client for NetworkManager. It allows querying and configuring network connections and interfaces.

Examples: #

To show all connections:

nmcli con show

To add a new Ethernet connection:

nmcli con add con-name "static-eth0" ifname eth0 type ethernet ip4 192.168.1.100/24 gw4 192.168.1.1

To bring up a connection:

nmcli con up id "static-eth0"

5. Configuring Networks with systemd-networkd #

systemd-networkd is a system daemon that manages network configurations.

Example Configuration File (/etc/systemd/network/10-static-eth0.network): #

[Match]
Name=eth0

[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8

To restart systemd-networkd:

sudo systemctl restart systemd-networkd

Conclusion #

In this tutorial, you have learned about several tools and configurations that can be used to manage persistent network settings on Linux. Whether you’re using ifconfig, ip, netplan, nmcli, or systemd-networkd, each tool has its specific use cases and benefits. Understanding these tools will help you effectively manage network configurations in a persistent manner across system reboots, ensuring your networked systems stay connected as needed.