44

I had this problem when I got my new Wi-Fi dongle and have seen a few people with the same issue. Basically when I have one interface configured and want to swap to the other one, it throws up this error:

RTNETLINK answers: File exists
Failed to bring up eth0

or something similar.

/etc/network/interfaces file:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 192.168.1.2
    netmask 255.255.255.0
    gateway 192.168.1.1

iface wlan0 inet static
    address 192.168.1.3
    netmask 255.255.255.0
    gateway 192.168.1.1
  • 1
    You can not have more than one default gateway on Linux. In particular you can not have the same default gateway on two different interfaces. And you can not have the same network on two different interfaces. – ceving May 18 '17 at 7:54
  • @ceving there is no problem in having two interfaces in the same network. There is also no problem if these two interfaces have the same gateway. The routing table is parsed in a strict manner and you can imagine the entries being destination IP -> interface. Thus it will be sent to the gateway through the interface that it parses first (from the bottom) in the routing table. – George May 2 at 12:44
  • if dealing with IPV6 always add a network length: xxxx:xxxx:...::1/64 on the address – fcm Jun 14 at 11:34
46

If the solution provided by @theoB610 still doesn't work, then you might have to flush the wlan0 device before ifup and ifdown.

sudo ip addr flush dev wlan0

This is a problem not too specific to Raspberry Pi, a similar problem occurred and was solved in wired networks in here (from where I derived the solution for my problem with the Pi).

  • 1
    I was having this problem on an HP ProLiant server (!), and this fixed it. – sudo Aug 9 '16 at 18:17
  • 1
    Great solution. The basic problem is some previous configuration, automatic or manual (such as running ifconfig from the cmd line) still lingers. The flush command fixes that situation. – kmarsh Sep 22 '16 at 15:13
  • 1
    I have had this issue when there are malformed /etc/sysconfig/network-scripts/ifcfg-* files causing by NetworkManager not liking some setups and creating a replacement file, thus creating multiple extra files and causing the error RTNETLINK answers: File exists. Removing the broken ones (the ones that don't show as a profile) seems to be a fix. – Wilf Oct 19 '16 at 22:31
  • 2
    Never copy-paste this on a production server. I replaced wlan0 with eth0 and the interface went down immediately and don't want to come back. – Fusseldieb Feb 7 '17 at 16:52
  • 1
    Interesting that no one provided simplest and by the rule safest method: reboot. For instance with flushing interface I had troubles - my interface/IP went down and I could only connect directly on a console... so reboot is always the way to go for me with this. – stamster Mar 27 '18 at 13:34
24

I think a solution can be found in Solving “RTNETLINK answers: File exists” when running ifup (Lennart's weblog); it certainly fixed it for me.

Basically you can only have one gateway assigned in your interfaces file. Remove any duplicate lines that determine the gateway so that it only appears once.

Modified /etc/network/interfaces file:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 192.168.1.2
    netmask 255.255.255.0
    gateway 192.168.1.1

iface wlan0 inet static
    address 192.168.1.3
    netmask 255.255.255.0
    #gateway 192.168.1.1  <= Either comment or remove this line

All credit to Lennart for solving this issue!

  • Stumbled across this answer via Google. This is what worked for me on an Ubuntu VM on Hyper-V – abhijit Mar 8 '17 at 13:00
8

I solved by:

sudo ifup --ignore-errors wlan0

after this command ifdown and ifup started work properly.

  • This is useful after "service networking restart" fails, thanks. :) – Adambean Apr 20 '18 at 21:46
1

steps:

1 check-> ip route (if ip route default is other than your required interface then, follow 2d & 3rd step)

2 sudo ip route del default (delete that default interface)

3 sudo ip route add default via ip_address dev interface_name (add your required interface like this)

0

In my case, I had another connection still running - once I took that interface down with ifdown eth0, the one I was interested in (wlan0) came up cleanly.

I don't recommend using the --ignore-errors option

0

I stumbled across this while messing around with VMWare vCenter. If you're in the same boat, you should have installed the VMWare Tools, perl, and net-tools with your package manager before making the Template/Snapshot of the VM.

-1

Force de/configuration

ifdown --force --verbose ethX && ifup --force --verbose ethX

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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