VirtualBox supports various virtual networks: NAT, BridgeAdapter, InternalNetwork, and Host-onlyAdapter. Among them, BridgedAdapter is the most simple and commonly used. It is almost zero configuration, and can communicate with the Internet directly by bridging the wired or wireless physical network card. However, the intranets in my workplace are different from those in the home intranets. DHCP is available for a certain period of time. If you use BridgedAdapter and DHCP to obtain the IP address VirtualBox, various virtual networks are supported: NAT, Bridge Adapter, internal Network and Host-only Adapter. Among them, the Bridged Adapter is the most simple and commonly used. It is almost 0 configuration, and can communicate with the Internet directly by bridging the wired or wireless physical network card.
However, the intranets in my workplace are different from those in the home intranets. DHCP may be used for lease time. If you use the Bridged Adapter and DHCP to obtain the IP address, the virtual machine address will change frequently. To this end, I changed all the VirtualBox virtual machines on the laptop to the Host-only Adapter mode.
One problem is that the Host-only Adapter (network segment: 192.168.56.0/24) cannot communicate with the Internet by default. Google later found that someone had encountered a similar problem on the Internet. The solution they provided was to add the following to/etc/rc. local:
iptables -t nat -I POSTROUTING -s 192.168.56.0/24 -j MASQUERADE
Another problem is that the IP address lease time of VirtualBox built-in DHCP cannot be statically bound to the MAC address and IP address, which causes the Virtual Machine IP address to change once in a while and makes it inconvenient to use. On the other hand, www.linuxidc.com does not require static IP addresses, because in this case, I have to reset the IP address every time I install a virtual machine.
I have heard of dnsmasq before. It not only integrates DNS, DHCP, and TFTP functions, but also occupies a small amount of resources and is easy to set.
- Install dnsmasq
sudo apt-get install dnsmasq
- Open/etc/dnsmasq. conf and configure DHCP for vboxnet0.
Interface = vboxnet0 #192.168.56.1 is the default gateway (vboxnet0 address of the host machine) #208.67.222.222 and 208.67.220.220 are DNS addresses (www.linuxidc.com uses OpenDNS here) dhcp-option = vboxnet0, option: dns-server, 192.168.56.1, 208.67.222.222, 208.67.220.220 #192.168.56.2 and 192.168.56.254 are allocated address ranges # infinite indicates IP address never expires dhcp-range = vboxnet0, 192.168.56.2, 192.168.56.254
- Restart dnsmasq
sudo service dnsmasq restart
Of course, dnsmasq also supports static binding between MAC addresses and IP addresses. For example, for MAC address 08: 00: 27: 81: 51: 85 in/etc/dnsmasq. conf, assign the machine name vbox-xp and IP address 192.168.56.2.
dhcp-host=vbox-xp,08:00:27:81:51:85,192.168.56.2
Finally, do not forget to restart dnsmasq.