KVM使用之网络
网络有两种方式,一种是通过bridge, 一种通过NAT在NAT方式下,会使用virbr0进行通信,以允许虚拟机访问网络服务。目前我们环境是桥接,所有没有作用。查看和禁用:# virsh net-list# virsh net-destroy default# virsh net-undefine default# service libvirtd restart
网络有两种方式,一种是通过bridge, 一种通过NAT
在NAT方式下,会使用virbr0进行通信,以允许虚拟机访问网络服务。
目前我们环境是桥接,所有没有作用。查看和禁用:
# virsh net-list
# virsh net-destroy default
# virsh net-undefine default
# service libvirtd restart
或者
#ifconfig virbr0 down
#brctl delbr virbr0
当然,不禁用对我们系统也没有影响。
在网桥方式下,设计的操作有
1. 工具安装:
yum install bridge-utils
yum install tunctl
# tunctl - create and manage persistent TUN/TAP interfaces
2. 脚本创建:
# tunctl - create and manage persistent TUN/TAP interfaces
#!/bin/sh
PATH=$PATH:/usr/sbin:/sbin
sudo brctl addbr br0
sudo ifconfig eth0 0.0.0.0
sudo brctl addif br0 eth0
sudo ifconfig br0 192.168.1.120 netmask 255.255.255.0 up
sudo route add -net 192.168.1.0 netmask 255.255.255.0 br0
sudo route add default gw 192.168.1.1 br0
sudo tunctl -b -u john
sudo ifconfig tap0 up
sudo brctl addif br0 tap0
#export SDL_VIDEO_X11_DGAMOUSE=0
#sudo iptables -I RH-Firewall-1-INPUT -i br0 -j ACCEPT
qemu-kvm ~/win2k.img -m 512 -net nic -net tap,ifname=tap0,script=no
或者QEMU TAP选项中的脚本
#/etc/kvm/qemu-ifup-br1
#tunctl -t interface Specifies the desired interface name.
switch=br1
if [ -n "$1" ];then
tunctl -u `whoami` -t $1
ip link set $1 up
sleep 0.5s
brctl addif ${switch} $1
exit 0
else
echo "Error: no interface specified"
exit 1
fi
整个环境网络设备参数如下:
$brctl show
bridge name bridge id STP enabled interfaces
br0 8000.128abd3da3a0 no tap22
tap15
tap13
tap24
tap17
tap20
tap5
tap7
tap2
eth0
br1 8000.1e7c411d6778 no tap23
tap16
tap14
tap25
tap18
tap21
tap6
tap8
tap3
eth1
tap1
virbr0 8000.000000000000 yes
$ifconfig
br0 Link encap:Ethernet HWaddr 12:8A:BD:3D:A3:A0
inet addr:192.168.16.226 Bcast:192.168.16.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:56149092 errors:0 dropped:0 overruns:0 frame:0
TX packets:43895050 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5336444585 (4.9 GiB) TX bytes:7401435140 (6.8 GiB)
br1 Link encap:Ethernet HWaddr 1E:7C:41:1D:67:78
inet addr:172.31.16.226 Bcast:172.31.16.255 Mask:255.255.255.0
inet6 addr: fe80::1c7c:41ff:fe1d:6778/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:379283800 errors:0 dropped:0 overruns:0 frame:0
TX packets:185801315 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:265058942288 (246.8 GiB) TX bytes:66398472590 (61.8 GiB)
tap1 Link encap:Ethernet HWaddr 1E:7C:41:1D:67:78
inet6 addr: fe80::1c7c:41ff:fe1d:6778/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:168 errors:0 dropped:0 overruns:0 frame:0
TX packets:84299454 errors:0 dropped:0 overruns:9 carrier:0
collisions:0 txqueuelen:500
RX bytes:27000 (26.3 KiB) TX bytes:10826727533 (10.0 GiB)
.....
tap25 Link encap:Ethernet HWaddr 92:6C:35:97:95:9C
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1523 errors:0 dropped:0 overruns:0 frame:0
TX packets:33235 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:1815274 (1.7 MiB) TX bytes:6320065 (6.0 MiB)
virbr0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:37 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:7248 (7.0 KiB)
更多推荐
所有评论(0)