This howto will show you how to add multiple IP addresses to a single NIC on your Centos system.

Applicable to Centos Versions:

  • Centos 5.x
  • Centos 6.x

Requirements

Explanation of requirements.

  1. Root access to the system
  2. A working network with at least 2 computers.

Doing the Work

Basic description of what will be done and what is expected.

  1. Make a copy of the interfaces config script:
  2. cat /etc/sysconfig/network-scripts/ifcfg-eth0 > /etc/sysconfig/network-scripts/ifcfg-eth0:1
  3. Edit the newly created alias and remove the HWADDR line, save and exit vi (esc :qw):
  4. vi /etc/sysconfig/network-scripts/ifcfg-eth0:1
    
    # Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ <-- remove this line
    DEVICE=eth0:1 <-- change this line
    BOOTPROTO=none
    BROADCAST=192.168.1.255
    HWADDR=00:15:8F:9F:21:E6 <-- remove this line
    IPADDR=192.168.1.5 <-- change this to the new ip
    NETMASK=255.255.254.0
    NETWORK=192.168.1.0
    ONBOOT=yes
    GATEWAY=192.168.1.1
    TYPE=Ethernet
    
  5. Restart the network:
  6. sudo service network restart

Troubleshooting

How to test

Explanation troubleshooting basics and expectations.

  1. use ifconfig to see the currently configured interfaces:
  2. eth0      Link encap:Ethernet  HWaddr 00:15:8F:9F:21:E6
              inet addr:192.168.1.4 Bcast:192.168.1.255  Mask:255.255.254.0
              inet6 addr: fe80::213:8fff:fe9e:31e6/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:61557428 errors:36898 dropped:94634 overruns:17643 frame:0
              TX packets:56608276 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:2226223836 (2.0 GiB)  TX bytes:1019572576 (972.3 MiB)
              Interrupt:201 Base address:0xc00 
    
    eth0:1    Link encap:Ethernet  HWaddr 00:15:8F:9F:21:E6
              inet addr:192.168.1.5  Bcast:192.168.1.255  Mask:255.255.254.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              Interrupt:201 Base address:0xc00 
    
    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:461180 errors:0 dropped:0 overruns:0 frame:0
              TX packets:461180 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:270762863 (258.2 MiB)  TX bytes:270762863 (258.2 MiB)
  3. Ping the IPs to test:
  4. From a computer other than 192.168.1.4 or 192.168.1.5 issue the following commands and examine the output which should be similar to the examples below:
    
    ping 192.168.1.4
    PING 192.168.1.4 (192.168.1.4) 56(84) bytes of data.
    64 bytes from 192.168.1.4: icmp_seq=1 ttl=64 time=0.050 ms
    64 bytes from 192.168.1.4: icmp_seq=2 ttl=64 time=0.039 ms
    
    --- 192.168.1.4 ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 999msrtt min/avg/max/mdev = 0.039/0.044/0.050/0.008 ms
    
    ping 192.168.1.5
    PING 192.168.1.5 (192.168.1.5) 56(84) bytes of data.
    64 bytes from 192.168.1.5: icmp_seq=1 ttl=64 time=3.81 ms
    64 bytes from 192.168.1.5: icmp_seq=2 ttl=64 time=6.77 ms
    
    --- 192.168.1.5 ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 1000msrtt min/avg/max/mdev = 3.815/5.296/6.778/1.483 ms

Common problems and fixes

Common problems described here, include links to known common problems if located on another site.

More Information

Any additional information or notes.

Disclaimer

We test this stuff on our own machines, really we do. But you may run into problems, if you do, come to #centoshelp on irc.freenode.net

Added Reading

© 2012 CentosHelp.org