2009年12月14日 星期一

uml的網路設定

host端 (ip設定為10.222.222.254/24)
在/etc/network/interface中設定一個新的tap裝置

auto tap0
iface tap0 inet static
address 10.222.222.254
netmask 255.255.255.0
tunctl_user uml-net
up /etc/network/uml.sh
down /etc/network/uml.sh
uml.sh內容
#!/bin/sh
case $MODE in
start)
iptables -t nat -A POSTROUTING -s $IF_ADDRESS/$IF_NETMASK -j MASQUERADE
;;
stop)
iptables -t nat -D POSTROUTING -s $IF_ADDRESS/$IF_NETMASK -j MASQUERADE
;;
esac
使用sysctl開啟ip forwarding
echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/99-uml.conf
修改/etc/default/uml_utilities以符合設定
# Options to pass to uml_switch.

# set to "false" if you want to prevent uml_switch from
# starting with SysV scripts in /etc/init.d
# UML_SWITCH_START="false"

# For preconfigured tap setup, see
# /usr/share/doc/uml-utilities/examples/interfaces.example
UML_SWITCH_OPTIONS="-tap tap0"

# User as which to run uml_switch
UML_SWITCH_USER="uml-net"

# Socket file to use
# Debian's default is:
#UML_SWITCH_CTL="/var/run/uml-utilities/uml_switch.ctl"
#
# if you instead use your rolled up kernel from upstream
# sources you may want to uncomment the following:
UML_SWITCH_CTL="/tmp/uml.ctl"

uml client端依正常方式設定,gateway設成host端ip就好

執行

./linux ubd0=root_fs mem=512M eth0=daemon