Monday 19 January 2015

VirtualBox guest with Host Only and Bridged network interfaces

My CentOS guest has interfaces
- 192.168.100.102 - host-only adapter
- 192.168.0.105 - bridged adapter

If I run ifconfig on my Mac (which is running the hypervisor) I see it has the same subnet (192.168.0.0) as the guests bridged adapter. The host only adapter appears to be represented by a new interface in the listing called vboxnet0 with an ipaddress of 192.168.100.100. This means the Mac is directly connected to both subnets and therefore doesn't need to route.

The guest should be able to route to internet (if available) via bridged adapter so therefore the default gateway should be the same as the one the Mac uses, i.e when I'm at home this is the wireless router and when I'm mobile it's my phones hotspot router. These are on different subnets and my guest interface is hard coded for a class C 192.168.0.0 network, this is OK for my home but my phones hotspot has a network address of 192.168.43.0.  To work around this I've been changing the eth0 interface IP Address in /etc/sysconfig/network-scripts/ifcfg-eth0. I probably need to add another interface so that I'll have three in total (1 for host only and two bridged, 1 for the mobile subnet (192.168.43.0) and another for home wireless subnet 192.168.0.0).  Not sure how to configure the routing table to contain both but I'll work that out. Alternatively I could just configure the home wireless router to be on subnet 192.168.43.0 but that wouldn't be as interesting.

To add a default router manually (not sure how to make this permanent as /etc/defaultgateway doesn't seem to be working) I run.
route add default gw 192.168.0.1 eth0

I would normally use netstat -r to look at the routing table but it takes ages to display the last entry (the one I'm interested in) for some reason. I've found that ip route list is faster.

Setting the DNS Server is just a case if updating /etc/resolve.conf.

No comments:

Post a Comment