Problems bringing up a second virtual network interface

10,941

Solution 1

EDIT:

The problem is you have 2 default gateway's defined. You need to remove one of them. I would think the one on the eth0:1 device.

The file exists error is being thrown by attempting to add the default route again which is already in place.


Firstly, I presume the * as the host number is a valid number and not literally a '*'?

Now try it this way. I suspect there is a problem with the parsing of the auto line in the startup scripts - just a hunch, I haven't looked.

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#eth0 is our main IP address
auto eth0
iface eth0 inet static
 address 198.58.103.*
 netmask 255.255.255.0
 gateway 198.58.103.1
 # Put your nameserver address here!
 dns-nameservers x.x.x.x 

#eth0:0 is our private address
auto eth0:0
iface eth0:0 inet static
 address 192.168.129.134
 netmask 255.255.128.0

#eth0:1 is for www.site.com
auto eth0:1
iface eth0:1 inet static
 address 198.58.104.*
 netmask 255.255.255.0
 # This shouldn't be here!  remove it.
 #gateway 198.58.104.1

And secondly, to get rid of the annoying resolv.conf error run:

sudo dpkg-reconfigure resolvconf

Although this is a separate issue.

Solution 2

Try this command:

sudo dpkg-reconfigure resolvconf

Also this:

ifdown eth0:0 
ifdown eth0:1 
ifdown eth0
ifup eth0

The ifup eth0 at the end starts both the primary and the alias AND only sets the route once.

Share:
10,941

Related videos on Youtube

nwalke
Author by

nwalke

Updated on September 18, 2022

Comments

  • nwalke
    nwalke over 1 year

    I'm having issues adding a second IP address to one interface. Below is my /etc/networking/interfaces

       # The loopback network interface
    auto lo
    iface lo inet loopback
    
    #eth0 is our main IP address
    auto eth0
    iface eth0 inet static
     address 198.58.103.*
     netmask 255.255.255.0
     gateway 198.58.103.1
    
    #eth0:0 is our private address
    auto eth0:0
    iface eth0:0 inet static
     address 192.168.129.134
     netmask 255.255.128.0
    
    #eth0:1 is for www.site.com
    auto eth0:1
    iface eth0:1 inet static
     address 198.58.104.*
     netmask 255.255.255.0
     gateway 198.58.104.1
    

    When I run /etc/init.d/networking restart, I get a fail error about bringing up eth0:1:

    RTNETLINK answers: File exists
    Failed to bring up eth0:1.
    

    Any reason this would be? I didn't have any problems with I first set up eth0 and eth0:0.

    • hookenz
      hookenz over 11 years
      Remove the second gateway 198.58.104.1
    • nwalke
      nwalke over 11 years
      For future readers, I did still have to reboot even after I removed the second gateway.
    • hookenz
      hookenz over 11 years
      /etc/init.d/networking restart has always been problematic for me. Always best to do a full machine reboot.
    • Arunas Bartisius
      Arunas Bartisius over 4 years
      with current Debian based systems syntax has changed: unix.stackexchange.com/questions/427414/…
  • nwalke
    nwalke over 11 years
    Fixed the resolv.conf issue
  • nwalke
    nwalke over 11 years
    Fixed my resolv.conf issue. Edited my question, still seeing the same issue after breaking out the auto line.
  • Zim3r
    Zim3r over 11 years
    Alright, I edited my post.
  • hookenz
    hookenz over 11 years
    Try a full reboot. I've not had much success with networking restart personally. It's not always cleanly restarted. Failing that, try changing eth0:1 to eth0:2
  • hookenz
    hookenz over 11 years
    Also don't change your question too much. It won't be useful if you solve it and make it right. e.g. you've now removed the resolvconf stuff.
  • nwalke
    nwalke over 11 years
    True. I removed it since it obviously wasn't a part of the real issue.
  • hookenz
    hookenz over 11 years
    Remove the second gateway
  • nwalke
    nwalke over 11 years
    Removed the second gateway and still couldn't get it to work. Rebooted and everything is working now.
  • SteffenNielsen
    SteffenNielsen about 9 years
    The two gateways of the same physical netcard seemed to be the problem for me too. To avoid rebooting, I did: ifdown eth0:1; ifconfig eth0:1 down; ifup eth0:1. It then came up without any erros/warnings.