当前位置: 首页 > news >正文

【博客698】为什么当linux作为router使用时,安装docker后流量转发失败

为什么当linux作为router使用时,安装docker后流量转发失败

场景

当一台linux机器作为其它服务器的router,负责转发流量的时候,让你在linux上安装docker之后,就会出现流量都被drop掉了

原因

没装docker之前:

[root@~]# iptables -t raw -nvL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain OUTPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination[root@~]# iptables -t mangle -nvL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain INPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain FORWARD (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain OUTPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination[root@~]# iptables -t filter -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain FORWARD (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain OUTPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination[root@~]# iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain INPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain OUTPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination

装docker之后:

[root@~]# iptables -t raw -nvL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain OUTPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination[root@ ~]# iptables -t filter -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain FORWARD (policy DROP 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination0     0 DOCKER-USER  all  --  *      *       0.0.0.0/0            0.0.0.0/00     0 DOCKER-ISOLATION-STAGE-1  all  --  *      *       0.0.0.0/0            0.0.0.0/00     0 ACCEPT     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED0     0 DOCKER     all  --  *      docker0  0.0.0.0/0            0.0.0.0/00     0 ACCEPT     all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/00     0 ACCEPT     all  --  docker0 docker0  0.0.0.0/0            0.0.0.0/0Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain DOCKER (1 references)pkts bytes target     prot opt in     out     source               destinationChain DOCKER-ISOLATION-STAGE-1 (1 references)pkts bytes target     prot opt in     out     source               destination0     0 DOCKER-ISOLATION-STAGE-2  all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/00     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0Chain DOCKER-ISOLATION-STAGE-2 (1 references)pkts bytes target     prot opt in     out     source               destination0     0 DROP       all  --  *      docker0  0.0.0.0/0            0.0.0.0/00     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0Chain DOCKER-USER (1 references)pkts bytes target     prot opt in     out     source               destination0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0[root@~]# iptables -t mangle -nvL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain INPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain FORWARD (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain OUTPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination[root@~]# iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination5  1121 DOCKER     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCALChain INPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destinationChain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination0     0 MASQUERADE  all  --  *      !docker0  172.17.0.0/16        0.0.0.0/0Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target     prot opt in     out     source               destination3   168 DOCKER     all  --  *      *       0.0.0.0/0           !127.0.0.0/8          ADDRTYPE match dst-type LOCALChain DOCKER (2 references)pkts bytes target     prot opt in     out     source               destination0     0 RETURN     all  --  docker0 *       0.0.0.0/0            0.0.0.0/0

看到根本原因是:

Docker 将FORWARD链的默认策略设置为DROP。这时主机还充当路由器,这将导致该路由器不再转发任何流量。

解决办法

如果希望系统继续充当路由器,您可以ACCEPT向DOCKER-USER链添加明确的规则以允许它:

iptables -I DOCKER-USER -i src_if -o dst_if -j ACCEPT
http://www.lryc.cn/news/126356.html

相关文章:

  • el-dialog嵌套,修改内层el-dialog样式(自定义样式)
  • B树和B+树区别
  • intelJ IDEA\PHPStorm \WebStorm\PyCharm 通过ssh连接远程Mysql\Postgresql等数据库
  • vfuhyuuy
  • CSS自学框架之表单
  • 使用Spring Boot和Redis实现用户IP接口限流的详细指南
  • 前端性能优化——包体积压缩插件,打包速度提升插件,提升浏览器响应的速率模式
  • 配置vscode
  • 【Spring】深入理解 Spring 事务及其传播机制
  • eclipse常用设置
  • ajax解析
  • CSS3:图片边框
  • (七)Unity VR项目升级至Vision Pro需要做的工作
  • 【计算机视觉|生成对抗】生成对抗网络(GAN)
  • 神经网络基础-神经网络补充概念-15-神经网络概览
  • iOS Epub阅读器改造记录
  • 负载均衡搭建
  • form表单input标签的23种type类型值?
  • python selenium如何保存网站的cookie用于下次自动登录
  • DHCP Server
  • DMR+PoC宽窄融合互通解决方案
  • Springboot定时执行任务
  • 【Apollo】阿波罗自动驾驶:塑造自动驾驶技术的未来
  • JavaEE初阶:多线程 - Thread 类的基本用法
  • 编写 loading、加密解密 发布NPM依赖包,并实施落地使用
  • 【剑指Offer 57】和为s的连续正数序列,Java解密。
  • 深度学习实战基础案例——卷积神经网络(CNN)基于SqueezeNet的眼疾识别|第1例
  • 麦肯锡发布《2023年度科技报告》!
  • JAVASE---数组的定义与使用
  • 211、仿真-基于51单片机土壤湿度智能盆栽灌溉报警Proteus仿真设计(程序+Proteus仿真+配套资料等)