In this article I will show you how to configure a persistent network configuration on your Linux machine. Note that you will need to edit the network adapter configuration file. If you choose to configure your server using other methods (DHCP or bash commands), the network parameters will not persist upon reboot. You can also add those commands in one of the initialization files but, I prefer editing the network adapter configuration file directly.
The location of the network configuration file may differ from one Linux distribution to another. For the following example I will be using two virtual machines running CentOS named VM2 and VM3. The network configuration file on a CentOS Server, can be found in /etc/sysconfig/network-scripts/ifcfg-eth0. If you are using a machine with multiple interfaces, there will be several confg files in the same location so make sure to edit the right file.
If you have downloaded the OS image from http://www.centos.org/, your Server will be configured to obtain it’s IP configuration from a DHCP Server this is why, the following lines would normally appear:
- DEVICE=interface_name; – physical interface name
- BOOTPROTO=protocol; – protocol used to obtain IP configuration
the specified protocol can be one of the following: none — no boot-time protocol will be used bootp — BOOTP protocol will be used. dhcp — DHCP protocol will be used.
- ONBOOT=yes/no – will enable the interface upon reboot.
I’ve opened the ifcfg-eth0 on VM2 using a text editor. You will need to add the following lines on your CentOS machine:
Note that the HWADDR,TYPE,UUID and NM_CONTROLLED parameters are configured automatically by the System so, you will not need to worry about those. I’ve added the IP Address, Network Mask, Gateway and Network Address parameters.
This is how your configuration file should look like:
Now we will make similar configurations on the second Server:
The only thing left to do is to restart the network service on both Servers. To achieve this result, you must run the following command: service network restart
There are several ways to test the network connectivity between these two servers but, one of the most common methods is by using the ping command:
Now it’s time to test our persistent configuration by rebooting both machines. Simply type reboot on each server:
For verifying your IP configuration use ifconfig or ip addr show commands. Note that you can configure a static IP address using these two commands but, these will not persist upon reboot. The ouput of these commands are as follows:
ip addr show
As you can see these commands have similar output so choose whatever method you desire. For verifying the default gateway, use the route command:
That’s it for this article folks, I hope you’ve understood how to configure a persistent IP configuration on your Linux machine. Note that I’m still in the process of learning Linux this is why there may be things that I cannot explain yet. Please feel free to post any question related on this topic and I will try to respond as soon as possible. Wish you all the best and stay tuned for the following articles from IT training day.