12 | | I imagine running Windows apps is what 90% of VirtualBox users use it for, but it can do so much more than that. I also run several Linux-based VMs, and use them to test server configs, or even whole networks before rolling out the real thing. If you do this, you probably want to use more than the basic NAT networking that VirtualBox uses by default. For instance, wouldn’t it be nice to install an SSH server in the VM, minimise the VirtualBox GUI, and SSH in from a terminal just like you would a real server? |
13 | | |
14 | | I assume you are using VirtualBox 2.1.4 from a Linux host running Ubuntu 8.04 “Hardy Heron”. Similar commands can be used on any recent Debian or Ubuntu release. You’ll have to adapt some things to use it on RPM- or source-based Linux distributions. Assume all commands are run as root (directly or with sudo). |
15 | | |
16 | | Update 2010-08-18: These instructions are still valid as of VirtualBox 3.2.8 and Ubuntu 10.04 “Lucid Lynx”. VirtualBox now creates a “vboxnet0″ interface by default, but this is not a bridge. Follow the instructions below. |
17 | | |
18 | | === Step 1: Create a bridge interface === |
19 | | |
20 | | First, we have to create a bridge interface for the VMs. Install the bridge utilities: |
21 | | apt-get install bridge-utils |
22 | | |
23 | | Now make the bridge start on boot. Add the following to /etc/network/interfaces: |
| 11 | Hay que asegurarse de que los módulos: ''vboxdrv, vboxnetflt y vboxnetadp'' se encuentren cargados. Añádelos a ''/etc/modules'' (o ''/etc/rc.conf'' para !ArchLinux) para asegurar que lo estén en cada arranque: |
49 | | Now you must tell the kernel to route traffic. Find the ‘net.ipv4.ip_forward’ line in /etc/sysctl.conf, and uncomment it: |
| 39 | {{{ |
| 40 | interface=vnet0 |
| 41 | dhcp-range=172.16.0.2,172.16.0.254,1h |
| 42 | dhcp-option=option:router,172.16.0.1 |
| 43 | dhcp-option=option:dns-server,80.58.0.33,80.58.32.97 |
| 44 | dhcp-option=option:domain-name,example.com |
| 45 | |
| 46 | dhcp-host=aa:bb:cc:dd:ee:02,172.16.0.2 |
| 47 | dhcp-host=aa:bb:cc:dd:ee:03,172.16.0.3 |
| 48 | }}} |
| 49 | |
| 50 | Que no se nos olvide reiniciar este servicio después de aplicar los cambios. |
| 51 | |
| 52 | == Configuración de maquinas virtuales == |
| 53 | |
| 54 | Accedemos a la configuración de una maquina virtual que haya sido creada dándole al botón ''Settings'' después de seleccionarla estando apagada. Le damos a la opción ''System''. Habilitamos la opción ''Network'' dentro de la opción ''Boot order'' y la ponemos en primer lugar. Luego nos vamos a la opción ''Network'' y ponemos a ''Attached to:'' a ''Host-only'' y la interfaz a la que creamos anteriormente, probablemente ''vboxnet0''. También podemos aprovechar para cambiar la MAC y usar alguna que hayamos configurado como IP fija en dnsmasq. |
| 55 | |
| 56 | Con esto es suficiente para que las máquinas virtuales arranquen por red. Si queremos además que tengan internet hay que seguir el siguiente paso. |
| 57 | |
| 58 | == Configuración para ofrecer internet == |
| 59 | |
| 60 | En el fichero /etc/sysctl.conf buscamos la línea ‘net.ipv4.ip_forward’ y la descomentamos para que quede así: |
70 | | And edit /etc/dnsmasq.conf to include: |
71 | | |
72 | | {{{ |
73 | | interface=vnet0 |
74 | | dhcp-range=172.16.0.2,172.16.0.254,1h |
75 | | }}} |
76 | | |
77 | | That’s all you really need, but you may want to explicitly define DNS servers and domains for the guests, or static assignments. Add: |
78 | | |
79 | | {{{ |
80 | | dhcp-option=option:dns-server,172.16.0.1,208.67.222.222,208.67.220.220 |
81 | | dhcp-option=option:domain-name,example.com |
82 | | dhcp-host=08:00:27:00:00:02,vmxp,172.16.0.2 # Windows XP |
83 | | dhcp-host=08:00:27:00:00:03,vmubuntu,172.16.0.3 # Ubuntu |
84 | | }}} |
85 | | |
86 | | This defines the host OS and the OpenDNS servers as the DNS servers (instead of passing on whatever your host OS uses), tells all guests they are part of the domain example.com, and defines two static assignments by MAC address. |
87 | | |
88 | | === Step 4: Set up the virtual machine === |
89 | | |
90 | | Start the VirtualBox interface, and edit your virtual machine’s settings. |
91 | | 1. Choose “Network”. |
92 | | 1. Enable a network adaptor. |
93 | | 1. Under “Attached to:”, select “Host Interface”. |
94 | | 1. If you assigned a static DHCP assignment above, be sure to set the same MAC address. |
95 | | 1. Under “Host Interfaces”, select the bridge you created in step 1, vnet0. |
96 | | |
97 | | Example: |
98 | | |
99 | | (TODO Add image) |
100 | | Your virtual machines will now automatically receive an IP address in the 172.16.0.0/24 network, will resolve DNS, will NAT to your host’s external IP address, and can directly address each other. |
| 79 | Si se quiere que se ejecute al inicio en cada arranque se deberá configurar manualmente según la distribución. |