04 虚拟化技术基础原理
一、配置虚拟化网络
1、编辑配置文件
#关闭NetworkManager
[[email protected] ~]# service NetworkManager stop
[[email protected] ~]# chkconfig NetworkManager off
[[email protected] ~]# chkconfig --list NetworkManager
NetworkManager 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
[[email protected] ~]# yum -y install bridge-utils
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-eth0 ifcfg-br0
[[email protected] network-scripts]# vim ifcfg-br0
修改
DEVICE=eth0
为
DEVICE=br0
修改
TYPE=Ethernet
为
TYPE=Bridge
[[email protected] network-scripts]# vim ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BRIDGE=br0
IPV6INIT=no
NAME="System eth0"
[[email protected] network-scripts]# service network restart
[[email protected] network-scripts]# ifconfig
br0 Link encap:Ethernet HWaddr 00:0C:29:F1:37:B9
inet addr:192.168.1.62 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fef1:37b9/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:288 errors:0 dropped:0 overruns:0 frame:0
TX packets:120 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:23746 (23.1 KiB) TX bytes:16803 (16.4 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:F1:37:B9
inet6 addr: fe80::20c:29ff:fef1:37b9/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:57325 errors:0 dropped:0 overruns:0 frame:0
TX packets:3235 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:11649764 (11.1 MiB) TX bytes:249757 (243.9 KiB)
Interrupt:19 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 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:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[[email protected] network-scripts]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29f137b9 no eth0
#启用STP
[[email protected] network-scripts]# brctl stp br0 on
[[email protected] network-scripts]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29f137b9 yes eth0
二、命令方式
[[email protected] ~]# brctl show
bridge name bridge id STP enabled interfaces
[[email protected] ~]# brctl addbr br0
[[email protected] ~]# ifconfig eth0 0 up
[[email protected] ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000000000000 no
[[email protected] ~]# brctl addif br0 eth0
[[email protected] ~]# ifconfig br0 192.168.1.61/24 up
[[email protected] ~]# route add default gw 192.168.1.254
[[email protected] ~]# ifconfig
br0 Link encap:Ethernet HWaddr 00:0C:29:5A:FE:D5
inet addr:192.168.1.61 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe5a:fed5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:431 errors:0 dropped:0 overruns:0 frame:0
TX packets:127 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:41011 (40.0 KiB) TX bytes:15891 (15.5 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:5A:FE:D5
inet6 addr: fe80::20c:29ff:fe5a:fed5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14050 errors:0 dropped:0 overruns:0 frame:0
TX packets:2197 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5399019 (5.1 MiB) TX bytes:157286 (153.5 KiB)
Interrupt:19 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:958 (958.0 b) TX bytes:958 (958.0 b)