Master Linux Network Configuration: From IP Setup to Netplan & NetworkManager
This guide explains Linux network management, covering IP address and routing configuration, interface naming rules, GRUB tweaks for legacy eth names, editing configuration files for CentOS and Ubuntu (including Netplan YAML), restarting appropriate services, and using graphical tools with NetworkManager, while clarifying the differences between the traditional network service and NetworkManager.
Network Configuration
Network configuration process
1. User‑space tools configure IP address, subnet mask, routes, then invoke system calls to pass the information to the kernel.
2. The kernel stores the received configuration in its network‑stack data structures (e.g., device IP address, netmask).
3. During communication, the kernel looks up the network interface name (e.g., eth0, wlan0), selects the corresponding driver, which converts packets to the proper format and sends them via the physical NIC.
Network interface naming rules
ethX naming (deprecated because the order can change on boot).
Hardware naming: ensX (e.g., ens33), enpXsY (e.g., enp2s0).
MAC‑address naming: enx (enx followed by the MAC address).
Hardware‑path naming: enoX, ensX, etc.
The actual name is defined by rules under /lib/udev/rules.d/.
If you prefer the old ethX naming, you can modify the GRUB configuration.
CentOS
1. Edit the GRUB configuration file: sudo vim /etc/default/grub 2. Modify the line that sets kernel parameters:
GRUB_CMDLINE_LINUX="spectre_v2=retpoline rhgb quiet net.ifnames=0"3. Generate a new GRUB configuration:
grub2-mkconfig -o /boot/grub/grub.cfg # or update-grub4. Reboot the system:
sudo rebootUbuntu
1. Edit the GRUB configuration file: sudo vim /etc/default/grub 2. Modify the kernel parameters line:
GRUB_CMDLINE_LINUX="net.ifnames=0"3. Regenerate the GRUB configuration: sudo grub-mkconfig -o /boot/grub/grub.cfg 4. Reboot the system:
sudo rebootConfigure network via configuration files
This method is typical for headless Linux systems.
CentOS 7
Edit the interface file /etc/sysconfig/network-scripts/ifcfg-IFACE (replace IFACE with the actual interface name) and set the required variables:
TYPE – device type (e.g., Ethernet, Bridge).
NAME – description, usually the same as the interface name.
DEVICE – physical device name (e.g., eth0, ens33).
BOOTPROTO – address acquisition method (dhcp, static, none, bootp).
IPADDR – IPv4 address.
NETMASK – subnet mask in dotted decimal.
PREFIX – CIDR notation (alternative to NETMASK).
GATEWAY – default gateway IP.
ONBOOT – activate on boot (yes/no).
DNS1, DNS2 – primary and secondary DNS servers.
Example static IP configuration:
TYPE="Ethernet"
BOOTPROTO="none"
NAME="eth0"
DEVICE="eth0"
ONBOOT="yes"
IPADDR="10.0.0.7"
PREFIX="24"
GATEWAY="10.0.0.2"
DNS1="180.76.76.76"Example dynamic IP configuration:
TYPE="Ethernet"
BOOTPROTO="dhcp"
NAME="eth0"
DEVICE="eth0"
ONBOOT="yes"After editing, restart the appropriate service:
CentOS 6: service network restart CentOS 7: systemctl restart network CentOS 8:
systemctl restart NetworkManager.serviceUbuntu 16.04
Primary configuration file: /etc/network/interfaces.
Static IP example:
auto eth0
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameserver 180.76.76.76Dynamic IP example:
auto eth0
iface eth0 inet dhcpApply changes by restarting the networking service:
sudo systemctl restart networkingUbuntu 18.04 and later
Since Ubuntu 17.10, static IP configuration is done via Netplan YAML files under /etc/netplan/. The renderer key selects the backend (networkd or NetworkManager).
Static IP YAML example (renderer set to networkd to avoid GUI conflicts):
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.8.10/24
- 10.0.0.10/8
gateway4: 10.0.0.2
nameservers:
addresses:
- 180.76.76.76
- 8.8.8.8
- 1.1.1.1Dynamic IP YAML example:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yesApply the configuration: sudo netplan apply networkd : lightweight daemon for servers without a graphical environment.
NetworkManager : full‑featured manager for desktop environments.
Configure network via graphical interface
Desktop Linux distributions use NetworkManager; GUI changes are saved to /etc/NetworkManager/system-connections/.
Ubuntu 16.04 steps: open System Settings → Network → select the wired connection → click Options to edit settings.
For Ubuntu 18.04+ with a GUI, the Netplan file typically contains renderer: NetworkManager. To avoid conflicts when configuring a static IP via Netplan, change the renderer to networkd so that NetworkManager does not manage those interfaces.
Difference between the traditional network service and NetworkManager
network service : uses init scripts and configuration files to bring interfaces up; common on older distributions.
NetworkManager daemon : runs in the background, manages connections, and is suited for desktops and mobile devices.
CentOS 6 used the network service by default; CentOS 7 switched to NetworkManager while still providing the network service; CentOS 8 removed the network service entirely. Ubuntu has used NetworkManager for a long time, but still supports the legacy /etc/network/interfaces file for compatibility.
Linux Cloud Computing Practice
Welcome to Linux Cloud Computing Practice. We offer high-quality articles on Linux, cloud computing, DevOps, networking and related topics. Dive in and start your Linux cloud computing journey!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
