0

I have 2 EC2 instances that run Ubuntu (VM1: 172.0.1.11 and VM2: 172.2.1.12).

I want to make a default Gateway to my Routers R1which its addresses are the following respectively 172.0.1.8and 172.2.1.13.

In VM1: I did sudo ip route add default via 172.0.1.8. On the other side, in VM2: sudo ip route add default via 172.2.1.13. Both routes are working.

However, when I reboot the instances, I lose that default route.

Is there any way to permanently save the default route?

I tried in both sides the following code modifying /ect/network/interfaces?

auto eth0
iface eth0 inet static
address 172.2.1.10 (172.0.1.11 VM1)
netmask 255.255.255.240
up route add -net 172.2.0.0 (172.0.0.0) netmask 255.255.0.0 gw 172.2.1.13 (172.0.1.8)
Tim Luka
  • 137
  • 1
  • 8

3 Answers3

0

You can try this,

on VM1

auto eth0
iface eth0 inet static
...
up route add default via 172.0.1.8 dev eth0

on VM2

auto eth0
iface eth0 inet static
...
up route add default via 172.2.1.13 dev eth0
0

You should add in file /etc/network/interfaces line like this:

gateway 172.0.1.8

(for VM1) and

gateway 172.0.1.13

for VM2 And then restart the network or reboot the VMs

Romeo Ninov
  • 3,195
  • 2
  • 13
  • 16
0

Your /etc/network/interfaces file should looks like below after adding route.

auto eth0
iface eth0 inet static
      address <IP>
      netmask 255.255.255.0
      up route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1

After that

ifdown eth0
ifup eth0

Or restart your vm.

asktyagi
  • 2,401
  • 1
  • 5
  • 19