GuestbookSign our guestbook ContactGet in touch with the authors ArchiveAll unixwerk articles since 2003
January 04, 2011

MiniTip: Setting IP Aliases under Fedora

Contents

  1. Set an IP Alias
  2. Make the IP Alias Permanent
  3. Remove an IP Alias

Set an IP Alias

To put a second IP address to eth0, just enter on the commandline as root:

# ip addr add 192.168.100.199/24 brd + dev eth0 label eth0:0

This sets an IP address 192.168.100.199 to eth0:0. Check again with ifconfig:

# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:40:45:28:89:37
          inet addr:192.168.100.199  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::92e6:baff:fe43:ff4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:16191 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12375 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:20577186 (19.6 MiB)  TX bytes:1174207 (1.1 MiB)
          Interrupt:27 Base address:0x6000

eth0:0    Link encap:Ethernet  HWaddr 00:40:45:28:89:37
          inet addr:192.168.100.199  Bcast:192.168.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:27 Base address:0x6000

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:114 errors:0 dropped:0 overruns:0 frame:0
          TX packets:114 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:13662 (13.3 KiB)  TX bytes:13662 (13.3 KiB)

Now we see a new interface eth0:0. If you forget to define a label for the alias you would not see the new IP in the ifconfig output, but it would still work! In this case check with:

With label:

# ip a | grep -w inet
    inet 127.0.0.1/8 scope host lo
    inet 192.168.1.44/24 brd 192.168.1.255 scope global eth0
    inet 192.168.100.199/24 brd 192.168.100.255 scope global eth0:0

No label:

# ip a | grep -w inet
    inet 127.0.0.1/8 scope host lo
    inet 192.168.1.44/24 brd 192.168.1.255 scope global eth0
    inet 192.168.100.199/24 brd 192.168.100.255 scope global eth0

Make the IP Alias Permanent

If you use ip or ifconfig to set an IP alias, the alias won't be present after the next reboot. To make the setting permanent, we have to create a file ifcfg-eth0:0 with the following contents:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
ISALIAS=yes
DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.100.199
NETMASK=255.255.255.0
NETWORK=192.168.100.0
BROADCAST=192.168.100.255
TYPE=Ethernet

The important part in this file is that you include the line ISALIAS=yes - otherwise the file will be ignored! It took me some time to figure this out.

We have to create hardlinks to this file under /etc/sysconfig/networking/devices and /etc/sysconfig/networking/profiles/default:

# ln /etc/sysconfig/network-scripts/ifcfg-eth0:0 /etc/sysconfig/networking/devices/ifcfg-eth0:0
# ln /etc/sysconfig/network-scripts/ifcfg-eth0:0 /etc/sysconfig/networking/profiles/default/ifcfg-eth0:0

Remove an IP Alias

You can remove an IP alias with a comand like this:

# ip addr delete 192.168.100.199/24 dev eth0

This deletes the second address from the interface keeping the first. eth0:0 will disappear in the ifconfig output.