linux无线网络下安装xen
这些天玩了一下hypervm,xen,openvz的环境,觉得hypervm还是不错的,希望开源能有一个好的前景。
因为家里的网络是无线的,弄xen的虚拟机稍微费了些周折。 直接的bridge方式无线Xen VM不能访问internet, 换了dummy network及nat方式倒是可以。
Dummy network
One simple solution is to have the xen ethernet bridge completely internal to the system, and leave the outside network interfaces (both wired and wireless) free to change with whatever environment you attach them to. Simply attaching the xen ethernet bridge to a dummy network interface inside domain zero will do the trick.
Add these lines to /etc/modprobe.conf:
alias dummy0 dummy options dummy numdummies=1
To configure your dummy network (with Red Hat style initscripts), create /etc/sysconfig/network-scripts/ifcfg-dummy0:
# Dummy interface for Xen DEVICE=dummy0 BOOTPROTO=none ONBOOT=yes USERCTL=no IPV6INIT=no PEERDNS=yes TYPE=Ethernet NETMASK=255.255.255.0 IPADDR=10.1.1.1 ARP=yes
In order to actually bind the xenbr0 ethernet bridge to dummy0, edit the network-script line in /etc/xen/xend-config.sxp:
(network-script 'network-bridge bridge=xenbr0 netdev=dummy0')
NAT
In order to make packet forwarding and Network Address Translation (NAT) work, you can add commands like the following to your firewall startup script, or simply to rc.local:
/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE /sbin/iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
You can enable packet forwarding in /etc/sysctl.conf:
# Controls IP packet forwarding net.ipv4.ip_forward = 1 net.ipv6.conf.default.forwarding = 1
NetworkManager
NetworkManager can deal with random new network hardware (eg. wifi network cards or USB sticks) being plugged into the system, but this does add the complexity of unpredictable network interface names. Luckily the NetworkManagerDispatcher daemon will call any script in the /etc/NetworkManager/dispatcher.d every time an interface is brought up or taken down.
The following script (lets call it /etc/NetworkManager/dispatcher.d/xenNAT) should work.
#!/bin/sh # /etc/NetworkManager/dispatcher.d/xenNAT # # Bring up iptables NAT for our Xen guests if a new network interface is brought up. # # The script is invoked by NetworkManagerDispatcher, like this: # xenNat <interface> <up/down> INTERFACE=$1 UPDOWN=$2 if [ $UPDOWN = 'up' ] ; then /sbin/iptables -t nat -A POSTROUTING -o $INTERFACE -j MASQUERADE else /sbin/iptables -t nat -D POSTROUTING -o $INTERFACE -j MASQUERADE fi
Note that this script is untested because the author has no system with Xen and wifi networking. If you have verified that the script works, or have improvements, please edit this page.
Inside the guest
Since we do not have dhcp set up yet on our dummy network, for now it is easiest to simply configure your Xen guests with static IP addresses on the same subnet as your domain 0 dummy0 interface (10.1.1.0/24). You can edit the /etc/sysconfig/networking inside the guest to look like this:
NETWORKING=yes HOSTNAME=localhost.localdomain GATEWAY=10.1.1.1 IPADDR=10.1.1.10 NETMASK=255.255.255.0
相关文章:
