将多个主机(物理机或虚拟机)连接到同一个网桥上,实现它们之间的通信,但是要构建复杂的网络,就需要多个网桥,在装有open vswitch的主机上建立两个网桥,实现它们之间的连接,构建结果如下:
1. 新建网桥br
ovs-vsctl add-br br0 //添加一个名为br0的网桥
ovs-vsctl add-br br1 //添加一个名为br0的网桥
- 1
- 2
2. 新建虚拟端口并打patch
ovs-vsctl add-port br0 patch-to-br1 //为br0添加一个虚拟端口
ovs-vsctl set interface patch-to-br1 type=patch //把patch-to-br1的类型设置为patch
ovs-vsctl set interface patch-to-br1 options:peer=patch-to-br0 //把对端网桥和此网桥连接的端口名称设置为patch-to-br0
- 1
- 2
- 3
以及:
ovs-vsctl add-port br1 patch-to-br0 //为br0添加一个虚拟端口
ovs-vsctl set interface patch-to-br0 type=patch //把patch-to-br0的类型设置为patch
ovs-vsctl set interface patch-to-br0 options:peer=patch-to-br1 //把对端网桥和此网桥连接的端口名称设置为patch-to-br1
- 1
- 2
- 3
3. 备注
1) 以下两个是对ovs-database的操作,有兴趣的同学可以参考.5
ovs-vsctl set interface patch-to-br0type=patch
ovs-vsctl set interface patch-to-br0 options:peer=patch-to-br1
2) tcpdump抓包无法获取patch端口的数据包
root@node2:/tmp/zq# tcpdump -i patch-to-con
tcpdump: patch-to-con: No such device exists
(SIOCGIFHWADDR: No such device)
- 1
- 2
- 3
而:NAT的网口可以…
root@node2:/tmp/zq# tcpdump -i eout-if -n
tcpdump: WARNING: eout-if: no IPv4 address assigned
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eout-if, link-type EN10MB (Ethernet), capture size 65535 bytes
15:33:49.793172 ARP, Request who-has 192.168.19.69 tell 192.168.19.11, length 46
^C
1 packet captured
3 packets received by filter
0 packets dropped by kernel
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
4. 为两个网桥添加物理网卡
在两台机器上分别安装上open vswitch并创建网桥,分别为两个网桥添加物理网卡,然后通过网线连接两个网桥,实现两个网桥之间的互通。构建结果图如下:
host1
ovs-vsctl add-br br0 //添加名为br0的网桥
ovs-vsctl add-port br0 eth0 //把eth0挂接到br0上
- 1
- 2
host2
ovs-vsctl add-br br0 //添加名为br0的网桥
ovs-vsctl add-port br0 eth0 //把eth0挂接到br0上
- 1
- 2
然后使用网线把host1的eth0和host2的eth0相连即可。