How do I configure a network card to have multiple IP addresses?

How do I configure a network card to have multiple IP addresses?


Author: Aaron Turner
Email: aturner@pobox.com
Web Page: http://www.pobox.com/~aturner/

System Architecture: All/General
RedHat Release: All/General
FAQ Category: Networking and netcfg
Modification Date: Oct 2, 1998

Question:

How do I configure a network card to have multiple IP addresses?

Answer:

[Note, this assumes you already have the network card working with one IP
address.  If not, do that before you continue.]

The easiest way to configure a network card for IP "aliasing" is to login as
root and cd to /etc/sysconfig/network-scripts

if you do an 'ls' you see one or more files that start with:

ifcfg-

Let's say you have an existing ethernet card (eth0) with an IP of 192.168.1.1
and you want to alias 192.168.1.111 to it as well.

First copy the ifcfg-eth0 file to ifcfg-eth0:0

Next edit ifcfg-eth0:0 with your favorite editor.  Edit the fields as
appropriate.

DEVICE=eth0  --> DEVICE=eth0:0
USRCTL=???  (Allow regular users to control this interface?? yes/no)
ONBOOT=???  (Turn this interface on at boot time?? yes/no)
BOOTPROTO=none
BROADCAST=192.168.1.255 (the brodcast of the new network)
NETWORk=192.168.1.0 (the network the new IP address lives on)
NETMASK=255.255.255.0 (the network mask of the network)
IPADDR=192.168.1.1 --> IPADDR=192.168.1.111 (the 2nd IP address of the interface)

Save the file, and test your work:

ifup eth0:0
ifconfig

You should now see the interface eth0:0 "UP"

You can do this as many times as you wish, by incrementing the second number.
For example a second alias would be interface eth0:1 and so on.

References:

man ifconfig