How to Fix “rtnetlink answers: file exists”?

In Linux, there are possible ways to make a connection in a network, either using some ports like ethernet or the computer’s wireless card. While using the “ifup” or “ifdown” commands to configure a specific network interface, users have to face the error “rtnetlink answers: file exists”, which occurs due to the duplicate gateway or the duplicate connection name. . 

This article will provide the possible reasons for this error mentioned above along with the solutions. 

Reason 1: Duplicate Gateway Exists

The gateway is the node that establishes the connection between two different protocols with the help of some protocols. When we talk about the network during connectivity, there is already a gateway assigned, and we try to connect with another gateway. They cause confusion for the network and generate the error “rtnetlink answers: file exits”. 

Solution: Delete Duplicate Gateway

One of the most suitable solutions is that list down the contents of the “/etc/netplan” to find the name of the networking files to configure the Network Manager:

$ ls /etc/netplan/

In our case, it is named “01-network-manager-all.yaml”, it can be different in your case. After finding the file’s name, open it with some text editor:

$ sudo nano /etc/netplan/01-network-manager-all.yaml

In this file, if users find two gateways, then delete any one of them or comment it with “#”. 

Reason 2: Connection With the Same Name Already Exists

This error is also invoked if the connection with the same name already exists. This can be resolved either by flushing the duplicate entry or ignoring the errors. The solutions are demonstrated below:

Solution 1: Flush the Duplicate Entry

Users must delete the previous one before making a new connection. For instance, flush the old connection by following the below-mentioned syntax:

$ sudo ip addr flush dev {networkDeviceNameHere}

Solution 2: Ignore the Error

This can also be fixed by using the “–ignore-error” option of the “ifup” command as shown below: 

$ sudo ifup --ignore-errors <Network-Interface>

Conclusion

To fix the “rtnetlink answers: file exists”, remove the duplicate gateway by commenting it from the network file or flush the connection. In this blog, both solutions are explained against the reasons for the duplicate connections. This blog will help you resolve the error of the “rtnetlink answers: file exists.