How to Add an IP Address to an Interface With Red Hat or CentOS Or Linux OS?

Posted by Jiltin     27 February, 2009    1,590 views   

Purpose: Adding an IP Address to an Interface With Red Hat and CentOS

This tutorial demonstrates how to bind multiple IP addresses to a single network card. By using multiple IP’s you can run a service under a specific IP while having another service under a different one (for example, have HTTP on one and SMTP on another), or create a private LAN using a local IP and have the alias hold your Internet IP (such as NAT). One of the major benefits is that you don’t need a physical adapter for each IP but instead can create many virtual ones tied to a single physical card. The instructions provided apply to RedHat, Fedora, and CentOS. I’ll be using LAN IP’s in this example, so replace them with the ones you’ll be using.

The network scripts are located in /etc/sysconfig/network-scripts/

#> cd /etc/sysconfig/network-scripts/

#> ifconfig

you will see

eth0      Link encap:Ethernet  HWaddr 00:1C:23:02:E2:E6
inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0
inet6 addr: 2002:47c6:ce62:1234:21c:23ff:fe02:e2e6/64 Scope:Global
inet6 addr: fe80::21c:23ff:fe02:e2e6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:3786 errors:0 dropped:0 overruns:0 frame:0
TX packets:3798 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1263270 (1.2 MiB)  TX bytes:2504415 (2.3 MiB)
Interrupt:177

#> cp ifcfg-eth0 ifcfg-eth0:0

vi ifcfg-eth0:0

DEVICE=eth0:0
IPADDR=192.168.0.110

Finally if you want it to start up with the server just make sure ONBOOT is set to yes.
ONBOOT=yes

Then type
#> service network restart

Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]

#> ifconfig

eth0      Link encap:Ethernet  HWaddr 00:1C:23:02:E2:E6
inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0
inet6 addr: 2002:47c6:ce62:1234:21c:23ff:fe02:e2e6/64 Scope:Global
inet6 addr: fe80::21c:23ff:fe02:e2e6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:41 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:658 (658.0 b)  TX bytes:10642 (10.3 KiB)
Interrupt:177

eth0:0    Link encap:Ethernet  HWaddr 00:1C:23:02:E2:E6
inet addr:192.168.0.110  Bcast:192.168.0.255  Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
Interrupt:177

Please notice filename format: IT IS MANDATORY! Each of these files will provide IP information for a network initializing script.To activate new IPs you can reboot the server. Restart the network config activate new IPs by running one of the following scripts below:
Option 1: (Start each ip individually)

# ./ifup eth0:0

Option2: (Restart the entire network)

# /etc/rc.d/init.d/network -reload

You are done. It is permanently added in your system. Tested both CentOS and Redhat systems.

Similarly, you can add more ips like this and repeating the steps above

cp ifcfg-eth0 ifcfg-eth0:1
cp ifcfg-eth0 ifcfg-eth0:2

Following Google Searches Lead To This Post: oracle 11g install aix not seeing swap

Post to Twitter  Post to Delicious  Post to Digg    Post to StumbleUpon

Categories : Scripts Unix Tags :

Comments
May 17, 2009

Good site, admin.

Posted by Alex
May 18, 2009

Good site, admin.

Posted by Sancho
May 18, 2009

Good site, admin.

Posted by Panzer
Leave a comment

(required)

(required)