Tag: iptables

用nat设置docker容器

我正在设置两个docker集装箱 container1 container2 | | | eth0 eth1 | | | eth1 docker0 docker1<—————- | | internet docker0和docker1是桥梁。 我有ip转发到1在主机和容器。 我已经设置 iptables -I POSTROUTING -t nat -o eth0 -j MASQUERADE in container 1 不过,我不能ping任何从容器2到互联网。 我可以看到数据包在容器1的eth1上被接收。 OS: ubuntu 13.10 docker version: 0.11.1, build fb99f99 我缺less一些configuration? 重现步骤: SERV=$(docker run –privileged=true -i -d -t -v ~/Projects/code/myproject/build:/build:ro debian:7.4 /bin/bash) CLI=$(docker […]

Docker的NAT表输出链规则

我想了解iptables中的规则之一: $ sudo iptables -t nat –list -v … Chain OUTPUT (policy ACCEPT 618 packets, 31267 bytes) pkts bytes target prot opt in out source destination 0 0 DOCKER all — any any anywhere !127.0.0.0/8 ADDRTYPE match dst-type LOCAL … 所以这条规则试图匹配目的地址types“本地”,而不是在127.0.0.0/8的范围内? 那么它会匹配什么地址? 这个规则的目的是什么? 谢谢!

如何将docker容器中的单个端口redirect到容器的主机?

为了使项目的开发更容易,我在docker容器中放了一些它依赖的服务。 这使得项目configuration中的“localhost”在传递给其中一个容器时会有所不同。 编辑 要清楚,我试图转发一个容器的端口到主机,所以当容器中运行的进程试图访问localhost:5432时,它连接到主机的端口5432。 EndEdit中 我目前正在使用 HOST_IP=`ip route | grep default | awk '{ printf "%s",$3 }'` cat /etc/hosts | sed "s/127.0.0.1/$HOST_IP/" > /tmp/etc_hosts cp /tmp/etc_hosts /etc/hosts 将任何目标为'本地主机'redirect到容器的主机。 它在这种情况下工作,但我宁愿find一种方法来做到这一点,只为所需的端口,因为我希望它不会在其他情况下工作。 这是我想出来做的,但是这不起作用。 当容器中的连接是localhost:5432时,它将尝试连接到容器的5432而不是主机的: # — These are the things that should make redirecting port 5432 to the host machine # work, provided the container is run in […]

在基于alpinelinux的docker容器中安装iptables

我正在写一个dockerfile,我需要在docker容器中安装IPtables。 我需要添加一个规则到IP表,因为我试图在“主机”networking模式下运行,似乎我需要为此安装IPtables。 当我尝试如下包含规则时,出现以下错误。 iptables -I INPUT -p tcp -m tcp –dport 8080 -j ACCEPT iptables v1.6.0: can't initialize iptables table `filter': Permission denied (you must be root) 也许iptables或你的内核需要升级。 是否有可能以root权限运行iptables。

阻止从Docker容器到私有IP的传出连接

我们使用Docker在服务器上运行的一些服务尝试连接到私有IP地址(10.0.0.0/8,192.0.0.0/16,172.16.0.0/12,100.64.0.0/10)。 这种行为是正常的,但我们的服务器提供商检测到这种stream量,并发送警报 我们只想停止传出stream量,而不是使用iptables传入。 这是我们目前的设置: -A OUTPUT -d 192.168.0.0/16 -m owner –uid-owner `id -u dockeruser` -j REJECT –reject-with icmp-port-unreachable -A OUTPUT -d 100.64.0.0/10 -m owner –uid-owner `id -u dockeruser` -j REJECT –reject-with icmp-port-unreachable -A OUTPUT -d 172.16.0.0/12 -m owner –uid-owner `id -u dockeruser` -j REJECT –reject-with icmp-port-unreachable -A OUTPUT -d 10.0.0.0/8 -m owner –uid-owner `id -u […]

Docker是否在iptables中为桥接networking自动化IP伪装规则?

我有一台QNAP RAID机器上运行docker-1.9.1 。 它具有使用子网10.0.3.0/24的默认bridgenetworking。 在iptables中,我在nat表中看到一条规则: -A POSTROUTING -s 10.0.3.0/24 ! -d 10.0.3.0/24 -j MASQUERADE 我假设Docker自己创build了这个规则。 我创build了一个新的桥梁networking: docker network create \ –gateway=10.0.5.1 \ –subnet=10.0.5.0/24 \ -o "com.docker.network.bridge.host_binding_ipv4"="0.0.0.0" \ -o "com.docker.network.bridge.enable_icc"="true" \ -o "com.docker.network.driver.mtu"="1500" \ -o "com.docker.network.bridge.name"="lxcbr1" \ -o "com.docker.network.bridge.enable_ip_masquerade"="true" \ isolated_nw 这不会在iptables中创build一个规则。 我错过了一个步骤? 下面是完整的设置命令和结果,复制@larsks的例子: [/share/Containers] # docker –version Docker version 1.9.1, build 147ce3e [/share/Containers] # iptables […]

如何从另一台机器连接到Docker API?

我正在尝试使用Docker API从另一台机器连接到docker守护进程。 我能够成功地执行这个命令: docker -H=tcp://127.0.0.1:4243 images 但不是当我使用真正的IP地址: docker -H=tcp://192.168.2.123:4243 images 2013/08/04 01:35:53 dial tcp 192.168.2.123:4243: connection refused 为什么在使用非本地IP时无法连接? 我在Vagrantfile中使用Vagrant VM: config.vm.network :private_network, ip: "192.168.2.123" 以下是iptables: # Generated by iptables-save v1.4.12 on Sun Aug 4 01:24:46 2013 *filter :INPUT ACCEPT [1974:252013] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [1511:932565] -A INPUT -p tcp -m tcp –dport 4243 -j […]

如何防止docker容器内的代码访问networking?

我需要阻止我的docker集装箱访问外部世界。 这意味着容器不应该像wget http://www.google.com那样做 以前,我使用JérômePetazzoni的指令 ,joiniptables规则,例如: -A FORWARD -s 10.0.3.0/24 -j DROP 这似乎不再工作。 也许我不知道如何find用于docker / lxc的正确IP。 我使用lxc驱动程序运行docker 1.1.2 。 一种可能适用于某些方法的方法是使用–net="none" 。 但是,这不适合我,因为我仍然需要在我的容器中的eth0适配器和关联的HWaddr。 我目前的iptables是: *mangle :PREROUTING ACCEPT [12966683:10182972515] :INPUT ACCEPT [12966640:10182952166] :FORWARD ACCEPT [42:20285] :OUTPUT ACCEPT [12323852:11636850769] :POSTROUTING ACCEPT [12323894:11636871054] -A POSTROUTING -o lxcbr0 -p udp -m udp –dport 68 -j CHECKSUM –checksum-fill COMMIT # Completed on […]

给Docker容器一个可路由的IP地址

我在ubuntu 14.04上运行这个,并将docker0设置为静态IP,然后通过防火墙从公共IP路由。 我试图设置我的后端API在Docker容器中运行,并由一些事情困惑。 1.)如何将docker0的ip映射到容器的ip,使得docker0知道将传入的数据包发送到容器(如果可能,dynamic地)。 2.)如果还没有这样做,我怎么能这样做,以便我不必每次重新运行docker集装箱时都要设置它? 提前致谢!

在Docker容器内暴露dynamic打开的端口

假设一个应用程序dynamic地打开Docker容器中运行的UDP端口,如何将这些端口暴露/绑定到外部(主机)端口? 这可能与此处提出的问题相同,但答案(使用–net=host )限制了运行多个容器实例的可扩展性,从而将相同的端口暴露给主机。 有什么办法可以configuration主机容器中dynamic打开的端口的一对一映射吗? 例如,端口45199/udp在容器内部打开,并暴露在主机上的端口45199/udp上?