"RTNETLINK answers: File exists" /etc/network/interfaces Does'nt contain 2 gateways, so what's wrong?
Solution 1:
Edit your configuration file to remove the spaces before the iface
stanza so that it looks like this,
auto eth0
iface eth0 inet static
address 192.168.1.57
netmask 255.255.255.0
gateway 192.168.1.1
up ip addr add 192.168.0.57/24 dev eth0 label eth0:1
down ip addr del 192.168.0.57/24 dev eth0 label eth0:1
up ip route add 192.168.0.0/24 via 192.168.0.1 dev eth0:1 metric 20
down ip route del 192.168.0.0/24 via 192.168.0.1 dev eth0:1 metric 20
The message you receive is just indication that the interface is already up, so you need to do ifdown
before you do ifup
. However, you need to be careful if you are connecting via ssh - you may lock yourself out. This is a way to do it:
sudo ifdown eth0 && sudo ifup eth0
Note, how these two commands are executed on the same line. And just a precaution, make sure you can get access to the server console or reboot the server if something goes wrong.
Solution 2:
I just ran into this problem and none of the solutions above worked for me. I couldn't change /run/network/ifstate
because it was reset immediately to the former state. Also sudo ifdown eth0 && sudo ifup eth0
didn't work.
I then found out the following command:
sudo ip addr flush dev eth0
which solved the problem.