The cart is empty

CentOS 7, being a popular Linux distribution utilized in server and professional environments, offers robust tools for managing network configurations. To change the IP address, default gateway, and other network settings, it's essential to understand how the network configuration system operates. This article will guide you through the process step by step.

1. Identifying the Network Interface

Before making any changes, it's crucial to identify the network interface on which you want to make modifications. You can do this using the command:

nmcli d

This command will list all available network interfaces on your system.

2. Backing Up the Current Configuration

Before proceeding with any changes, it's recommended to back up the current configuration files to easily restore the original settings if needed. You can back up using the cp command:

sudo cp /etc/sysconfig/network-scripts/ifcfg-[InterfaceName] /etc/sysconfig/network-scripts/ifcfg-[InterfaceName].bak

3. Editing Configuration Files

The configuration file for a network interface can be found in /etc/sysconfig/network-scripts/ with the name ifcfg-[InterfaceName], where [InterfaceName] is the name of the network interface you wish to configure. You can use any text editor such as nano or vi to edit:

sudo nano /etc/sysconfig/network-scripts/ifcfg-[InterfaceName]

In the configuration file, you can set the following values according to your requirements:

  • BOOTPROTO=none - This option indicates that you will set the IP address statically.
  • ONBOOT=yes - Ensures that the interface is activated during system startup.
  • IPADDR=[YourIPAddress] - Sets the static IP address of the interface.
  • NETMASK=[YourSubnetMask] - Specifies the subnet mask.
  • GATEWAY=[GatewayAddress] - Sets the default gateway.
  • DNS1=[PrimaryDNS] - Sets the primary DNS server.
  • DNS2=[SecondaryDNS] - Optionally sets the secondary DNS server.

After making the changes, save and close the file.

4. Restarting Network Services

To apply the changes, you need to restart the network services. You can do this using the following command:

sudo systemctl restart network

5. Verifying the New Settings

After restarting the network services, it's a good practice to verify that the new settings have been applied correctly. You can do this using the ip addr or ifconfig command, which will display the current configuration of the network interface.

That completes the process of changing the IP address, default gateway, and network settings on CentOS 7. It's important to ensure that your network settings are correctly configured for seamless communication between your system and other devices on the network and the internet. If you encounter any issues, double-check that you've entered the correct values and that your network interface is active and properly configured.