More Than One IP Address On Network Device?

Home » CentOS » More Than One IP Address On Network Device?
CentOS 20 Comments


/etc/sysconfig/network-scripts/ifcfg-eth0 looks like this:

# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
TYPE=Ethernet NAME=eth0
NM_CONTROLLED=no IPV4_FAILURE_FATAL=yes UUID=cc2635ff-3c14-48ba-b19a-84c5b9d36a9d ONBOOT=yes DEVICE=eth0
BOOTPROTO=none HWADDR=00:50:56:01:00:01

if I would need an additional IPv6 address I’d just add IPV6ADDR_SECONDARIES=”ipv6addr”
to this file; if I would need an additional IPv4 address this works only by a virtual device e.g. eth0:1 like this:

# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper), Alias 1
TYPE=Ethernet DEVICE=eth0:1

why can’t I add this to the virtual device eth0:1, if I needed both an additional IPv4 and an additional IPv6 address?
IPV6INIT=yes IPV6ADDR=ipv6addr IPV6_AUTOCONF=no IPV6_DEFAULTGW=ipv6addr-gateway IPV6_DEFAULTDEV=eth0:1

Thanks, Walter

20 thoughts on - More Than One IP Address On Network Device?

  • That’s not true, you can add ipv4 address to the interface in the same way:

    | IPADDR22.17.170.101
    | NETMASK2%

    There is no need to create a virtual network device.

    best regards Ulf

  • no other values needed. i assume that the second ip is in the same subnet as the first one.

    I’m not sure at this point. If you have to add a second ip in another different network maybe you need a virtual device.

    best regards Ulf

  • Interesting… With these settings, namely GATEWAY2=…, how the arbitration is done (in networks stack) which of gateways is used for packets to be sent outside of networks the machine is on?

    As far as I know FreeBSD, there can be only one gateway (BTW, synonym:
    default gateway). Theoretically, the machine can have more than one gateway, but for that you need to have specially configured firewall/nat. Is this somehow different in Linux, and Linux does that auto-magically?


    Valeri Galtsev Sr System Administrator Department of Astronomy and Astrophysics Kavli Institute for Cosmological Physics University of Chicago Phone: 773-702-4247

  • OK, some testing has been done. you have to specify


    please note, that you have to specify only one GATEWAY, there can be only one default gateway active.

    best regards Ulf

  • I tried this way; but
    ‘ifconfig’ doesn’t show these additional addresses …

    thought that IPADDR, GATEWAY, NETMASK and NETWORK must go with, the same with IPADDR2, GATEWAY2, NETMASK2 and NETWORK2 …


  • Hi,

    It works, but, it didn’t create “virtual address” aka “eth0:0”, try using “ip” command: “ip addr show dev eth0”



    2016-09-04 14:27 GMT-03:00 Walter H. :

    *Antonio da Silva Martins Jr. *
    *Analista de Suporte*
    NPD – Núcleo de Processamento de Dados UEM – Universidade Estadual de Maringá
    email: ** / fone: +55 (44) 3011-4015 / 3011-4411
    inoc-dba: 263076*100

    “Real Programmers don’t need comments — the code is obvious.”

  • Valeri,

    not on list as it does not pertain to Linux.

    Decades ago, I was running Solaris x86 at home. My internet connection was a 24/7 14.4KBaud phone connection to my ISP. I then added my first broadband cable connection. During the transition I investigated dual gateways. At that time, Solaris just alternated between the two. It wasn’t load balancing, and once a connection was made it stayed with that interface if it was up. Just new connections alternately were sent via one or the other gateway interfaces.


  • How about using the “ip” tool?

    “ip addr show” and
    “ip route show”

    should give the needed info, at least with CentOS 7.x

    – Yamaban.

  • –Thanks. I looked at the man page and it looks like it’s the Swiss army knife of Linux networking. Lots of subcommands. I’ll dig through that.

  • As a matter of curiosity, why didn’t someone setup ifconfig/netstat/route commands that just referenced & passed args to ip, kinda like grep/egrep/fgrep & possibly others ? Would have made the transition a bit gentler …. $0.02, no more, no less ….

  • of course one can run ip …. commands having the same result as the ifconfig thing, but how would this go, when e.g. eth0 shall be up at OS startup?

    e.g. /etc/sysconfig/network-scripts/route6-sit1
    with this content
    ::/0 dev sit1
    does the job automatically using ip ….
    (ip route add ::/0 dev sit1)

    you will find e.g. where one runs iptables -A …. ip6tables -A … or other firewall solutions;
    but all this doesn’t make any sense as long it is done automatically after OS startup;
    no ip … command?

  • Good to know, b/c as my contact with C5 is minimal and no-existant with C6 , I could not check myself. C7 otoh, I use regulary.

    – Yamaban.

  • In alias files:
    * BOOTPROTO isn’t used, since you can’t run dhclient on an alias interface
    * GATEWAY is disregarded if it is already set
    * DNS* aren’t used at all

    …and in no case do you really need to specify all of BROADCAST, NETWORK, and NETMASK. The latter, alone, is sufficient.

    See /usr/share/doc/initscripts*/sysconfig.txt and
    /etc/sysconfig/network-scripts/ifup-aliases for more information.

    Since not all of them were mentioned in this thread, there are at least three ways to specify additional IPv4 addresses. First, use IPADDRn and either PREFIXn or NETMASKn in ifcfg-dev (documented in sysconfig.txt).
    Second, use alias files such as ifcfg-dev:alias (documented in sysconfig.txt). Third, use range files such as ifcfg-dev-range0 to specify all of the addresses from a START to an END address (documented in ifup-aliases).

    Mostly because device aliases are obsolete: