Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Alias interfaces defined in /etc/network/interfaces cannot have multiple default gateways. Unfortunately I would like to use the same interface to access 2 differents 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 manally 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.23.14.33
    netmask 255.255.255.224
    network 172.23.14.32
    broadcast 172.23.14.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.23.14.62 metric 1
    pre-down route del default gw 172.23.14.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 193.55.146.1
        netmask 255.255.255.128
        network 193.55.146.0
        broadcast 193.55.146.128
        # this is the interface with the default gateway!
        gateway 193.55.146.126 
        dns-nameservers 193.50.27.67
        dns-search mysite.org

auto eth1:0
iface eth1:0 inet static
    address 172.23.14.33
    netmask 255.255.255.224
    network 172.23.14.32
    broadcast 172.23.14.63
    # multiple gateways are not allowed, so we do it like that
    post-up route add -net 172.23.14.32 netmask 255.255.255.224 gw 172.23.14.62
    pre-down route del -net 172.23.14.32 netmask 255.255.255.224 gw 172.23.14.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
share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
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 at 14:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.