When an IP address is assigned to your server you need to configure it in your OS. This article will guide you by showing all the steps you need to do in order to configure an IP address in CentOS.
How to add an IP address to CentOS:
- Log in to your server as root.
- Go to directory /etc/sysconfig/network-scripts
- Determine the interface that the OS will be using to add the IP address.
The output should look like this.
Here we determine that we will use interface ”eth1” (Note: This can change for each system).
- Create a file named ”ifcfg-ethX:Y” for each IP you wish to add (replacing X with the ID of the physical and replacing Y with the number of the virtual interface (start with 0 for the first additional IP) for example ”ifcfg-eth1:0”,”ifcfg-eth1:1”,”ifcfg-eth1:2”etc.).
- Add the following fields and edit them accordingly.
- Press CTRL+O and then ENTER to save the file.
Press CTRL+X to Exit. Repeat steps 4 and 5 until you’re finished adding all the IP addresses.
- Restart the network
You can check if the IP’s has been added to the OS by executing this command:
You are done with this configuration.
How to Add an IP range to CentOS:
- Follow the steps 1 to 3 from ”Adding an IP address to CentOS”
- Create a file ‘”ifcfg-ethX-range” (replacing X with the ID of the physical interface for example ”ifcfg-eth1”)
For example, if you were using eth1, you would use the following file name:
- Add the following entries
IPADDR_START=IPADDR_START means the start of the IP address range
IPADDR_END means the end of the IP address range
CLONENUM_START means the number assigned to the first virtual interface (same as in step 4 of ”Adding an IP address to CentOS”), for example, eth1:0 or eth1:1, or eth1:7 as in the screen capture below
NETMASK is 255.255.255.0, depends on the class of the IP addresses.
- Now Restart the network
- You can check if the IP’s have been added to your OS by executing the following command:
That’s it you are completely finished.