How to configure IP addresses on CentOS

Estimated reading time: 1 min

Introduction

Whenever an IP address is assigned to your server you need to configure it in your OS. This article will guide you by showing all steps you need to do in order to configure an IP address in CentOS.

STEPS Adding an IP address to CentOS:

  1.  Login  to your server as root.
  2.  Go to directory  /etc/sysconfig/network-scripts.
    cd /etc/sysconfig/network-scripts
    
  3.  First determine the interface that the OS will be using to add the IP address.
    /sbin/ifconfig
    
    Output01

    Output01

    The output should look like this

    Here we determine that we will use interface ”eth1” (Note: This can change for each system).

  4. 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
    
  5. Add the following fields and edit them accordingly.
    DEVICE="eth1:0" 
    IPADDR="89.207.132.9"
    NETMASK="255.255.255.0" 
    ONBOOT="yes"

    ifcfg-eth1:0

    ifcfg-eth1:0

  6. 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.
  7. Restart the network
    /etc/init.d/network restart
  8. We can check if the IP’s has been added to the OS
    /sbin/ifconfig
    ifconfig

    ifconfig

    Done.

STEPS Adding an IP range to CentOS:

  1.  Follow the steps 1 to 3 from ”Adding an IP address to CentOS”
  2. 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
    
  3. 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.

    ifcfg-eth1-range

    ifcfg-eth1-range

  4. Restart the network
    /etc/init.d/network restart
  5. We can check if the IP’s have been added to the OS.
    /sbin/ifconfig
    ifconfig

    ifconfig

    Done.

Was this article helpful?
Dislike 0
Views: 21

Reader Interactions