Notes about open source software, computers, other stuff.

Solving “RTNETLINK answers: File exists” when running ifup

On a server with multiple network cards I tried to configure the eth3 interface by editing /etc/network/interfaces (this was an Ubuntu 12.04 machine).

This was the contents of /etc/networking/interfaces:

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
        address xxx.yyy.zzz.mmm
        netmask 255.255.255.0
        gateway xxx.yyy.zzz.1
        dns-nameservers xxx.yyy.zzz.aaa xxx.yyy.zzz.bbb
        dns-search mydomain.nl

auto eth3
iface eth3 inet static
        address 192.168.4.1
        netmask 255.255.255.0
        gateway 192.168.4.1

When I tried to bring the interface up I got an error message:

$ ifup eth3
RTNETLINK answers: File exists
Failed to bring up eth3.

It took me a while to figure it out, but the problem was the gw line in the eth3 entry. Of course you can only have one default gateway in your setup. I missed this because I was also trying to add routes to networks behind the machine on the other end of eth3.
In the end, removing the gw line in the eth3 entry solved the problem.

My final /etc/networking/interfaces looks like this:

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
        address xxx.yyy.zzz.mmm
        netmask 255.255.255.0
        gateway xxx.yyy.zzz.1
        dns-nameservers xxx.yyy.zzz.aaa xxx.yyy.zzz.bbb
        dns-search mydomain.nl

auto eth3
iface eth3 inet static
        address 192.168.4.1
        netmask 255.255.255.0
        post-up /sbin/route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.4.250
        post-up /sbin/route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.4.250
        post-up /sbin/route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.4.250
        post-down /sbin/route del -net 192.168.1.0 netmask 255.255.255.0
        post-down /sbin/route del -net 192.168.2.0 netmask 255.255.255.0
        post-down /sbin/route del -net 192.168.3.0 netmask 255.255.255.0

Update 2013-08-19: Removed network entries as per Ville’s suggestion.

Related Images:

11 Comments

  1. Ville

    The “network” entry is obsoleted and can be removed. It’s derived from the address, and is no longer listed as an option in “man interfaces”.

  2. LCK

    Thanks Ville! I’ve updated the post accordingly.

  3. nemo

    The same error message appears when one of the post-up scripts fails (exits 0). The interface then is configured, but it’s not in /run/network/ifstate (a giveaway). ifdown will fail, even with –force.

    This is, in my opinion, a bug. /run/network/ifstate should reflect the state of the interface *before* post-up.

  4. nemo

    That was (exits != 0) in my post above, but the brackets I used for unequal are being eaten…

    (I hate it when there is no preview option.)

  5. burin

    thanks, on “nemo” opinion that right to check in /run/network/ifstat to solve this provblem.

  6. Spacen Jasset

    There seems to be a bug here, surely. You can have a different gateway for each network interface.

    So why does putting two gateways in the interface file not work. It’s not right, it should add a device specific route should it not?

  7. Scott

    What is the purpose of adding three additional routes to three different subnets with your .4 subnet? How does that affect the gateway on the .4 subnet?

    confused….

    • Mads

      I was wondering just the same thing? Any thougths?

      • LCK

        Hi Scott, Mads,

        It’s been a while (3 years ;-)) since I had to deal with this situation. As far as I can remember, the following was the case:
        There was a single network cable between eth3 (192.168.4.1) on this machine and 192.168.4.250 on the other end. The machine with 192.168.4.250 had another set of (virtual) network cards, each in their own range (192.168.{1,2,3}.0). So in order to tell the machine I was working on (192.168.4.1) where to find the 1,2 and 3 networks, I needed these routes.

  8. withanHdammit

    A decade later, and this post is still helping people! Much appreciated!

    • LCK

      You’re welcome! Glad to hear it is still helpful.

      Funny: it’s the most-viewed page on my blog. Who would have expected that 🙂

Leave a Reply to LCK Cancel reply

Your email address will not be published. Required fields are marked *

© 2024 Lennart's weblog

Theme by Anders NorénUp ↑