I am trying to setup a gateway server in my cloud network so all my servers(some who do not have an external IP) can access the internet via this gateway server.
To achieve this, my first task is to configure the network interfaces on my servers manually and set the gateway property.
So this first server I am trying to configure is a ubuntu 16.04 web server that has both a public and a private network interface. I went ahead and updated /etc/network/interfaces as follows:
auto lo
iface lo inet loopback
# public interface - to be used only for inbound access
auto eth0
iface eth0 inet static
address 94.237.40.154
netmask 255.255.252.0
# internal interface - this is where it will get internet
auto eth1
iface eth1 inet static
address 10.5.0.155
netmask 255.255.252.0
gateway 10.5.2.135 # my gateway server
dns-nameservers 8.8.8.8
# unused interface - this was there from before
auto eth2
iface eth2 inet6 auto
So as soon as I save this and reboot the server, any inbound connection to the server on the external IP stops working. Currently I have port 80 and port 22 open on this server and both these just stop working.
I got to the server using a cloud console, and it manages to get internet access perfectly fine via my gateway server (tried doing traceroute and all works well). Both my interfaces are up and show the correct ip config on "ifconfig". But no inbound access at all. If I revert my settings to use DHCP again, all works fine.
I have had this issue in the past on a local server as well but never managed to figure out what I'm missing. Help appreciated.
EDIT: One more observation. If I set a default gateway on eth0 and remove the one from eth1 then inbound access starts working.