(ubuntu ufw)My firewall is blocking network connections from the docker container to outside





Maybe this is due to the current version, but the current answer doesn't work on my system (Docker 0.7.2 with base Ubuntu image).

The solution is explained here in the official Docker documentation.

For the lazy ones:

    edit /etc/default/ufw to change DEFAULT_FORWARD_POLICY's value to "ACCEPT",
    reload with [sudo] ufw reload.

This ensures ufw forward your traffic to the Docker's bridged network (as of my current understanding of these things...).


This fixed it for me:

 ufw allow in on docker0



Edit /etc/ufw/before.rules as follows:

In the *filter section, after the first block of required lines, add:

# docker rules to enable external network access from the container
# forward traffic accross the bridge
-A ufw-before-forward -i docker0 -j ACCEPT
-A ufw-before-forward -i testbr0 -j ACCEPT
-A ufw-before-forward -m state --state RELATED,ESTABLISHED -j ACCEPT

At the end of the file, after the line that says COMMIT, add the following section:

*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -s 172.16.42.0/8 -o eth0 -j MASQUERADE
# don't delete the 'COMMIT' line or these rules won't be processed
COMMIT

After saving the file, restart ufw with sudo ufw disable && sudo ufw enable

转载于:https://www.cnblogs.com/SZLLQ2000/p/7094274.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu UFW (Uncomplicated Firewall) 是一种简单易用的防火墙配置工具,它是基于 iptables 构建的。UFW 旨在简化防火墙的配置过程,使用户能够轻松地管理网络连接和访问规则。 要在 Ubuntu 上使用 UFW,可以按照以下步骤进行操作: 1. 确认 UFW 是否安装:默认情况下,UFWUbuntu 上已经预装了。可以通过运行以下命令来检查 UFW 是否已安装: ``` ufw version ``` 2. 设置默认策略:首先,需要设置默认的入站和出站策略。默认情况下,所有入站和出站连接都被拒绝。可以使用以下命令设置默认策略: ``` sudo ufw default deny incoming sudo ufw default allow outgoing ``` 3. 开启或关闭防火墙:可以使用以下命令来启用或禁用 UFW: ``` sudo ufw enable sudo ufw disable ``` 4. 添加规则:可以使用 UFW 添加特定的规则来允许或拒绝特定的网络连接。例如,要允许 SSH 连接,可以运行以下命令: ``` sudo ufw allow ssh ``` 还可以根据需要添加其他规则,如允许特定端口或 IP 地址的连接。 5. 查看状态:可以使用以下命令查看 UFW 的状态和配置: ``` sudo ufw status ``` 这将显示当前的防火墙规则和状态信息。 请注意,使用 UFW 进行防火墙配置可能需要以管理员身份运行命令(使用 `sudo`)。 以上是使用 Ubuntu UFW 进行基本防火墙配置的简要说明。更多详细信息,可以参考 Ubuntu 的官方文档或在互联网上寻找相关的教程和资源。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值