环境:
host1 : rhel7.2
host2: rhel7.2
1)启动docker,导入imag
# systemctl startdocker
# systemctl enabledocker
# docker load -irhel_img.tar
2) 创建网桥并给ip
# ovs-vsctl add-brvxbr
# ifconfig vxbr10.1.2.1/24
3) 添加vxlan类型端口,remoteip为host2的ip地址
# ovs-vsctl add-portvxbr vxlan -- set interface vxlan type=vxlan options:remote_ip=10.167.226.97
# ovs-vsctl show
8671ba34-06b7-4cfe-bcf8-f84351144b5c
Bridge vxbr
Port vxbr
Interface vxbr
type: internal
Port vxlan
Interface vxlan
type: vxlan
options:{remote_ip="10.167.226.97"}
4) 启动没有网口的容器
# docker run --net=none --privileged=true-it 22b67c35b968 /bin/bash
给容器机指定一个eth0并绑定到宿主机的vxbr网桥
# ovs-dockeradd-port vxbr eth0 d1b7acd6da69
回到容器将eth0赋予ip地址
# ip addr add10.1.2.3/24 dev eth0
在host1上可以看到vxbr有三个端口
# ovs-vsctl show
8671ba34-06b7-4cfe-bcf8-f84351144b5c
Bridge vxbr
Port vxbr 与自己通信
Interface vxbr
type: internal
Port vxlan vxlan端口
Interface vxlan
type: vxlan
options:{remote_ip="10.167.226.97"}
Port"9a63db7861f04_l" docker自身通信端口
Interface"9a63db7861f04_l"
5) 在host2上执行以上相同的步骤,网桥ip换成10.1.2.2/24
6)关闭防火墙
# iptable -F
7) 通过ping测试两个容器之间的通信