How to add interface alias on RHEL6 or CentOS6 with NetworkManager?

26,649

Solution 1

run following commands as root:-

  1. cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
  2. vi /etc/sysconfig/network-scripts/ifcfg-eth0:0

Find entry that read as follows:

DEVICE=eth0

Replace with:

DEVICE=eth0:0

Find entry that read as follows:

IPADDR=

Replace it with additional IP address you want to give the machine:

IPADDR=172.134.54.1

4.run:-

ifup eth0:0

or service network restart

similarly you can add additional ip addresses.

for more details refer to :- http://www.cyberciti.biz/faq/linux-creating-or-adding-new-network-alias-to-a-network-card-nic/

Solution 2

NetworkManager has only a very basic CLI nmcli which, unfortunately, is not capable of creating connections at this time (but can bring them up and down).

If you need to configure a machine without a GUI it's strongly recommended you use the normal (non-NM) method as described in the documentation and do not use NetworkManager at all. I will note that you haven't actually given a reason to use NetworkManager on this system, so I have to recommend against it.

If you really have to do this, the NetworkManager way on Red Hat-derived systems is to add all of the IP addresses to the same /etc/sysconfig/network-scripts/ifcfg-eth0 file. This was described in the NetworkManager documentation under Device Aliases.

Example:

IPADDR=172.25.33.1
PREFIX=29
IPADDR2=172.25.33.2
PREFIX2=29
IPADDR3=172.25.33.3
PREFIX3=29
IPADDR4=172.25.33.4
PREFIX4=29
IPADDR5=172.25.33.5
PREFIX5=29
Share:
26,649

Related videos on Youtube

Antoni Sawicki
Author by

Antoni Sawicki

Updated on September 18, 2022

Comments

  • Antoni Sawicki
    Antoni Sawicki over 1 year

    How to add a network interface alias (for example eth0:0) on CentOS6 or RHEL6 in the "correct" way that is through NetworkManager without NM_CONTROLLED=no. And this has to be done without GUI.

    Thank you, a

  • Antoni Sawicki
    Antoni Sawicki over 11 years
    You didn't read the question. The answer you presented is the "old" or "incorrect" way, that is without NetworkManager. If you do it the new file ifcfg-eth0:0 will be deleted unless it has NM_CONTROLLED=no option. My question was how to add it through NetworkManager correctly.
  • Red Tux
    Red Tux over 11 years
    Also if you're going to point to documentation at least point to the documentation most relevant to CentOS which is the upstream Distro. access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Li‌​nux/…
  • achal tomar
    achal tomar over 11 years
    Network Manager Provides GUI tools to configure a network.It cant be used without GUI.Please explain your purpose of using it with command line.Until and unless you make it clear what actually your purpose is we cannot help you.The answer i presented is non-NM method i did this because you didnt made it clear what actually your purpose is.
  • Antoni Sawicki
    Antoni Sawicki over 11 years
    I need to add the second IP address or interface alias from a shell script and it has to be compatible with NM. Thanks.
  • Antoni Sawicki
    Antoni Sawicki over 11 years
    I would refer to SELinux statement that programs should be made compatible with SELinux rather than disable it. Same principle happens here. I want my shell script to be compatible with NM rather than disable it.
  • Michael Hampton
    Michael Hampton over 11 years
    I've posted the directions, but I still have to recommend against it, since you haven't shared with us a good reason for using NetworkManager.
  • achal tomar
    achal tomar over 11 years
    Well in that case you can refer to:-ubuntuforums.org/showthread.php?t=1259634 This is for ubuntu but making a script out of it for RHEL6 is not a difficult task.It must work in your case i hope.