Ubuntu Network Configuration

Just a little cheat sheet for setting up multiple routes/interfaces on ubuntu servers. The file you’ll be making modifications to is “/etc/network/interfaces”.

Assuming you have 2 NICs and you are wanting 1 public and 1 private, this is pretty simple. In this example I’ll assume that your public IP is 1.2.3.4/24 with a normal gateway, and your private is 10.1.1.2/24 :
auto eth0
iface eth0 inet static
address 1.2.3.4
netmask 255.255.255.0
gateway 1.2.3.1

auto eth1
iface eth1 inet static
address 10.1.1.2
netmask 255.255.255.0

That’ll basically send all your traffic that doesn’t belong to the private subnet out your public gateway.

But what if you need to have the private as your primary interface? Or what if you have multiple subnets you need to route for on the private side? I’ll assume the same IPs from above, but also that you have 10.2.2.0/16 that you need to access. Check this one out :
auto eth0
iface eth0 inet static
address 1.2.3.4
netmask 255.255.255.0

auto eth1
iface eth1 inet static
address 10.1.1.2
netmask 255.255.255.0

up route add -net 0.0.0.0/0 gw 1.2.3.1 dev eth0
up route add -net 10.2.2.0/16 gw 10.1.1.1 dev eth1

Ubuntu Network Configuration

Leave a Reply