Solving “RTNETLINK answers: File exists” when running ifup
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.
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
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 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.
If the solution provided by @theoB610 still doesn't work, then you might have to flush the
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).
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.
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.
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.
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.
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