3

Alias interfaces defined in /etc/network/interfaces cannot have multiple default gateways. Unfortunately I would like to use the same interface to access 2 different nets, and I need to define 2 addresses and 2 gateways, on the same interface.

This alias interface has to be on eth1 interface because eth0 is used on the local network. If I define only one gateway for the main eth1 interface, and manually do route add default gw 1.2.3.4 for the alias eth1:0 it works.

But I would like it to set up correctly at boot time automatically.

This is my last trial /etc/network/interfaces :

# The loopback network interface
auto lo
iface lo inet loopback

# The external network interface, address on university internal network
auto eth1
iface eth1 inet static
    address 172.x.y.33
    netmask 255.255.255.224
    network 172.x.y.32
    broadcast 172.x.y.63
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers x.x.x.x
    dns-search mysite.org
    # multiple gateways are not allowed, so I try to add them like that:
    post-up route add default gw 172.x.y.62 metric 1
    pre-down route del default gw 172.x.y.62

# external interface with external world IP address
auto eth1:0
iface eth1:0 inet static
        address 1.2.3.1
        netmask 255.255.255.128
        network 1.2.3.0
        broadcast 1.2.3.128
    # dns on ensg dns
        dns-nameservers x.x.x.x
        dns-search mysite.org
        # multiple gateways are not allowed, so I try to add them like that:
    post-up route add default gw x.x.x.x metric 2
    pre-down route del default gw x.x.x.x

# internal network for my cluster
auto eth0
iface eth0 inet static
    address 10.1.1.1
    netmask 255.255.255.0
    network 10.1.1.0
    broadcast 10.1.1.255
    gateway 10.1.1.1
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 10.1.1.1 127.0.0.1
    dns-search cluster

But when I try to bring up one interface I get:

root@server:~# ifconfig eth1:0 up
SIOCSIFFLAGS: Cannot assign requested address

I cannot find a further solution on my own, does anyone have an idea?

Thanks, best regards.

SOLUTION:

I have finally solved it like that:

# The primary network interface
auto eth1
iface eth1 inet static
        address a.b.c.1
        netmask 255.255.255.128
        network a.b.c.0
        broadcast a.b.c.128
        # this is the interface with the default gateway!
        gateway a.b.c.126 
        dns-nameservers a.d.e.f
        dns-search mysite.org

auto eth1:0
iface eth1:0 inet static
    address 172.x.y.33
    netmask 255.255.255.224
    network 172.x.y.32
    broadcast 172.x.y.63
    # multiple gateways are not allowed, so we do it like that
    post-up route add -net 172.x.y.32 netmask 255.255.255.224 gw 172.x.y.62
    pre-down route del -net 172.x.y.32 netmask 255.255.255.224 gw 172.x.y.62



auto eth0
iface eth0 inet static
    address 10.1.1.1
    netmask 255.255.255.0
    network 10.1.1.0
    broadcast 10.1.1.255
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 10.1.1.1 127.0.0.1
    dns-search cluster

1 Answer 1

5

This setup should not work since alias interfaces can´t have gateways on legacy mode(aka: /etc/network/interfaces:

https://wiki.debian.org/NetworkConfiguration#Legacy_method

An alias interface should not have "gateway" or "dns-nameservers"; dynamic IP assignment is permissible.

What about if you use ip to define this route on a post-up?

ip route add default via x.x.x.x dev eth0:1

The only problem here is that using iproute you will probably need to create 2 rules, one for each link, and set priorities while keeping the default table empty. LARC is your friend - http://www.lartc.org/howto/lartc.rpdb.multiple-links.html

Why use iproute2 instead of route? Because route, arp, ifconfigand it´s friends are old tools and in proccess of being deprecated, but some distros still ships them.

1
  • 1
    Thanks for your answer. Actually, I have solved it right now by: a) disabling gateway on eth0 (I didn't need it), b) adding a default gw on eth1 and post-up only on eth1:0. This works. I will have a look to LARC and iproute2. Thanks for your suggestions.
    – Danduk82
    Apr 24, 2014 at 14:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .