配置
打开 Xen 的配置文件,注释掉 (network-script network-bridge) 一行,然后加上下面一行:
# vi /etc/xen/xend-config.sxp
#(network-script network-bridge)
(network-script network-multi-bridge)
然后创建一个 network-multi-bridge 脚本,用来2次执行 network-bridge 脚本:
# vi /etc/xen/scripts/network-multi-bridge
#!/bin/sh
dir=$(dirname "$0")
"$dir/network-bridge" "$@" vifnum=0 bridge=xenbr0 netdev=eth0
"$dir/network-bridge" "$@" vifnum=1 bridge=xenbr1 netdev=eth1
重启 Xen 服务使配置生效:
# /etc/init.d/xend restart
打开 Xen 虚拟机的配置文件,加入一个虚拟网卡:
# vi /etc/xen/vpsee
vif = [ "mac=00:16:3E:58:FF:AB,bridge=xenbr0",
"mac=00:16:3E:58:FF:AD,bridge=xenbr1" ]
重启虚拟机后,查看网络适配器的配置就会发现多了一个 eth1:
# /sbin/ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:16:3E:58:FF:AB
inet addr:172.16.38.200 Bcast:172.16.39.255 Mask:255.255.254.0
inet6 addr: fe80::216:3eff:fe58:ffab/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:801 errors:0 dropped:0 overruns:0 frame:0
TX packets:209 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:93950 (91.7 KiB) TX bytes:42427 (41.4 KiB)
eth1 Link encap:Ethernet HWaddr 00:16:3E:58:FF:AD
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
给 eth1 配置 IP 地址、掩码、网关等:
# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
TYPE=Ethernet
IPADDR=192.168.10.200
GATEWAY=
NETMASK=255.255.255.0
配置好虚拟机的网卡后启动网卡:
# /etc/sysconfig/network-scripts/ifup eth1
这样就给运行在一台物理机器上的 Xen 虚拟机增加了一个新网卡,并连接到了物理服务器所在的新网络,虚拟机上的2个网卡和物理服务器上的2个网卡一一对应。
配置路由表
如果想在服务器上同时访问2个网络和其子网络的话,需要修改默认网关和配置路由表:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
IPADDR=172.16.39.200
GATEWAY=172.16.38.1
NETMASK=255.255.254.0
# vi /etc/sysconfig/network-scripts/ifcfg-eth2
IPADDR=192.168.10.200
GATEWAY=
NETMASK=255.255.255.0
# vi /etc/sysconfig/network-scripts/route-eth0 192.102.5.0/24 via 172.16.38.1 dev eth0
# vi /etc/sysconfig/network-scripts/route_eth1 192.168.0.0/23 via 192.168.10.2 dev eth1
阅读(659) | 评论(0) | 转发(0) |