mooc-course.com is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

How to configure network interfaces in CentOS?

How to configure network interfaces in CentOS?

5/5 - (1 vote)

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

  1. Open the network configuration file:
    sudo nano /etc/sysconfig/network-scripts/ifcfg-<interface_name>
  2. 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>
  3. Save the file and exit.
  4. Restart the network service:
    sudo systemctl restart network

Configuring DHCP

  1. Open the network configuration file:
    sudo nano /etc/sysconfig/network-scripts/ifcfg-<interface_name>
  2. Modify the file with these settings:
    BOOTPROTO=dhcp
    ONBOOT=yes
  3. Save the file and exit.
  4. Restart the network service:
    sudo systemctl restart network

Using NetworkManager Text User Interface (nmtui)

  1. Launch nmtui:
    sudo nmtui
  2. Select “Edit a connection” and choose your network interface.
  3. For static IP:
    • Set “IPv4 CONFIGURATION” to “Manual”
    • Add your IP address, gateway, and DNS servers
  4. For DHCP:
    • Set “IPv4 CONFIGURATION” to “Automatic”
  5. Save and exit nmtui.
  6. Restart the network service:
    sudo systemctl restart network

Configuring Network Settings via GUI

  1. Open the Network Manager applet.
  2. Select your network interface and click “Edit”.
  3. For static IP:
    • Set “Method” to “Manual”
    • Add your IP address, netmask, gateway, and DNS servers
  4. For DHCP:
    • Set “Method” to “Automatic (DHCP)”
  5. Save changes and close the Network Manager.
See also  Parrot Linux vs Manjaro: A Comprehensive Comparison

Advanced Network Configurations

Setting Up Multiple IP Addresses

  1. Open the network configuration file:
    sudo nano /etc/sysconfig/network-scripts/ifcfg-<interface_name>
  2. Add additional IP addresses:
    IPADDR1=<additional_ip_1>
    IPADDR2=<additional_ip_2>
  3. Save the file and restart the network service.

Configuring Network Bonding

  1. Create a bond configuration file:
    sudo nano /etc/sysconfig/network-scripts/ifcfg-bond0
  2. 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"
  3. Modify the slave interface configuration files to join the bond.
  4. Restart the network service.

Troubleshooting Common Network Issues

  1. Check network connectivity:
    ping <gateway_ip>
    1. Resolve DNS issues:
      • Check /etc/resolv.conf for correct DNS entries
      • Use nslookup or dig to test DNS resolution
    2. Fix IP conflicts:
      • Use arping to detect IP conflicts
      • Assign a different IP address if needed

Best Practices and Security Considerations

  1. Regularly backup network configuration files.
  2. Implement firewall rules using firewalld or iptables.
  3. Keep your CentOS system updated.
  4. Use strong passwords for network-related services.
  5. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free Worldwide Courses

Learn online for free

Enroll in Multiple Courses

Learn whatever your want from anywhere, anytime

International Language

Courses offered in multiple languages & Subtitles

Verified Certificate

Claim your verified certificate