Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I have a server running RHEL 6, and have created multiple IP aliases on it. However, when I restart the server, the IP aliases are gone. I tried to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2008
    Posts
    22

    Creating IP aliases upon server reboot


    Hi,

    I have a server running RHEL 6, and have created multiple IP aliases on it. However, when I restart the server, the IP aliases are gone.

    I tried to edit the /etc/rc.d/rc.local file to include

    Code:
    ifconfig eth0:1 1.1.1.1
    ifconfig eth0:2 2.2.2.2
    But it didn't work.

    How can I make sure that the IP aliases stay after reboot?

    Thank you.

    Regards,
    Rayne

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    you have to use the networking scripts or else every time you restart networking, you'll lose the aliases. here's a quick bit to give you a start:
    Code:
    cd /etc/sysconfig/network-scripts
    cat ifcfg-eth0|sed -e 's|^IPADDR=.*$|IPADDR=1.1.1.1|;s|^DEVICE=.*$|DEVICE=eth0:1|' > ifcfg-eth0:1
    cat ifcfg-eth0|sed -e 's|^IPADDR=.*$|IPADDR=2.2.2.2|;s|^DEVICE=.*$|DEVICE=eth0:2|' > ifcfg-eth0:2
    you may need to edit those resulting files, maybe pull out routing/gateway variables or whatever. then restart networking and they should appear. will be there upon reboot, too, unless ONBOOT="no".

    btw, i prefer using ip to ifconfig for setting aliases. it is the *newer* way to do things and you can do much more with ip than with ifconfig. here's a quick example:

    Code:
    ip addr add 1.1.1.1/24 dev eth0
    it is also easy to add these aliases to network config files for persistence across reboots, too (they go in /etc/network/ usually).

    the RHEL/Fedora distros are not using the ip/iproute tools by default yet, though, so i have to install iproute and the config scripts over top of the default ones. for debian/ubuntu, i think they already use ip only.

  3. #3
    Just Joined!
    Join Date
    Sep 2008
    Posts
    22
    Thank you!

  4. #4
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    Location
    The Keystone State
    Posts
    2,672
    You are aware that you can create an interface /etc/sysconfig/network-scripts/ called ifcfg-eth0:1 that contains the following;

    Code:
    DEVICE=eth0:1
    BOOTPROTO=none
    HWADDR=<HDRWARE ADDR>
    ONBOOT=yes
    IPADDR=1.1.1.1
    NETMASK=255.255.255.0
    TYPE=Ethernet
    You can repeat this as needed. and on boot/reboot the interfaces will be started automatically.

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •