0

I run a Ubuntu server in VirtualBox with 3 network interfaces. How can I make sure the default gateway is always the on from eth0.

eth0 -> NAT, DHCP
eth1 -> bridged, DHCP
eth2 -> host only adapter, static ip

I know how to do it manually...

$ sudo route del default
$ sudo route add default gw 10.0.2.2

/etc/network/interfaces

auto lo
iface lo inet loopback

# The NAT network interface
auto eth0
iface eth0 inet dhcp

# The bridged network interface
auto eth1
iface eth1 inet dhcp

# The host-only network interface
auto eth2
iface eth2 inet static
address 192.168.56.2
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255

Thanks, Stefan

1
  • 1
    You really do not need the network and broadcast in a static setup. That will be calculated by the OS. So adding them only makes it possible that you get it wrong, and then your net will not work.
    – Anders
    Mar 22, 2016 at 2:15

1 Answer 1

0

Problem appears when eth1 go up, because also from dhcp got default gw param. You can add in /etc/network/if-up.d/ some script to returns default gw to eth0

Example:

sudo nano /etc/network/if-up.d/script

and put content

# Check for specific interface if desired
[ "$IFACE" != "eth1" ] || exit 0
# Return default interface and gw
route add default dev eth0

give script privilege

chmod 755 /etc/ppp/if-up.d/script

if-up.d will trigger script called script when eth1 go up and return default gw to eth0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .