How to configure IP addresses on CentOS

Estimated reading time: 1 min

Introduction

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.

Step 1: Log in to your server as root

Go to directory  /etc/sysconfig/network-scripts

cd /etc/sysconfig/network-scripts

Determine the interface that the OS will be using to add the IP address.

/sbin/ifconfig

output-1

The output should look like this.

Step 2: Determining the interface

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.).

nano ifcfg-eth1:0

Add the following fields and edit them accordingly.

DEVICE="eth1:0"
IPADDR="89.207.132.9"
NETMASK="255.255.255.0"
ONBOOT="yes"

output-2

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

/etc/init.d/network restart

You can check if the IP’s has been added to the OS by executing this command:

/sbin/ifconfig

output-3

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:

nano ifcfg-eth1-range

Add the following entries

IPADDR_START=
IPADDR_END=
CLONENUM_START=
NETMASK=

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.

output-4

Now Restart the network

/etc/init.d/network restart

You can check if the IP’s have been added to your OS by executing the following command:

/sbin/ifconfig

output-5

Conclusion

Congratulations, you have configured IPv4 addresses on CentOS.

Was this article helpful?
Dislike 4
Views: 37739

Reader Interactions

Leave a Reply

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