Here is the abridged version of my question: Why does setting the gateway parameter in my network interfaces file have no effect on my network interfaces?
Or alternatively, why does the post-up command work where gateway fails and what exactly is setting the gateway parameter supposed to do?
Here is a longer description of my question.
Consider the following network-interface configuration file (/etc/network/interfaces) on a VirtualBox VM running Debian:
# /etc/network/interfaces
# Original file
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface (NAT)
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
# Host-only interface (vboxnet0)
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 192.168.56.2
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255
gateway 192.168.56.1
When I boot the machine and run route -n I get the following output:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
To my surprise, there is no gateway set for the 192.168.56.0/24 network on the eth1 interface.
Now consider the following alternative configuration file:
# /etc/network/interfaces
# Modified file
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface (NAT)
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
# Host-only interface (vboxnet0)
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 192.168.56.2
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255
# gateway 192.168.56.1
post-up route add default gw 192.168.56.1
pre-down route del default gw 192.168.56.1
When I reboot the machine with this configuration and run route -n I get the following output instead:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.56.1 0.0.0.0 UG 0 0 0 eth1
0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
So the upshot is that the post-up/pre-down approach to setting a default gateway works, but using the gateway parameter itself does not. What am I missing here?