Bridged Network independent of network interface

This is for discussing general topics about how to use VirtualBox.
Post Reply
Nap
Posts: 30
Joined: 22. Jul 2014, 02:06

Bridged Network independent of network interface

Post by Nap »

My MacBook Pro has a built in WiFi, which I normally keep turned off, and thus the Wi-Fi (AirPort) device on 'en0' is not normally available to select. In liue of WiFi, I use my Thunderbolt Ethernet adapter, which shows as device 'en5'. However, if I don't have the Thunderbolt Ethernet adapter plugged in, 'en5' does not show in the device list.
The actual arrangement of hardware settings depends on where I am and what I am doing, including being connected to different LANs which use different network addresses, that sometimes force me to use WiFi.
The reason this is of concern to me it that I am not able to setup my locally hosted VM using a Bridged Adapter because sometimes it's not available and at other times the IP range is different. This makes it really troublesome when accessing my VM.

To solve this, I have tried using a series of DNS servers with complimentary A records for each of the IPs that I tend to be working with. This sometimes works ok, but at other times, non-existent DNS servers (somehow) send DNS responses indicating no such name (from WireShark):

Code: Select all

 510	99.511350	172.20.10.14	172.20.11.2	DNS	69	Standard query response 0x4c79 No such name A work.int
Note that server: '172.20.10.14', does not exist (where I am right now), and is ordered in my host's DNS settings after the server that does exist: '172.20.11.6'. I had just flushed my Mac's DNS cache before performing the lookup.

Could anyone suggest a solution that does not involve NAT and port forwarding? Links to guides would be great.
socratis
Site Moderator
Posts: 27330
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Bridged Network independent of network interface

Post by socratis »

Nap wrote:The actual arrangement of hardware settings depends on where I am and what I am doing, including being connected to different LANs which use different network addresses, that sometimes force me to use WiFi.
I don't know too much about the underlying DNS caching and propagating information, but it seems to me that DNS+ever_changing_IP, don't mix very well. That's not really how a DNS record is supposed to work, they're more for fixed IPs. That's why services like Dynamic DNS were developed (read that Wikipedia article). You may have to look into something like that.

Moving to "Using VirtualBox" because this is not tied to your "OSX Host". Actually, this is not really a VirtualBox problem at all, this is a networking problem, so I would suggest to start thinking about it as such. I'm just moving it so that a wider audience can have a look at it...
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Bridged Network independent of network interface

Post by mpack »

In the past I used to have similar problems when I moved a VM around from PC to PC. At the time I suggested to the devs that the VMs keep a list of previously available bridge targets, and bridge to whatever one was available now: in a similar way to how your PC/device remembers a list of WiFi connections, and connects to whatever one is available where you are now. Nothing came of it, perhaps too much work, or perhaps I didn't explain the idea well. Perhaps paying customers don't have the problem.
Nap
Posts: 30
Joined: 22. Jul 2014, 02:06

Re: Bridged Network independent of network interface

Post by Nap »

[VirtualBox 5.1.30 r118389 (Qt5.6.3), HOST: MacBook Pro w/ 10.13.1 (High Sierra), GUEST: Ubuntu 14.04 LTS]

Yes, the changing IP caused DNS problems. I could have managed this using a script in the VM to adjust it's IP/DNS settings according to the network environment it was in, along with some minor (though irritating) adjustments to the Mac's network settings. But would prefer a cleaner solution.

So I have moved away from using the 'bridged network' arrangement and am trying a 'host-only' network approach instead.
As an isolated network, the 'host-only' network is functioning fine, and the configuration is almost ideal. From my Mac HOST, I am able to browse the public Internet (and post this question) as well as browse my locally hosted domains on my guest VM using its DNS server. The only problems that exist are:
1) The VM takes a REALLY long time to get past the network configuration stage of the boot. I don't know why this is happening except that I'm sure it has something to do with not being able to access the Internet. Also,
2) The VM itself cannot access the Internet to get updates etc (I prefer not to setup a NAT interface for this).
(By adding a NAT adapter to the VM, these problems are both solved. However, I really want to get the bridge going as I don't think putting two NICs in each VM is really the right way of going about the issue.)

In order to overcome the second limitation (which may have a positive effect on the first once it's working), I have setup a bridge between the 'vboxnet0' and 'en5' (the wired thunderbolt ethernet adapter on the Mac) interfaces. However the bridge isn't working, and I cannot ping any host upstream of my Mac HOST.

I created the bridge using the commands below:

Code: Select all

sudo sysctl -w net.inet.ip.forwarding=1
sudo sysctl -w net.inet6.ip6.forwarding=1
sudo sysctl -w net.link.ether.inet.proxyall=1
sudo sysctl -w net.inet.ip.fw.enable=1

sudo ifconfig bridge1 destroy 2>/dev/null #if bridge1 still exists
sudo ifconfig en5 down
sudo ifconfig vboxnet0 down
sudo ifconfig bridge1 create
sudo ifconfig bridge1 addm vboxnet0 addm en5
sudo ifconfig bridge1 up
Whilst the host's IP address on 'vboxnet0' is 192.168.56.1, I have set the IP of the bridge using:
sudo ifconfig bridge1 192.168.56.14 where the .14 is outside the DHCP range assigned by 'vboxnet0'. The DHCP address range is set to 192.168.56..2 - 192.168.56..13, and I have the server itself located on 192.168.56.1. The VM's IP address on the 'vboxnet0' network is 192.168.56.2.

On the guest, I've set the default route to point to 192.168.56.14, so the route table looks like:

Code: Select all

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.56.14   0.0.0.0         UG    0      0        0 eth0
192.168.56.0    *               255.255.255.240 U     0      0        0 eth0
On the Mac, I have cleaned up the route table to the following state:

Code: Select all

Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            172.20.11.1        UGSc           46        0     en5
127.0.0.1          127.0.0.1          UH              3      441     lo0
172.20.11/28       link#5             UCS             2        0     en5
172.20.11.1        0:xx:xx:xx:b1:10   UHLWIir        15       93     en5   1026     <<== MAC address here is the mac of the router's interface
192.168.56/28      link#13            UC              3        0 vboxnet
192.168.56.1       a:0:27:0:0:0       UHLWI           0        4     lo0
192.168.56.2       8:0:27:xx:xx:ef    UHLWIi          2     1015 vboxnet   1194
192.168.56.14      172.20.11.1        UGHS            0        0     en5
255.255.255.255/32 link#5             UCS             0        0     en5

Internet6:
Destination                             Gateway                         Flags         Netif Expire
default                                 fe80::%utun0                    UGcI          utun0
::1                                     ::1                             UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en5/64                           link#5                          UCI             en5
fe80::8e6:xxxx:xxxx:xxx%en5             38:xx:xx:xx:xx:97               UHLI            lo0   <<== MAC address here is the thunderbolt
                                                                                                   ethernet's adapter mac.
fe80::%utun0/64                         fe80::528c:xxxx:xxxx:xxxx%utun0 UcI           utun0
fe80::528c:xxxx:xxxx:xxxx%utun0         link#12                         UHLI            lo0
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%en5/32                           link#5                          UmCI            en5
ff01::%en0/32                           link#6                          UmCI            en0
ff01::%utun0/32                         fe80::528c:xxxx:xxxx:xxxx%utun0 UmCI          utun0
ff02::%lo0/32                           ::1                             UmCI            lo0
ff02::%en5/32                           link#5                          UmCI            en5
ff02::%en0/32                           link#6                          UmCI            en0
ff02::%utun0/32                         fe80::528c:xxxx:xxxx:xxxx%utun0 UmCI          utun0
In /etc/resolve.conf, I have:

Code: Select all

nameserver 192.168.56.2
nameserver 172.20.10.1
Assigned through the 'Advanced' settings for the Thunderbolt adapter in 'System Preferences'.
For some reason Mac OS does not always check with the alternative nameservers, it tends to simply use the 1st one. A possible reason for this is that the DNS servers are down different paths from the host; i.e. my private DNS is connected to a local subnet on my laptop, while the normal DNS I use is my internet access point, two hops from my notebook.
Post Reply