Persist IP address alias across reboots in CentOS/RHEL 6 using "ip" command

9,452

Solution 1

Put them in /etc/sysconfig/network-scripts/ifcfg-eth0, with a 2 or 3 etc. after them, such as:

IPADDR2=192.0.2.48
NETMASK2=255.255.255.0
IPADDR3=192.0.2.49
NETMASK3=255.255.255.0

Unfortunately this seems to be undocumented (or I can't find it right now; it looks like Red Hat rearranged their web site yet again).

Solution 2

On the same page where you pulled that paragraph, it tells you to use NetworkManager to assign multiple IP address to one interface.

For new installations, users should select the Manual method on the IPv4 or IPv6 tab in NetworkManager to assign multiple IP address to the same interface. For more information on using this tool, refer to Chapter 7, NetworkManager.

This appears to edit your interface configuration to add:

IPADDR2=IP address
PREFIX2=Netmask
GATEWAY2=Gateway

For what it's worth, it also says that it is no longer necessary to use alias files, but that doesn't mean it doesn't work. (Especially if you need DHCP.) I personally would rather manage my network outside the GUI so you should be able to stop the NetworkManager service and continue business-as-usual with your alias files.

The last option, would be to put your ip commands in /etc/rc.local to be executed at system start. Beware, though, that if the network service is restarted, these settings will not be persistent. This should only be considered as a last resort.

Deployment Guide, 8.2.7. Alias and Clone Files

Share:
9,452

Related videos on Youtube

prl77
Author by

prl77

Updated on September 18, 2022

Comments

  • prl77
    prl77 almost 2 years

    I've always used the ifcfg-eth0:1 alias files to create additional addresses. However, in recent rhel documentation, it states that:

    As the ip command of the iproute package now supports assigning multiple address to the same interface it is no longer necessary to use this method of binding multiple addresses to the same interface.

    Furthermore, numerous answers and comments on this site mention that ifconfig is deprecated and that "ip" should be used instead. I'm fine using it for live changes, but how do I persist the changes across reboots without using the alias files?

    • ewwhite
      ewwhite over 11 years
      I typically don't need aliased IP addresses to be persistent. It's always been a short-term need. There's nothing wrong with separate ifcfg-ethX:Y files, as that framework will continue to be supported for some time. What's your use-case, though?
    • Zoredache
      Zoredache over 11 years
      The iproute2 commands can create and assign addresses to the psuedo-interfaces, using aliases does not necessarily imply that ifconfig is being used. The deprecation of ifconfig, does not imply that the psuedo-interface feature in the kernel is also going away.
  • ewwhite
    ewwhite over 11 years
    Never seen that approach before.
  • Aaron Copley
    Aaron Copley over 11 years
    Yea, that's what NetworkManager did when I tested it just now. I was surprised too. Upvotes for being a shorter, clearer answer. :)
  • prl77
    prl77 over 11 years
    Thanks, I guess it never occurred to me to read sections about NM since I never use it. Good find.
  • prl77
    prl77 over 11 years
    I spoke too soon. This isn't working, perhaps it's only supported by NM?
  • Aaron Copley
    Aaron Copley over 11 years
    If you make changes to these files outside of NetworkManager, they won't be persistent. (Unless you stop NetworkManager and chkconfig it off.) NetworkManager likes to clobber your configuration with what it thinks is correct.
  • James Sumners
    James Sumners over 9 years
    The fun part is ifcfg-eth0:1 works on RHEL 6 but not on RHEL 7 and it's nowhere to be found in the Networking Guide document.
  • Michael Hampton
    Michael Hampton over 9 years
    @jsumners Interface aliases were also deprecated some time before RHEL 6 went out, so I'm not surprised that it's gone entirely in RHEL 7.
  • Stefan Lasiewski
    Stefan Lasiewski about 8 years
    Honestly, is this feature documented anywhere? It's vaguely hinted at in /usr/share/doc/initscripts-*/sysconfig.txt, which quickly mentions configurations like IPADDRn=.