๐ง Linux Network Configuration from Beginner to Advanced: Interface Naming, IP Setup, Gateway, DNS, and Hostname – Complete Guide
Network configuration is one of the most fundamental tasks in Linux system administration. Whether you are deploying servers, managing virtual machines, connecting to cloud platforms, or setting up development environments, understanding interface naming, IP assignment, routing, DNS, and hostname configuration is essential.
This article provides a complete, encyclopedia-level guide to Linux networking—from basic concepts
to practical operations using nmcli, ip, traditional ifcfg files, and systemd-networkd.
It includes configuration examples, troubleshooting techniques, and distribution-specific differences.
๐ 1. Linux Interface Naming (Predictable Network Interface Names)
Modern Linux distributions use “predictable interface names,” replacing legacy names such as eth0.
Examples include:
ens160– PCI Express–based namingenp0s3– Bus address–based namingeth0– Legacy naming (still appears in minimal or custom builds)
๐ List all interfaces
ip link
๐ View interface details
ip addr show ens160
Virtualization environments such as Proxmox, VMware, or KVM often modify interface numbering depending on virtual hardware order.
๐ 2. Configuring Static IP: Three Major Methods
Linux supports three mainstream configuration approaches:
| Method | Distributions | Difficulty | Characteristics |
|---|---|---|---|
| ifcfg (legacy) | RHEL / CentOS / Rocky Linux | Medium | Traditional config-file method widely used in enterprises |
| nmcli / nmtui | All NetworkManager-based systems | Easy | Modern, stable, interactive, preferred for most use cases |
| systemd-networkd | Ubuntu Server / Debian / containers | Medium | Efficient, clean, ideal for cloud or container images |
๐ฆ 2-1. Configure Static IP Using nmcli (Recommended)
nmcli con mod ens160 ipv4.addresses 192.168.1.20/24
nmcli con mod ens160 ipv4.gateway 192.168.1.1
nmcli con mod ens160 ipv4.dns "8.8.8.8 1.1.1.1"
nmcli con mod ens160 ipv4.method manual
nmcli con down ens160; nmcli con up ens160
---
๐ฆ 2-2. Configure Static IP Using ifcfg (RHEL/CentOS)
Configuration file location:
/etc/sysconfig/network-scripts/ifcfg-ens160
Example:
BOOTPROTO=none
DEVICE=ens160
IPADDR=192.168.1.20
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=1.1.1.1
ONBOOT=yes
Restart networking:
systemctl restart NetworkManager
---
๐ฆ 2-3. Configure Static IP Using systemd-networkd
File location:
/etc/systemd/network/10-ens160.network
Content:
[Match]
Name=ens160
[Network]
Address=192.168.1.20/24
Gateway=192.168.1.1
DNS=8.8.8.8 1.1.1.1
Enable the service:
systemctl enable systemd-networkd --now
systemctl restart systemd-networkd
๐ 3. Essential Network Commands
๐ Check current IP
ip addr
๐ Test gateway connectivity
ping 192.168.1.1
๐ View routing table
ip route
๐ DNS testing
dig google.com
nslookup google.com
๐ View listening ports
ss -tulnp
๐ 4. DNS (Resolver) Configuration
NetworkManager-managed systems usually configure DNS via nmcli or DHCP.
๐ช Method 1: Using nmcli
nmcli con mod ens160 ipv4.dns "8.8.8.8 1.1.1.1"
nmcli con up ens160
๐ช Method 2: Editing resolv.conf (Not Recommended)
In systems using systemd-resolved or NetworkManager, /etc/resolv.conf may be overwritten.
To force manual control:
chattr +i /etc/resolv.conf
⚠ Use only for special scenarios.
๐ 5. Configuring Default Gateway
๐ง Using nmcli
nmcli con mod ens160 ipv4.gateway 192.168.1.1
๐ง Using ip route (temporary)
ip route add default via 192.168.1.1
๐ง Show routing
ip route show
๐ 6. Hostname Configuration
๐ Check hostname
hostnamectl
๐ง Set a new hostname
hostnamectl set-hostname web01.example.local
Reopen your shell to apply.
๐ 7. Troubleshooting: Common Issues
❗ No IP Address?
nmcli device status
❗ DNS failures?
dig @8.8.8.8 google.com
❗ Can ping gateway but cannot reach the Internet?
- Upstream gateway missing NAT
- Firewall blocking traffic
- Incorrect DNS configuration
❗ Interface name changed unexpectedly?
ls -l /sys/class/net/
Usually caused by virtual hardware order changes.
ๆฒๆ็่จ:
ๅผต่ฒผ็่จ