Introduction
Configuring network settings is an essential task for managing Linux systems. This guide covers network interface naming, setting static IP addresses, enabling DHCP, and validating network configurations on CentOS and other Linux distributions using both command-line and GUI methods.
Network Interface Naming
Modern Linux systems use predictable network interface names, such as enp0s3
or eth0
. To list all network interfaces:
ip link show
If you prefer to revert to legacy naming (e.g., eth0
), add the following kernel parameter:
net.ifnames=0 biosdevname=0
Configuring Static IP
Using Command-Line
On CentOS/RHEL
sudo nano /etc/sysconfig/network-scripts/ifcfg-enp0s3
Add or modify the following lines:
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
sudo systemctl restart network
On Ubuntu/Debian
sudo nano /etc/netplan/01-netcfg.yaml
Example configuration:
network:
version: 2
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
sudo netplan apply
Using GUI
In most Linux distributions, you can use the network manager GUI to configure static IPs. Look for Network Settings in your desktop environment, select the network interface, and manually assign the IP address, gateway, and DNS.
Configuring Network Interface for DHCP
Using Command-Line
On CentOS/RHEL
sudo nano /etc/sysconfig/network-scripts/ifcfg-enp0s3
Set:
BOOTPROTO=dhcp
ONBOOT=yes
sudo systemctl restart network
On Ubuntu/Debian
sudo nano /etc/netplan/01-netcfg.yaml
Example configuration:
network:
version: 2
ethernets:
enp0s3:
dhcp4: yes
sudo netplan apply
Using GUI
In the network manager GUI, select the network interface, set the method to Automatic (DHCP), and save the changes.
Validating Network Settings
After configuring network settings, validate them using the following commands:
- Check IP Address:
ip addr show
- Check Routing Table:
ip route
- Test Connectivity:
ping -c 4 8.8.8.8
- Verify DNS Resolution:
nslookup google.com
Troubleshooting
- Network Service Not Starting: Check logs:
sudo journalctl -xe
- Changes Not Applied: Verify configuration files for syntax errors.
- No Connectivity: Ensure correct gateway and DNS settings.
Tips and Special Advice
- Use
nmcli
for scripting and automation of network configurations. - Always back up configuration files before making changes.
- Disable unused network interfaces to avoid conflicts.
- Use
ethtool
to check and configure advanced network settings.
Conclusion
Configuring network settings on Linux is straightforward with the right commands and tools. This guide provides the steps for both command-line and GUI methods, ensuring you can set up static IPs, enable DHCP, and validate network configurations efficiently.