3

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
  • 41
  • 1
  • 1
  • 3

2 Answers2

2

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/

achal tomar
  • 433
  • 3
  • 12
  • 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. – Antoni Sawicki Sep 10 '12 at 18:56
  • Also if you're going to point to documentation at least point to the documentation most relevant to CentOS which is the upstream Distro. https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Network_Interfaces.html – Red Tux Sep 11 '12 at 01:49
  • 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. – achal tomar Sep 11 '12 at 21:11
  • 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 Sep 12 '12 at 04:19
  • Well in that case you can refer to:-http://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. – achal tomar Sep 12 '12 at 06:19
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
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • 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. – Antoni Sawicki Sep 12 '12 at 04:25
  • 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. – Michael Hampton Sep 12 '12 at 04:35