2

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.

nwalke
  • 643
  • 2
  • 12
  • 32
  • Remove the second gateway 198.58.104.1 – hookenz Dec 05 '12 at 22:52
  • For future readers, I did still have to reboot even after I removed the second gateway. – nwalke Dec 05 '12 at 23:05
  • /etc/init.d/networking restart has always been problematic for me. Always best to do a full machine reboot. – hookenz Dec 06 '12 at 02:57
  • with current Debian based systems syntax has changed: https://unix.stackexchange.com/questions/427414/virtual-nic-siocsifflags-cannot-assign-requested-address-but-gets-created/545844#545844 – Arunas Bartisius Oct 09 '19 at 07:46

3 Answers3

5

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.

hookenz
  • 14,472
  • 23
  • 88
  • 143
  • Fixed my resolv.conf issue. Edited my question, still seeing the same issue after breaking out the auto line. – nwalke Dec 05 '12 at 22:38
  • 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 Dec 05 '12 at 22:41
  • 1
    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. – hookenz Dec 05 '12 at 22:42
  • True. I removed it since it obviously wasn't a part of the real issue. – nwalke Dec 05 '12 at 22:43
  • Remove the second gateway – hookenz Dec 05 '12 at 22:51
  • Removed the second gateway and still couldn't get it to work. Rebooted and everything is working now. – nwalke Dec 05 '12 at 23:05
  • 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. – SteffenNielsen Apr 15 '15 at 11:37
1

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.

Zim3r
  • 1,454
  • 5
  • 24
  • 45
0

With current Debian based systems syntax has changed. The key is to use format of address with slash subnet address 192.168.129.134/17, and not to use netmask keyword anymore.

The preferred method for Debian based system is to use networking configuration files.

The alias method prefers to use such order: eth0, eth:0:0, eth0:1, ...

So first alias to system would be eth0:0 and to achieve this persistent across system reboots, create a file /etc/network/interfaces.d/eth0 with such content:

auto eth0:0
allow-hotplug eth0:0
iface eth0:0 inet static
      address 192.168.129.134/17

Or you can edit directly the file /etc/network/interfaces but this is not recommended as it can be overwritten automatically.

Afterwards do

service networking restart

to test the configuration. Check afterwards with command:

service networking status

and

ip address

Arunas Bartisius
  • 709
  • 1
  • 7
  • 13