1

I apologize if the terminology I used in the title is incorrect, but I'm having a difficult time finding official terms/definitions. I'm on a CentOS 7 system and if I want to add a second IP address to an existing interface it seems I can either edit /etc/sysconfig/network-scripts/ifcfg-eth0 and add:

IPADDR1=xxx.xxx.xxx.xxx
PREFIX1=xx  

or I can create a new file containing the second IP (e.g. /etc/sysconfig/network-scripts/ifcfg-eth0:1).

What's the difference and when would I want to use one method over the other? I've already noticed that the ifconfig tool doesn't seem to find the IP when it's added as IPADDR1 under the same ifcfg file.

Thanks,

  • 4
    It's obsolete, see kernel.org/doc/html/latest/networking/alias.html – frostschutz Sep 19 '19 at 18:15
  • if you add the new address with the label option (eg: ip address add 192.0.2.2/24 dev eth0 label eth0:1) then it becomes visible to ifconfig. This was probably the compatibility layer added more than 10 years ago. the alias interface is also just an additional address, with the label tag, not an interface, but the older interface (ioctl, used by ifconfig) will then display it – A.B Sep 19 '19 at 18:37
  • @A.B Please keep in mind that most net-tools programs are obsolete now. wiki.linuxfoundation.org/networking/net-tools – Rasool Ziafaty Sep 19 '19 at 18:49
  • @RasoolZiafaty I'm describing the way the kernel sees an alias interface: as an additional address, not at all as a sub-interface. it's maintaining a 10+ year old compatibility layer for those obsolete tools which are using (obsolete) ioctl() rather than newer netlink method – A.B Sep 19 '19 at 18:51
2

What's the difference and when would I want to use

eth0:1 is a sub-interface for example you can shutdown a sub-interface independently or tag traffic with a VLAN ID on a sub-interface.

ifconfig tool doesn't seem to find the IP when it's added as IPADDR1 under the same ifcfg file

You must use iproute 2 package instead of net-tools. You can find your second ip address with ip addr. ip route2 is the new package for networking userspace. `ifconfig is deprecated

net-tools utilities obsoleted by iproute2

$ ip addr
 1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
     inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
     inet6 ::1/128 scope host 
        valid_lft forever preferred_lft forever
 2: enp1s0:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
     link/ether 52:54:00:8f:8c:86 brd ff:ff:ff:ff:ff:ff
     inet 192.168.122.197/24 brd 192.168.122.255 scope global dynamic noprefixroute enp1s0
        valid_lft 3546sec preferred_lft 3546sec
     inet 192.168.122.11/24 brd 192.168.122.255 scope global secondary noprefixroute enp1s0
        valid_lft forever preferred_lft forever
     inet6 fe80::4d61:1d19:14a4:a8dc/64 scope link noprefixroute 
        valid_lft forever preferred_lft forever
  • 1
    Thanks, I'll keep focused on iproute2, which seems to support the creation of a second address as well as the creation of a virtual link. – user Sep 19 '19 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.