Score:2

Gateway not being set on startup of VM

io flag

I'm running ubuntu server (20.04.2) as a VM (VirtualBox) as a network server (media, pihole etc). The network adapter is set as bridged. My modem is giving it the correct IP on startup as per my DHCP settings, but the gateway isn't being set correctly.

On a clean boot the gateway, viewed by route -n, is set as 10.0.2.15. The VM is unable to connect to the internet with this, and devices using my PiHole will fail as the DNS requests upstream don't work (unless cached).

Manually setting the gateway (using ip route add default via 192.168.0.1) resolves the issue.

If the VM has to reboot, the setup is lost and outside of creating a startup script to fix it, how can I resolve it?

Thanks

CrazyTux avatar
us flag
what is the ip of your host computer? have you tried to set the VM network as NAT and get the internet from you host ?
Terrance avatar
id flag
If you want the IP address of the VM to be on the same network as the host OS, set the network to Bridged Adapter instead of NAT.
Score:0
pl flag

Since you are standing up a server, I am assuming you are using a static IP. Ubuntu 20.04 uses netplan by default to manage your network settings. Your network adapters default gateway should be specified in its respective config file, located in /etc/netplan/ (having a name like this: /etc/netplan/01-netcfg.yaml) You should check that file and make sure the gateway you want is specified correctly, and if not, replace it with the correct one. Make sure to take a back up before editing. Afterwards, you can run "sudo netplan apply" to apply the changes. This will be persistent through reboots.

This article, while primarily for configuring a static IP, has good information on netplan and the file you are looking for: https://linuxize.com/post/how-to-configure-static-ip-address-on-ubuntu-20-04/

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.