Search Our Database
How to configure network settings on CentOS 7
Introduction
Configuring network settings on a CentOS 7 server is a crucial task for ensuring proper connectivity and communication within your network. Whether you need to set a static IP address, configure the network gateway, or set DNS servers, this guide will walk you through the necessary steps to configure your server’s network settings using the command line.
Step 1: Type the following command to access your system’s network configuration file. We will be using ethernet port eth0.
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Step 2: Here you can configure it as you like, as an example though we are going to configure it into a server with static IP. Press “i” to enter Insert Mode and perform the following changes.
- BOOTPROTO=static
- ONBOOT=yesAdd in the following lines:
- IPADDR=<your-ip-address>
- NETMASK=<your-network-mask>
Press Esc and then type “:wq” to save and exit the network configuration file.
Step 3: Type the following command to edit your network gateway.
vi /etc/sysconfig/network
Then add in the following line: GATEWAY=<your-gateway>
Press Esc and then type “:wq” to save and exit the network configuration file.
Step 4: Add in DNS by typing the following command:
vi /etc/sysconfig/network
Then add in the following lines to use Google DNS:
nameserver 8.8.8.8 nameserver 8.8.4.4
Press Esc and then type “:wq” to save and exit the network configuration file.
Note: To check your network configuration on CentOS 7, use the following command:
ip addr
This is because the previously used command “ifconfig” has become obsolete as of this version of CentOS.
Step 5: Type in the following commands to start your network settings.
service network start ifup eth0
Try pinging any available sites (eg. google.com), if the connection works then the configuration is a success.
With the network now working, you can perform any updates of your CentOS with the command:
yum update
Conclusion
Configuring network settings on CentOS 7 is essential for ensuring that your server can communicate effectively within your network. By following these steps, you can set a static IP address, configure the network gateway, add DNS servers, and verify your network settings. Proper network configuration allows you to maintain stable and reliable connections, crucial for the performance and security of your server.
Article posted on 18 April 2020