1

I faced a small problem when assigning multiple IPv4 addresses to the interface. I added 2 IPv4 addresses by following these steps :

  • first, I added the 2 IPv4 addresses using these command-lines:

    #sudo ip address add  10.0.0.21/24 dev eth1
    #sudo ip address add  10.0.1.21/24 dev eth1
    

    To check the result I typed the following command-line :

    #ip address show eth0.
    
  • Second, to make these configurations permanent, I edited the /etc/network/interfaces file by adding specific configurations and now it looks like this:

    auto eth1 
    iface eth1 inet static
           address 10.0.0.21
           netmask 255.255.255.0
           gateway 10.0.0.1
    
    auto eth1 
    iface eth1 inet static
           address 10.0.1.21
           netmask 255.255.255.0
           gateway 10.0.1.1
    
  • Finally, to activate these settings without a reboot , I used the
    ifdown/ifup by typing:

    #sudo ifdown eth1 && sudo ifup eth1.
    

The first problem is when I used the ifdown/ifup command , I got this notifications:

ifdown: interface eth1 not configured
RTNETLINK answers: File exists
Failed to bring up eth1.

whereas I updated the /etc/network/interfaces so, normally it may to recognize the interface.

The second problem is when I rebooted my machine all the setting were lost. thank you

1 Answers1

1

To add secondary ip on interface you must create sub-interface.

In you case eth1:1

auto eth1 
iface eth1 inet static
       address 10.0.0.21
       netmask 255.255.255.0
       gateway 10.0.0.1

auto eth1:1 
iface eth1:1 inet static
       address 10.0.1.21
       netmask 255.255.255.0
       gateway 10.0.1.1
       metric 20

Based on comment I edit answer and add metric to interface eht1:1. This mean that gateway on eth1 will be primary routing decision. You can add metric to eth1 if you wish eth1:1 be primary.

Edit 2

I found more people which have the same problem and solution is:

auto eth1 
iface eth1 inet static
       address 10.0.0.21
       netmask 255.255.255.0
       gateway 10.0.0.1
       up ip addr add 10.0.1.21/24 dev eth1 label eth1:1
       down ip addr del 10.0.1.21/24 dev eth1 label eth1:1
       up ip route add 10.0.1.0/24 via 10.0.1.1 dev eth1:1 metric 20
       down ip route del 10.0.1.0/24 via 10.0.1.1 dev eth1:1 metric 20
2707974
  • 10,758