1. 机器列表
主机名 IP docker0 IP docker容器IPnode101 192.168.80.101 10.1.1.1/24 10.1.1.2/24
node102 192.168.80.102 20.1.1.1/24 20.1.1.2/24
2. 网络示意图
3. rpm制作
mkdir -p ~/rpmbuild/SOURCEScp openvswitch-2.5.0.tar.gz ~/rpmbuild/SOURCES使用源码包中的SPEC文件制作rpm安装包
tar -xf openvswitch-2.5.0.tar.gzrpmbuild -bb openvswitch-2.5.0/rhel/openvswitch.spec 4. node101==================4.1 安装制作的rpm包yum localinstall ~/rpmbuild/RPMS/x86_64/openvswitch-2.5.0-1.x86_64.rpm
4.2 启动openswitch
/etc/init.d/openvswitch start/etc/init.d/openvswitch status检查日志输出
tail -100 /var/log/messages4.3 ovs配置
创建网桥br0
ovs-vsctl add-br br0把网络设备gre1添加到网桥br0
ovs-vsctl add-port br0 gre1 -- set interface gre1 type=gre option:remote_ip=192.168.80.102添加br0到本地docker0,使得容器流量通过OVS流经tunnel
brctl addif docker0 br0修改网络设备状态为up
ip link set dev br0 upip link set docker0 up查看网桥和ovs接口
brctl showovs-vsctl list-brovs-vsctl list-ifaces br0ovs-vsctl list-ports br04.4 防火墙放行icmp
iptables -D INPUT -j REJECT --reject-with icmp-host-prohibitediptables -D FORWARD -j REJECT --reject-with icmp-host-prohibited4.5 添加到node102主机的docker路由
route add -net 20.1.1.0/24 gw 192.168.80.1024.6 启动容器
docker run -it mysql bash查看该容器ip地址
ip addr
5. node102
==================5.1 安装制作的rpm包
yum localinstall ~/rpmbuild/RPMS/x86_64/openvswitch-2.5.0-1.x86_64.rpm5.2 启动openswitch
/etc/init.d/openvswitch start/etc/init.d/openvswitch status检查日志输出
tail -100 /var/log/messages5.3 OVS配置
创建网桥br0
ovs-vsctl add-br br0把网络设备gre1添加到网桥br0
ovs-vsctl add-port br0 gre1 -- set interface gre1 type=gre option:remote_ip=192.168.80.101添加br0到本地docker0,使得容器流量通过OVS流经tunnel
brctl addif docker0 br0修改网络设备状态为up
ip link set dev br0 upip link set docker0 up查看网桥和ovs接口
brctl showovs-vsctl list-brovs-vsctl list-ifaces br0ovs-vsctl list-ports br05.4 防火墙放行icmp
iptables -D INPUT -j REJECT --reject-with icmp-host-prohibitediptables -D FORWARD -j REJECT --reject-with icmp-host-prohibited5.5 添加到node102主机的docker路由
route add -net 10.1.1.0/24 gw 192.168.80.1015.6 启动容器
docker run -it mysql bash查看该容器ip地址
ip addr
6. 抓包分析
在node101中的docker实例中pingnode102的docker实例IP,抓包分析OVS数据流向node101
==================[veth2a3e623] 04:03:59.861136 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 10.1.1.2 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64[veth2a3e623] 04:03:59.861986 IP (tos 0x0, ttl 62, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 10.1.1.2: ICMP echo reply, id 24, seq 0, length 64[docker0] 04:03:59.861136 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 10.1.1.2 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64
[docker0] 04:03:59.861979 IP (tos 0x0, ttl 62, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 10.1.1.2: ICMP echo reply, id 24, seq 0, length 64[eno16777728] 04:03:59.861185 IP (tos 0x0, ttl 63, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 192.168.80.101 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64
[eno16777728] 04:03:59.861946 IP (tos 0x0, ttl 63, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 192.168.80.101: ICMP echo reply, id 24, seq 0, length 64OUT方向按时间排序
[veth2a3e623] 04:03:59.861136 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 10.1.1.2 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64[docker0] 04:03:59.861136 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 10.1.1.2 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64[eno16777728] 04:03:59.861185 IP (tos 0x0, ttl 63, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 192.168.80.101 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64IN方向按时间排序
[eno16777728] 04:03:59.861946 IP (tos 0x0, ttl 63, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 192.168.80.101: ICMP echo reply, id 24, seq 0, length 64[docker0] 04:03:59.861979 IP (tos 0x0, ttl 62, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 10.1.1.2: ICMP echo reply, id 24, seq 0, length 64[veth2a3e623] 04:03:59.861986 IP (tos 0x0, ttl 62, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 10.1.1.2: ICMP echo reply, id 24, seq 0, length 64node102
==================[veth8198030] 04:03:59.043575 IP (tos 0x0, ttl 62, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 192.168.80.101 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64[veth8198030] 04:03:59.043621 IP (tos 0x0, ttl 64, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 192.168.80.101: ICMP echo reply, id 24, seq 0, length 64[docker0] 04:03:59.043565 IP (tos 0x0, ttl 62, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 192.168.80.101 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64
[docker0] 04:03:59.043621 IP (tos 0x0, ttl 64, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 192.168.80.101: ICMP echo reply, id 24, seq 0, length 64[eno16777728] 04:03:59.043509 IP (tos 0x0, ttl 63, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 192.168.80.101 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64
[eno16777728] 04:03:59.043634 IP (tos 0x0, ttl 63, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 192.168.80.101: ICMP echo reply, id 24, seq 0, length 64 IN方向按时间排序[eno16777728] 04:03:59.043509 IP (tos 0x0, ttl 63, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 192.168.80.101 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64[docker0] 04:03:59.043565 IP (tos 0x0, ttl 62, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 192.168.80.101 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64[veth8198030] 04:03:59.043575 IP (tos 0x0, ttl 62, id 0, offset 0, flags [DF], proto ICMP (1), length 84) 192.168.80.101 > 20.1.1.2: ICMP echo request, id 24, seq 0, length 64OUT方向按时间排序
[veth8198030] 04:03:59.043621 IP (tos 0x0, ttl 64, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 192.168.80.101: ICMP echo reply, id 24, seq 0, length 64[docker0] 04:03:59.043621 IP (tos 0x0, ttl 64, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 192.168.80.101: ICMP echo reply, id 24, seq 0, length 64[eno16777728] 04:03:59.043634 IP (tos 0x0, ttl 63, id 32460, offset 0, flags [none], proto ICMP (1), length 84) 20.1.1.2 > 192.168.80.101: ICMP echo reply, id 24, seq 0, length 64
br0抓包无数据,gre通道是虚拟的,实际还是从物理网卡传输