linux namespace连接参考:
docker网络-直接路由模式
参考:
- n1上创建br0ip link add br0 type bridgeip link set dev br0 upip addr add 10.1.1.1/24 dev br0- n2上创建br1ip link add br1 type bridgeip link set dev br1 upip addr add 20.1.1.1/24 dev br1- n1启动docker dockerd -b br0- n2启动docker dockerd -b br1tip: dockerd --help可以看到dockerd的选项- n1上写路由ip r a 20.1.1.0/24 via 192.168.14.133- n2上写路由ip r a 10.1.1.0/24 via 192.168.14.132- n1和n2 开启echo 1 > /proc/sys/net/ipv4/ip_forwardiptables -P FORWARD ACCEPT
出现的问题:
本端的容器,能访问到对方的br1,但是不能访问到对方br1下的容器
参考:系统默认是accept
iptables -t filter -Liptables -t filter -L --line-number,默认forward chian变成了drop
解决:
iptables -P FORWARD ACCEPT
可能将 iptables FORWARD chain的默认策略设置为DROP,从而导致 ping 其它 Node 上的 Pod IP 失败,遇到这种情况时,需要手动设置策略为 ACCEPT.
参考:
实现bridge之间的通信-一台主机
############################################ip link add br0 type bridgeip link set dev br0 upip addr add 10.1.1.1/24 dev br0ip netns add net0ip link add type vethip link set dev veth1 netns net0ip netns exec net0 ip link set dev veth1 name eth0ip netns exec net0 ip addr add 10.1.1.2/24 dev eth0ip netns exec net0 ip link set dev eth0 upip netns exec net0 ip route add default via 10.1.1.1 dev eth0ip link set dev veth0 master br0ip link set dev veth0 upip netns exec net0 ping 10.1.1.1############################################ip link add br1 type bridgeip link set dev br1 upip addr add 20.1.1.1/24 dev br1ip netns add net1ip link add type vethip link set dev veth1 netns net1ip netns exec net1 ip link set dev veth1 name eth0ip netns exec net1 ip addr add 20.1.1.2/24 dev eth0ip netns exec net1 ip link set dev eth0 upip netns exec net1 ip route add default via 20.1.1.1 dev eth0ip link set dev veth0 master br1ip link set dev veth0 upip netns exec net1 ping 20.1.1.1
实现bridge之间的通信-两台主机
#####################在n1操作######################ip link add br0 type bridgeip link set dev br0 upip addr add 10.1.1.1/24 dev br0ip netns add net0ip link add type vethip link set dev veth1 netns net0ip netns exec net0 ip link set dev veth1 name eth0ip netns exec net0 ip addr add 10.1.1.2/24 dev eth0ip netns exec net0 ip link set dev eth0 upip netns exec net0 ip route add default via 10.1.1.1 dev eth0ip link set dev veth0 master br0ip link set dev veth0 upip r a 20.1.1.0/24 via 192.168.14.133ip netns exec net0 ping 10.1.1.1########################在n2操作##################ip link add br1 type bridgeip link set dev br1 upip addr add 20.1.1.1/24 dev br1ip netns add net1ip link add type vethip link set dev veth1 netns net1ip netns exec net1 ip link set dev veth1 name eth0ip netns exec net1 ip addr add 20.1.1.2/24 dev eth0ip netns exec net1 ip link set dev eth0 upip netns exec net1 ip route add default via 20.1.1.1 dev eth0ip link set dev veth2 master br1ip link set dev veth2 upip r a 10.1.1.0/24 via 192.168.14.132ip netns exec net1 ping 20.1.1.1