3

I have a private network interface, as follows, on a Ubuntu 16.04 VM:

# Private network
auto ens19
iface ens19 inet static
    address 10.10.10.179
    netmask 255.255.255.0
    mtu 1450

My vLAN requires a gateway to be specified in order for it to work, so I append it as follows:

# Private network
auto ens19
iface ens19 inet static
    address 10.10.10.179
    netmask 255.255.255.0
    mtu 1450
    gateway 10.10.10.1

However, whenever I add that gateway and restart the networking service, it won't start with the following error:

Dec 15 10:50:08 postfix0 ifup[1968]: RTNETLINK answers: File exists
Dec 15 10:50:08 postfix0 ifup[1968]: Failed to bring up ens19.

Executing ip addr flush dev xxx does not help.

So, how do I fix this?

William
  • 584
  • 2
  • 9
  • 27

1 Answers1

1

Create a named routing table. The name, pvtnet, is arbitrary. This will not work if DHCP is handing out addresses on the 10.10.10 network.

echo '200 pvtnet' >> /etc/iproute2/rt_tables

Modify the file, /etc/network/interfaces.

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
# DHCP hands out the DEFAULT gateway.
auto eth0 # use the real device name on your system
allow-hotplug eth0
iface eth0 inet dhcp

# The private network interface
auto ens19
allow-hotplug ens19
iface ens19 inet static
address 10.10.10.179
netmask 255.255.255.0
mtu 1450
post-up ip route add 10.10.10.0/24 dev ens19 src 10.10.10.179 table pvtnet
post-up ip route add default via 10.10.10.1 dev ens19 table pvtnet
post-up ip rule add from 10.10.10.179/32 table pvtnet
post-up ip rule add to 10.10.10.179/32 table pvtnet
Christopher
  • 15,611
  • 7
  • 51
  • 64
  • That did the trick. Thank you! I tried many variations of that. Will award bounty in 23 hours when allowed. – William Dec 19 '17 at 20:22