CentOS Linux Networking

Add IP to CentOS 5/6

If you recently got a secondary IP block for your server but you do not know how to bind the secondary IP address, please follow the steps below:

 

First, run the following command to see which interface your server is using:

 

ifconfig 

You will see an output like so:

eth0 Link encap:Ethernet HWaddr 00:0C:29:40:93:9C
inet addr:192.168.154.102 Bcast:192.168.154.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1771 errors:0 dropped:0 overruns:0 frame:0
TX packets:359 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:138184 (134.9 KiB) TX bytes:49108 (47.9 KiB)
Interrupt:67 Base address:0x2000

lo   Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:390 errors:0 dropped:0 overruns:0 frame:0
TX packets:390 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:29204 (28.5 KiB) TX bytes:29204 (28.5 KiB)

In this scenario, you will be looking for the eth0 interface.  Now on to the actual command to bind the secondary ip!  Let’s say you get allocated an additional block of 3 ip addresses:  192.168.154.103, 192.168.154.104, 192.168.154.105 with a netmask of 255.255.255.0, you would do the following:

 

ifconfig eth0:1 192.168.154.103 netmask 255.255.255.0
ifconfig eth0:1 up
ifconfig eth0:2 192.168.154.104 netmask 255.255.255.0
ifconfig eth0:2 up
ifconfig eth0:3 192.168.154.105 netmask 255.255.255.0
ifconfig eth0:3 up 

If you want the new IP’s to be brought up automatically upon reboots, you can add these commands to the file: /etc/rc.local

That’s all there is to it!

Related Articles

  • Assign range of IP addresses to an interface.

    Sometimes you may need to assign a wide range of IP addresses to your network interface in Linux systems. Instead of manually creating aliases for the network interface, it is...
  • How to get rid of ^M characters.

    When you edit a file in Windows and then open in UNIX, you must have seen ^M characters getting appended in the content. How to get rid of it ?...
  • Extract Tar Files to a Different Directory

    Syntax Typical Unix tar syntax: tar -xf file.name.tar -C /path/to/directory GNU/tar syntax: tar xf file.tar -C /path/to/directory tar xf file.tar --directory /path/to/directory Example: Extract files to another directory In this...
  • A Basic Overview of the Vim Text Editor

    Many articles in our Webair Community advise editing configuration files. We usually recommend using your preferred text editor. I personally prefer vim. Vim, or its older sibling vi, are installed...