Creazione di un'interfaccia virtuale NAT & Host per VirtualBox
Si vuole creare un'interfaccia che permetta di creare una rete con
- delle VM che si vedano tra loro
- delle VM che accedano ad internet
- della VM accessibili dal PC
In pratica una rete Host Only + Nat
- Installare i pacchetti necessari:
sudo aptitude install uml-utilities
- Configurare l'interfaccia:
sudoedit /etc/network/interfaces
... auto tun254 iface tun254 inet static address 10.11.12.254 netmask 255.255.255.0 pre-up tunctl -t tun254 pre-up iptables -t nat -A POSTROUTING -o wlan0 -s 10.11.12.0/24 -j MASQUERADE pre-up iptables -t nat -A POSTROUTING -o eth0 -s 10.11.12.0/24 -j MASQUERADE post-down iptables -t nat -D POSTROUTING -o wlan0 -s 10.11.12.0/24 -j MASQUERADE post-down iptables -t nat -D POSTROUTING -o eth0 -s 10.11.12.0/24 -j MASQUERADE post-down tunctl -d tun254
- Attivarla
sudo invoke-rc.d networking restart
- Verificare che esista:
ifconfig tun254
tun254 Link encap:Ethernet HWaddr f6:1d:3a:4b:7f:d2
inet addr:10.11.12.254 Bcast:10.11.12.255 Mask:255.255.255.0
inet6 addr: fe80::f41d:3aff:fe4b:7fd2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:213 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
- Verificare che il nat in uscita sia attivato:
sudo iptables -L -n -v -t nat
Chain PREROUTING (policy ACCEPT 198 packets, 20066 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 4426 packets, 394K bytes)
pkts bytes target prot opt in out source destination
1 84 MASQUERADE all -- * wlan0 10.11.12.0/24 0.0.0.0/0
1 84 MASQUERADE all -- * eth0 10.11.12.0/24 0.0.0.0/0
Chain OUTPUT (policy ACCEPT 4426 packets, 394K bytes)
pkts bytes target prot opt in out source destination
- Installare e configurare un server DHCP (dhcpd3-server o dnsmasq)
- Configurare le VM come Bridged sull'interfaccia tun254. In questo modo si uscirà sempre su internet tra una delle due interfacce nattate.