80

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
3
  • 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, 2017 at 7:54
  • 4
    @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, 2019 at 12:44
  • if dealing with IPV6 always add a network length: xxxx:xxxx:...::1/64 on the address
    – fcm
    Jun 14, 2019 at 11:34

8 Answers 8

82

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).

9
  • 1
    I was having this problem on an HP ProLiant server (!), and this fixed it.
    – sudo
    Aug 9, 2016 at 18:17
  • 2
    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, 2016 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, 2016 at 22:31
  • 3
    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, 2017 at 16:52
  • 2
    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, 2018 at 13:34
42

I think a solution can be found in this blog post Solving “RTNETLINK answers: File exists” when running ifup; 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!

4
  • Stumbled across this answer via Google. This is what worked for me on an Ubuntu VM on Hyper-V
    – abhijit
    Mar 8, 2017 at 13:00
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year.
    – Ingo
    Mar 4, 2020 at 11:07
  • 1
    What if I have an IPv4 gateway on one interface, and an IPv6 gateway on another? The same error is showing, but I am not sure which one I should keep.
    – Sam Sirry
    May 23, 2022 at 23:20
  • Nevermind. I forgot the interface was disconnected.
    – Sam Sirry
    May 24, 2022 at 0:15
14

I solved by:

sudo ifup --ignore-errors wlan0

after this command ifdown and ifup started work properly.

4
  • This is useful after "service networking restart" fails, thanks. :)
    – Adambean
    Apr 20, 2018 at 21:46
  • Wouldn't that cause it to ignore "genuine" errors as well?
    – komodosp
    Feb 19, 2021 at 13:21
  • Thank you so much. It worked for Ubuntu as well.
    – noname
    Aug 17, 2022 at 13:47
  • 1
    I had a vlan setup and ran this command for all my vlan interfaces which showed up in the log. restarted and it all worked well
    – Manny265
    Apr 20, 2023 at 22:19
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

Force de/configuration

ifdown --force --verbose ethX && ifup --force --verbose ethX
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.

0

We use ifdown to remove RTNETLINK and ifup again

ifdown wlan0
ifup wlan0

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