Ubuntu11.10VirtualBox's Host-only network adapter's Internet and DHCP

Source: Internet
Author: User
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.
  1. Install dnsmasq
    sudo apt-get install dnsmasq
  2. 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
  3. 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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.