11---
22description : How do we connect docker containers within and across hosts ?
3- keywords : Examples, Usage, network, docker, documentation , user guide, multihost, cluster
3+ keywords : network, networking, iptables , user-defined networks, bridge, firewall, ports
44redirect_from :
55- /engine/userguide/networking/dockernetworks/
66- /articles/networking/
@@ -12,6 +12,9 @@ including the type of networks created by default and how to create your own
1212user-defined networks. It also describes the resources required to create
1313networks on a single host or across a cluster of hosts.
1414
15+ For details about how Docker interacts with ` iptables ` on Linux hosts, see
16+ [ Docker and ` iptables ` ] ( #docker-and-iptables ) .
17+
1518## Default Networks
1619
1720When you install Docker, it creates three networks automatically. You can list
@@ -550,6 +553,34 @@ in default `bridge` network and the
550553[ linking containers in user-defined networks] ( work-with-networks.md#linking-containers-in-user-defined-networks )
551554for links functionality in user-defined networks.
552555
556+ ## Docker and iptables
557+
558+ Linux hosts use a kernel module called ` iptables ` to manage access to network
559+ devices, including routing, port forwarding, network address translation (NAT),
560+ and other concerns. Docker modifies ` iptables ` rules when you start or stop
561+ containers which publish ports, when you create or modify networks or attach
562+ containers to them, or for other network-related operations.
563+
564+ Full discussion of ` iptables ` is out of scope for this topic. To see which
565+ ` iptables ` rules are in effect at any time, you can use ` iptables -L ` . Multiple
566+ tables exist, and you can list a specific table, such as ` nat ` , ` prerouting ` , or
567+ ` postrouting ` , using a command such as ` iptables -t nat -L ` . For full
568+ documentation about ` iptables ` , see
569+ [ netflilter/iptables] ( https://netfilter.org/documentation/ ) {: target="_ blank" class="_ " }.
570+
571+ Typically, ` iptables ` rules are created by an initialization script or a daemon
572+ process such as ` firewalld ` . The rules do not persist across a system reboot, so
573+ the script or utility must run when the system boots, typically at run-level 3
574+ or directly after the network is initialized. Consult the networking
575+ documentation for your Linux distribution for suggestions about the appropriate
576+ way to make ` iptables ` rules persistent.
577+
578+ Docker dynamically manages ` iptables ` rules for the daemon, as well as your
579+ containers, services, and networks. In Docker 17.06 and higher, you can add
580+ rules to a new table called ` DOCKER-USER ` , and these rules will be loaded before
581+ any rules Docker creates automatically. This can be useful if you need to
582+ pre-populate ` iptables ` rules that need to be in place before Docker runs.
583+
553584## Related information
554585
555586- [ Work with network commands] ( work-with-networks.md )
0 commit comments