0

I am on a ubuntu 12.04 vm

I read https://help.ubuntu.com/12.04/serverguide/network-configuration.html

which says I can set the gateway with a command like:

sudo route add default gw 10.0.2.211 eth0

which works, but clears after a reboot.

I also tried to set the gateway by editing my /etc/network/interface file:

auto eth0 iface eth0 inet dhcp gateway 10.0.2.211 pre-up sleep 2

I just added the gateway line.

That doesn't seem to work at all though.

I tried rebooting and running:

sudo /etc/init.d/networking restart

1 Answer 1

1

Solution 1 [dirty]

sudo nano /etc/rc.local

put

ifconfig eth0 10.0.2.211 netmask 255.255.255.0 &&
route add default gateway XXX.XXX.XXX.XXX

crtl+O [write] and crtl+x [close nano]. And the end of boot process ubuntu read and execute rc.local

Solution 2 [clear]

sudo nano /etc/network/interfaces

auto eth0
iface eth0 inet static
address XXX.XXX.XXX.XXX
netmask XXX.XXX.XXX.XXX
gateway XXX.XXX.XXX.XXX

crtl+O [write] and crtl+x [close nano].

Your ip and gw can not be same ip address. If you wish to set only gateway after dhcp, put only this in rc.local

sudo nano /etc/rc.local

route add default gateway XXX.XXX.XXX.XXX

crtl+O [write] and crtl+x [close nano]

2
  • Ahh.. So is the reason the /etc/network/interfaces isn't setting the gateway because I am using dhcp and not static?
    – JD Isaacks
    Mar 14, 2014 at 19:49
  • 1
    Yes. Dhcp commpletly configure nic card.
    – 2707974
    Mar 14, 2014 at 20:31

You must log in to answer this question.

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