本文共 3773 字,大约阅读时间需要 12 分钟。
虚拟化网络工具:
创建物理桥:1 virsh命令virsh iface-bridge eth0 br02 /etc/sysconfig/network-scripts/编辑配置文件方式:[root@www08:26:15network-scripts]#cat ifcfg-eth0 DEVICE=eth0#IPADDR=172.20.23.30#NETMASK=255.255.0.0#GATEWAY=172.20.0.1#DNS1=114.114.114.114#DNS2=8.8.8.8BRIDGE=br0[root@www08:26:42network-scripts]#cat ifcfg-br0 DEVICE=br0 TYPE=BridgeIPADDR=172.20.23.30NETMASK=255.255.0.0GATEWAY=172.20.0.1DNS1=114.114.114.114DNS2=172.20.0.1BOOTPROTO=none ONBOOT=yes重启网络服务~
virsh和网络相关的命令:[root@www14:09:43~]#virsh help network Networking (help keyword 'network'): net-autostart net-create net-define 创建网络 net-destroy net-dhcp-leases net-dumpxml 查看网桥创建配置文件 net-edit net-event net-info net-list 查看网桥列表 net-name net-start net-undefine 删除网桥 net-update net-uuid 如何创建一个虚拟网络:[root@www19:48:51networks]#cat mynet0.xml[root@www19:52:19networks]#virsh net-create ./mynet0.xml Network mynet0 created from ./mynet0.xml拆除之前mybr0的接口:brctl delif mybr0 eth1 查看拆除结果:[root@www19:56:07networks]#brctl showbridge name bridge id STP enabled interfacesbr0 8000.000c2970f727 yes eth0mybr0 8000.000000000000 yes 将接口添加至mybr1:[root@www19:56:17networks]#brctl addif mybr1 eth1[root@www19:57:07networks]#brctl showbridge name bridge id STP enabled interfacesbr0 8000.000c2970f727 yes eth0mybr0 8000.000000000000 yes mybr1 8000.525400d7ee54 yes eth1 mybr1-nic测试和外面的mybr1链接:[root@www19:59:38networks]#ip netns exec r1 ping 192.168.24.3PING 192.168.24.3 (192.168.24.3) 56(84) bytes of data.64 bytes from 192.168.24.3: icmp_seq=1 ttl=64 time=0.069 ms64 bytes from 192.168.24.3: icmp_seq=2 ttl=64 time=0.093 ms创建一个虚拟机,选择和 mynet0 在同一网络! mynet0 72c15a3e-89ab-4d2c-819b-841342262eb1
brctl工具:来自----bridge-utils包[root@www14:09:24~]#rpm -qf `which brctl`bridge-utils-1.5-9.el7.x86_64常见选项:addbr --添加桥设备[软]delbr --删除桥设备[硬]addif --给网桥添加接口delif --网桥中拆除网线show --查看所有桥信息stp --开启生成树常见命令:添加网桥:brctl addbr mybr0启用禁用生成树:brctl stp mybr0 on/off激活网桥:ip link set [网桥名] up创建虚拟网卡对:ip link add veth1.1 type veth peer name veth1.2删除虚拟网卡对:ip link del veth1.1查看关联网卡对:ip link show更改虚拟网卡名称:ip link set veth1.1 name eth1启用虚拟网卡:ip link set eth1 upip link set eth2 up同样可以激活网桥:ip link set mybr0 up将网卡关联至网桥:brctl addif mybr0 eth1查看结果:[root@www19:26:30~]#brctl showbridge name bridge id STP enabled interfacesbr0 8000.000c2970f727 yes eth0mybr0 8000.82383e8abd07 yes eth1添加网络名称空间:ip netns add r1查看网络名称空间列表:ip netns list把虚拟网卡设备关联至网络名称空间:ip link set dev eth2 netns r1 查看结果:[root@www19:30:21~]#ip netns exec r1 ifconfig -aeth2: flags=4098mtu 1500 ether fe:46:56:2f:ee:61 txqueuelen 1000 (Ethernet) RX packets 8 bytes 648 (648.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 8 bytes 648 (648.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0网络名称空间配置IP:ip netns exec r1 ifconfig eth0 172.20.23.2/16具体执行:ip netns exec r1 ifconfig eth2 192.168.23.2/24和r1空间链接测试:[root@www19:37:07~]#ping 192.168.23.2PING 192.168.23.2 (192.168.23.2) 56(84) bytes of data.64 bytes from 192.168.23.2: icmp_seq=1 ttl=64 time=0.461 ms64 bytes from 192.168.23.2: icmp_seq=2 ttl=64 time=0.036 ms如何从虚拟网桥中拆除接口:brctl delif mybr0 eth1更改网络名称空间中的虚拟网卡设备名称:ip netns exec r1 ip link set dev veth1.2 name eth0
转载于:https://blog.51cto.com/13878078/2313722