CentOS 7 and later versions use predictable network interface naming conventions. Instead of eth0, eth1, etc., interfaces are named based on their physical location, like enp0s3 or ens33. To view your network interfaces, use the command:
CentOS 7 and later versions use predictable network interface naming conventions. Instead of eth0, eth1, etc., interfaces are named based on their physical location, like enp0s3 or ens33. To view your network interfaces, use the command:
ip a
Configuring Network Settings via Command Line
Viewing Current Network Configuration
To view your current network settings, use:
nmcli device show
Setting Up a Static IP Address
- Open the network configuration file:
sudo nano /etc/sysconfig/network-scripts/ifcfg-<interface_name>
- Modify the file with these settings:
BOOTPROTO=static ONBOOT=yes IPADDR=<your_static_ip> NETMASK=<your_netmask> GATEWAY=<your_gateway> DNS1=<primary_dns> DNS2=<secondary_dns>
- Save the file and exit.
- Restart the network service:
sudo systemctl restart network
Configuring DHCP
- Open the network configuration file:
sudo nano /etc/sysconfig/network-scripts/ifcfg-<interface_name>
- Modify the file with these settings:
BOOTPROTO=dhcp ONBOOT=yes
- Save the file and exit.
- Restart the network service:
sudo systemctl restart network
Using NetworkManager Text User Interface (nmtui)
- Launch nmtui:
sudo nmtui
- Select “Edit a connection” and choose your network interface.
- For static IP:
- Set “IPv4 CONFIGURATION” to “Manual”
- Add your IP address, gateway, and DNS servers
- For DHCP:
- Set “IPv4 CONFIGURATION” to “Automatic”
- Save and exit nmtui.
- Restart the network service:
sudo systemctl restart network
Configuring Network Settings via GUI
- Open the Network Manager applet.
- Select your network interface and click “Edit”.
- For static IP:
- Set “Method” to “Manual”
- Add your IP address, netmask, gateway, and DNS servers
- For DHCP:
- Set “Method” to “Automatic (DHCP)”
- Save changes and close the Network Manager.
Advanced Network Configurations
Setting Up Multiple IP Addresses
- Open the network configuration file:
sudo nano /etc/sysconfig/network-scripts/ifcfg-<interface_name>
- Add additional IP addresses:
IPADDR1=<additional_ip_1> IPADDR2=<additional_ip_2>
- Save the file and restart the network service.
Configuring Network Bonding
- Create a bond configuration file:
sudo nano /etc/sysconfig/network-scripts/ifcfg-bond0
- Add the following content:
DEVICE=bond0 TYPE=Bond BONDING_MASTER=yes BOOTPROTO=none ONBOOT=yes IPADDR=<bond_ip_address> NETMASK=<bond_netmask> GATEWAY=<bond_gateway> BONDING_OPTS="mode=1 miimon=100"
- Modify the slave interface configuration files to join the bond.
- Restart the network service.
Troubleshooting Common Network Issues
- Check network connectivity:
ping <gateway_ip>
- Resolve DNS issues:
- Check /etc/resolv.conf for correct DNS entries
- Use
nslookup
ordig
to test DNS resolution
- Fix IP conflicts:
- Use
arping
to detect IP conflicts - Assign a different IP address if needed
- Use
- Resolve DNS issues:
Best Practices and Security Considerations
- Regularly backup network configuration files.
- Implement firewall rules using firewalld or iptables.
- Keep your CentOS system updated.
- Use strong passwords for network-related services.
- Disable unnecessary network services.
By following this guide, you should be able to configure network settings in CentOS effectively, whether you prefer using the command line or GUI methods. Remember to always test your network configuration after making changes to ensure everything is working as expected.