Linux Networking Error: “RTNETLINK answers: File exists” When Applying Static IP Configuration Without Dual Gateways


2 views

When working with Linux network configurations, particularly in Debian-based systems, the /etc/network/interfaces file is crucial for static IP setups. The current configuration shows a single gateway but attempts to add secondary routing:

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 "File exists" message from RTNETLINK indicates the kernel already has the network configuration you're trying to add. This commonly occurs when:

  • Network interface is already up with conflicting settings
  • Routes or IP addresses already exist in the routing table
  • Previous configuration wasn't properly cleaned up

Instead of just running ifup, you should follow this sequence:

sudo ifdown eth0
sudo ip addr flush dev eth0
sudo ip route flush dev eth0
sudo ifup eth0

For systems using NetworkManager, try these commands first:

sudo nmcli connection reload
sudo nmcli connection down "Wired connection 1"
sudo nmcli connection up "Wired connection 1"

Verify your current configuration before applying changes:

ip addr show eth0
ip route show
ip link show eth0

To check for conflicting configurations:

ip addr | grep 192.168.0.57
ip route | grep 192.168.0.0/24

For production systems, consider modifying the configuration to prevent conflicts:

auto eth0
iface eth0 inet static
    address 192.168.1.57/24
    gateway 192.168.1.1

auto eth0:1
iface eth0:1 inet static
    address 192.168.0.57/24
    post-up ip route add 192.168.0.0/24 via 192.168.0.1 metric 20
    pre-down ip route del 192.168.0.0/24 via 192.168.0.1

The error message "RTNETLINK answers: File exists" typically occurs when you try to add a network configuration that already exists in the kernel's routing table. In your case, this happens when executing sudo ifup eth0 after modifying /etc/network/interfaces.

During system reboot, all existing network configurations are cleared before applying new ones from /etc/network/interfaces. When trying to apply changes manually, the existing routes conflict with the new ones you're trying to add.

Here's the correct sequence to apply your network configuration changes:

# First bring down the interface
sudo ifdown eth0

# Clear any remaining routes (important step)
sudo ip route flush dev eth0
sudo ip route flush dev eth0:1

# Then bring it back up
sudo ifup eth0

If you're using NetworkManager (common in modern distributions), you might need to disable it for manual interface control:

# Stop NetworkManager
sudo service network-manager stop

# Mark the interface as unmanaged
echo -e "[keyfile]\nunmanaged-devices=interface-name:eth0" | sudo tee /etc/NetworkManager/conf.d/99-unmanaged.conf

# Restart NetworkManager
sudo service network-manager start

To verify your current routing configuration and identify conflicts:

# Show all routes
ip route show

# Show interface-specific routes
ip route show dev eth0
ip route show dev eth0:1

# Show existing IP addresses
ip addr show eth0

Here's a more robust version of your configuration that handles edge cases better:

auto eth0
iface eth0 inet static
    address 192.168.1.57
    netmask 255.255.255.0
    gateway 192.168.1.1
    post-up ip addr add 192.168.0.57/24 dev eth0 label eth0:1 || true
    post-down ip addr del 192.168.0.57/24 dev eth0 label eth0:1 || true
    post-up ip route add 192.168.0.0/24 via 192.168.0.1 dev eth0:1 metric 20 2>/dev/null || true
    post-down ip route del 192.168.0.0/24 via 192.168.0.1 dev eth0:1 metric 20 2>/dev/null || true

For modern systems using systemd-networkd, consider this alternative configuration:

# /etc/systemd/network/10-eth0.network
[Match]
Name=eth0

[Network]
Address=192.168.1.57/24
Gateway=192.168.1.1

[Route]
Destination=192.168.0.0/24
Gateway=192.168.0.1
Metric=20