Article title: virtualbox network configuration in linux, integrating host-only and nat. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The network configuration mode of virtualbox is either host-only or bridge. for those who frequently use virtualbox, they must want nat configuration like vmware, which allows the host to access guest, allows guest to access external networks.
The installation steps are as follows:
1. establish a bridge network
Apt-get install bridge-utils
Modify/etc/network/interfaces
Add the following content:
######################################## ############
# VirtualBox NAT bridge
Auto vnet0
Iface vnet0 inet static
Address 172.16.0.1
Netmask 255.255.255.0
Bridge_ports none
Bridge_maxwait 0
Bridge_fd 1
Up iptables-t nat-I POSTROUTING-s 172.16.0.0/24-j MASQUERADE
Down iptables-t nat-d postrouting-s 172.16.0.0/24-j MASQUERADE
######################################## ############
Up Nic
Sudo ifup vnet0
2. enable ip forwarding
Modify/etc/sysctl. conf to remove comments from this line.
# Uncomment the next line to enable packet forwarding for IPv4
Net. ipv4.ip _ forward = 1
Run the following command to make it take effect
Sysctl-p
3. build a dhcp server and a dns server for the virtual machine
Apt-get install dnsmasq
Modify/etc/dnsmasq. conf
Remove the following comments
# Include a another lot of configuration options.
# Conf-file =/etc/dnsmasq. more. conf
Conf-dir =/etc/dnsmasq. d
Add a file named virtualbox under the/etc/dnsmasq. d/directory with the following content:
#######################################
Interface = vnet0
Dhcp-range = 172.16.0.2, 172.16.0.254, 1 h
Dhcp-option = option: dns-server, 172.16.0.1, 208.67.222.222, 208.67.220.220
Dhcp-option = option: domain-name, precision-m65
# Mac address, host name, assigned ip address
Dhcp-host = 08: 08: 27: 00: 00: 02, vmxp, 172.16.0.20 # Windows XP
Dhcp-host = 08: 08: 27: 00: 00: 03, vmubuntu, 172.16.0.30 # Ubuntu
#######################################
4. modify the virtualbox virtual machine configuration
A. enable virtual machine configuration
B. select a network
C. select Attached to: "Bridged Adapter"
Name: "vnet0"
Advanced-> Mac Address: 080827000002 # corresponds to the mac Address allocated to the VM by virtualbox in step 3. remove the colon.
D. The application takes effect.
Start the VM and check whether the correct address is allocated. the above configuration is passed in the ubuntu 10.04 LTS test. other releases are similar.