How to Configure Networking at Boot Time

To configure the network at boot time in Linux, you can use the network configuration files specific to your Linux distribution. The location and naming conventions of these files can vary based on the distribution and version you are using. Here are some common methods to configure the network at boot time: 1. **NetworkManager:** Many modern Linux distributions use NetworkManager to manage network connections. NetworkManager provides a convenient way to configure the network settings, including wired and wireless connections, and automatically manages network configuration during boot. To configure network connections with NetworkManager, you can use tools like `nmtui` or the graphical network settings manager provided by your desktop environment. For example, to use `nmtui` (text-based NetworkManager configuration tool), open a terminal and run: ```bash sudo nmtui ``` This will launch a text-based interface where you can configure network connections. After making the changes, save the settings, and NetworkManager will apply them at boot time. 2. **Traditional Network Configuration (SysVinit):** Some Linux distributions still use traditional SysVinit for managing network services and configurations. In this case, you need to modify the network configuration files in the `/etc/network/` directory. For example, on Debian-based systems (e.g., Ubuntu), you can edit the `/etc/network/interfaces` file: ```bash sudo nano /etc/network/interfaces ``` In the file, you can define the network settings for each network interface. Save the changes, and the network will be configured at boot time. 3. **Systemd-Networkd:** Some modern Linux distributions use systemd-networkd for network configuration. With systemd-networkd, you define network configuration for each interface in separate `.network` files. For example, on systemd-based systems, you can create a `.network` file in the `/etc/systemd/network/` directory. Create a file named something like `enp0s3.network`: ```bash sudo nano /etc/systemd/network/enp0s3.network ``` Add the network configuration settings for the interface in this file. Save the changes, and systemd-networkd will apply the settings at boot time. Remember to restart the network service or reboot the system after making changes to apply the new network configuration. The specific command to restart the network service may vary based on your Linux distribution and init system. Please note that the methods and files mentioned above are based on common Linux distributions as of my knowledge cutoff date in September 2021. Newer versions or distributions might use different tools and configuration files for network setup. Always refer to the documentation and community resources specific to your Linux distribution for the most up-to-date information on configuring the network at boot time.

A server that can’t reach the network after a reboot is effectively useless — you can’t SSH into it, it can’t serve web traffic, and it can’t reach package repositories to update itself. Configuring networking to come up automatically and correctly at boot time is therefore one of the most fundamental Linux administration skills. This article explains, from first principles, the different systems Linux distributions use to configure networking at boot — legacy /etc/network/interfaces, NetworkManager, and modern Netplan — with practical, real-world examples for each.

Why Boot-Time Network Configuration Matters

flowchart TD
    A[System Boots] --> B[Kernel Detects Network Interfaces]
    B --> C[Network Configuration Service Starts]
    C --> D{Static or DHCP?}
    D -->|Static| E[Apply Fixed IP/Gateway/DNS]
    D -->|DHCP| F[Request IP from DHCP Server]
    E --> G[Interface Up, Network Ready]
    F --> G

Without correct boot-time configuration, a server might come up with no IP address at all, the wrong IP address, or no default route — any of which can mean losing remote access entirely, requiring physical console intervention to fix.

Two Approaches: DHCP vs. Static IP

ApproachHow It WorksBest For
DHCPInterface automatically requests an IP from a DHCP server on the networkMost client machines, dynamic environments
Static IPIP address, gateway, and DNS are manually and permanently configuredServers, infrastructure that needs a fixed, predictable address

Servers almost always use static IP addresses (or DHCP reservations tied to a MAC address), since services, DNS records, and firewall rules typically depend on a predictable address.

Method 1: Legacy Debian/Ubuntu — /etc/network/interfaces

Older Debian-based systems (and Ubuntu Server before 17.10) configure networking through this file.

Static IP Configuration Example

auto eth0
iface eth0 inet static
    address 192.168.1.50
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 1.1.1.1

DHCP Configuration Example

auto eth0
iface eth0 inet dhcp

Apply changes:

sudo systemctl restart networking

Or bring an individual interface up/down:

sudo ifdown eth0 && sudo ifup eth0

Method 2: Modern Ubuntu — Netplan

Since Ubuntu 17.10+, Netplan is the default networking configuration system, using YAML files under /etc/netplan/.

Static IP Configuration Example

# /etc/netplan/01-netcfg.yaml
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 192.168.1.50/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]

DHCP Configuration Example

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: yes

Applying Netplan Changes

sudo netplan apply

Testing Before Committing (Safety Net)

Netplan supports a “try” mode that automatically reverts changes if you don’t confirm within a timeout — extremely useful when configuring networking remotely, since a bad config could otherwise lock you out entirely:

sudo netplan try

If the new configuration breaks connectivity, it automatically rolls back after ~120 seconds unless you press Enter to confirm it works.

Method 3: RHEL/CentOS/Fedora — NetworkManager (nmcli)

RHEL-family distributions primarily use NetworkManager, controllable via the nmcli command-line tool.

Viewing Current Connections

nmcli connection show

Configuring a Static IP

sudo nmcli connection modify eth0 ipv4.addresses 192.168.1.50/24
sudo nmcli connection modify eth0 ipv4.gateway 192.168.1.1
sudo nmcli connection modify eth0 ipv4.dns "8.8.8.8 1.1.1.1"
sudo nmcli connection modify eth0 ipv4.method manual
sudo nmcli connection up eth0

Configuring DHCP

sudo nmcli connection modify eth0 ipv4.method auto
sudo nmcli connection up eth0

Legacy Equivalent: ifcfg Files

Older RHEL/CentOS systems (before NetworkManager became fully dominant) used files under /etc/sysconfig/network-scripts/:

# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.50
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
ONBOOT=yes

ONBOOT=yes is the critical setting ensuring the interface activates automatically at boot.

Comparison Table: Boot-Time Network Configuration Systems

SystemDistrosConfig FormatConfig Location
/etc/network/interfacesOlder Debian/UbuntuPlain text, iface blocks/etc/network/interfaces
NetplanModern Ubuntu (17.10+)YAML/etc/netplan/*.yaml
NetworkManager (nmcli)RHEL/CentOS/Fedora, many desktopsConnection profiles (INI-like)/etc/NetworkManager/system-connections/
ifcfg scripts (legacy)Older RHEL/CentOSShell-variable style/etc/sysconfig/network-scripts/

A Practical Walkthrough: Setting a Static IP on a New Ubuntu Server

Step 1: Identify your interface name

ip link show

Step 2: Create/edit the Netplan config

sudo nano /etc/netplan/00-installer-config.yaml
network:
  version: 2
  ethernets:
    ens160:
      dhcp4: no
      addresses:
        - 10.0.0.20/24
      routes:
        - to: default
          via: 10.0.0.1
      nameservers:
        addresses: [10.0.0.1, 1.1.1.1]

Step 3: Test safely before committing (especially over a remote SSH session)

sudo netplan try

Step 4: Apply permanently once confirmed working

sudo netplan apply

Step 5: Verify

ip addr show ens160
ip route show

Ensuring the Interface Comes Up at Boot (Not Just Now)

A very common mistake: an admin manually brings an interface up with ip addr add or ifconfig, tests it, and moves on — not realizing that command doesn’t persist across a reboot. Always confirm the setting lives in a persistent configuration file (Netplan YAML, nmcli connection profile, or /etc/network/interfaces), not just applied as a one-off runtime command.

# THIS DOES NOT PERSIST ACROSS REBOOT:
sudo ip addr add 192.168.1.50/24 dev eth0

# THIS DOES PERSIST (via Netplan, NetworkManager, etc. as shown above)

Real-World Use Case: Bonded/Redundant Network Interfaces

For servers needing network redundancy, multiple physical interfaces can be “bonded” into one logical interface configured at boot:

network:
  version: 2
  ethernets:
    eth0: {}
    eth1: {}
  bonds:
    bond0:
      interfaces: [eth0, eth1]
      addresses: [192.168.1.50/24]
      parameters:
        mode: active-backup
      routes:
        - to: default
          via: 192.168.1.1

Best Practices

Troubleshooting

Problem: Interface has no IP address after boot

Check whether the interface is set to start automatically:

ip link show
cat /etc/netplan/*.yaml       # Ubuntu
nmcli connection show          # RHEL/Fedora

Problem: netplan apply returns an error

Check YAML syntax carefully — indentation errors are the most common cause:

sudo netplan --debug apply

Problem: Static IP configured but no internet access

Check the default route and DNS separately — a missing gateway or DNS entry can each independently break connectivity:

ip route show
cat /etc/resolv.conf

Problem: Lost SSH access after a network config change

If you used netplan try, it will auto-revert after ~120 seconds. If not, you’ll need out-of-band console access to fix the configuration directly.

Problem: NetworkManager and Netplan conflict on Ubuntu Desktop

Some Ubuntu desktop installations run NetworkManager as the actual backend for Netplan. Check which renderer Netplan is using:

network:
  version: 2
  renderer: NetworkManager   # or 'networkd'

Conclusion

Boot-time network configuration is the foundation that everything else — SSH access, web services, monitoring — depends on. Whether you’re working with legacy /etc/network/interfaces, modern Netplan YAML on Ubuntu, or NetworkManager’s nmcli on RHEL-family systems, the underlying goal is the same: ensure the correct IP configuration is applied automatically and reliably every time the system boots, without requiring manual intervention. Testing changes safely (especially over remote connections) and keeping configurations well-documented will save you from one of the most common and painful sysadmin mistakes: getting locked out of your own server.

Further Reading

Exit mobile version