8.2. Bridged networking con libvirt
Il Bridged networking (conosciuto anche come condivisione del dispositivo fisico) è usato per rendere disponibile un dispositivo fisico ad una macchina virtuale. Il Bridging viene spesso usato per impostazioni più avanzate e su server con interfacce di rete multiple.
Se il sistema utilizza un bridge Xen è consigliato disabilitare il bridge di rete Xen predefinito modificando /etc/xen/xend-config.sxp
ed in particolare la riga:
(network-script network-bridge)
In:
(network-script /bin/true)
NetworkManager non supporta il bridging. A tal proposito è necessario disabilitare il NetworkManager per poter usare il vecchio networking per gli script di rete.
# chkconfig NetworkManager off
# chkconfig network on
# service NetworkManager stop
# service network start
Note
A tale scopo sarà possibile aggiungere NM_CONTROLLED=no
" agli script ifcfg-*
usati negli esempi.
Creare o modificare i seguenti file di configurazione di rete. Questa fase può essere ripetuta (con nomi diversi) per bridge di rete aggiuntivi.
Andare nella cartella /etc/sysconfig/network-scripts
:
# cd /etc/sysconfig/network-scripts
Aprire lo script di rete per il dispositivo che si sta aggiungendo al bridge. In questo esempio ifcfg-eth0
definisce l'interfaccia di rete fisica impostata come parte di un bridge:
DEVICE=eth0
# change the hardware address to match the hardware address your NIC uses
HWADDR=00:16:76:D6:C9:45
ONBOOT=yes
BRIDGE=br0
Suggerimento
È possibile configurare il Maximum Transfer Unit (MTU) del dispositivo aggiungendo una variabile MTU
alla fine del file di configurazione.
MTU=9000
Creare un nuovo script di rete nella cartella /etc/sysconfig/network-scripts
chiamato ifcfg-br0
o simile. br0
è il nome del bridge, può essere qualsiasi cosa se il nome del file è uguale al parametro del DISPOSITIVO.
DEVICE=br0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes
DELAY=0
Warning
The line, TYPE=Bridge
, is case-sensitive. It must have uppercase 'B' and lower case 'ridge'.
Dopo la configurazione riavviare il networking oppure eseguire un riavvio.
# service network restart
Configure iptables
to allow all traffic to be forwarded across the bridge.
# iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
# service iptables save
# service iptables restart
Disable iptables on bridges
Alternatively, prevent bridged traffic from being processed by iptables
rules. In /etc/sysctl.conf
append the following lines:
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
Reload the kernel parameters configured with sysctl
# sysctl -p /etc/sysctl.conf
Restart the libvirt
daemon.
# service libvirtd reload
Ora si dovrebbe avere un "dispositivo fisico condiviso" al quale è possibile collegare i guest ed avere un accesso LAN completo. Verificare il nuovo bridge:
# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.000000000000 yes
br0 8000.000e0cb30550 no eth0
Da notare che il bridge è completamente indipendente dal bridge virbr0
. È consigliato non collegare un dispositivo fisico a virbr0
. Il bridge virbr0
è solo per la connettività Network Address Translation (NAT).