Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › Container Networking

How to Configure the Linux Firewall for Docker Swarm

By Freedom251 Team · · 11 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a Docker Swarm, allow node-to-node traffic only on TCP 2377, TCP and UDP 7946, and UDP 4789 by default. Restrict those ports to the network that contains your managers and workers. Then control application ports separately, because Swarm’s routing mesh can make a published port reachable on every node, including nodes that are not running that service.

Keep Docker’s generated firewall chains intact. Put administrator rules in DOCKER-USER for container and published-port policy, while host-level Swarm control traffic is filtered in the host’s input path. Docker’s documented nftables backend is not supported when the daemon runs in Swarm mode, so a Swarm host should continue using the iptables path (including an iptables-nft compatibility command only when Docker’s support statement for your release permits it).

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The ports Docker Swarm needs

Every participating node must be able to reach the other nodes on the control, membership, and overlay data paths. The minimum rules are:

Traffic Protocol and port Who should be allowed Purpose
Swarm manager control plane TCP 2377 Only trusted Swarm nodes Manager join and control traffic
Node discovery and membership TCP and UDP 7946 All participating managers and workers Node discovery and membership gossip
Overlay/VXLAN data path UDP 4789 by default All participating managers and workers Overlay networks, including ingress routing-mesh traffic
Encrypted overlay data IP protocol 50 (ESP) Participating nodes when encrypted overlays are used Encrypted overlay packets
Published services Application-specific TCP or UDP ports Only intended clients or load balancers, on every Swarm node Client access to services published with Swarm

Port 4789 is configurable. If the cluster was initialized with a different data-path port, allow that UDP port instead of 4789 on every node. Port 7946 is not configurable. These rules are for the private or otherwise trusted network carrying Swarm traffic, not for arbitrary Internet sources.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Why the trust boundary matters

VXLAN on UDP 4789 does not authenticate its packets. An Internet-facing firewall must never expose that port to untrusted networks. A perimeter firewall should allow it only across the private link, VPN, or dedicated segment used by the nodes. The same source restriction should be applied to TCP 2377 and both protocols on 7946.

Do not confuse “the host has a public address” with “the Swarm network is public.” A node can have a public interface for client traffic and a separate private interface for cluster traffic. Bind the inter-node rules to the private interface or its CIDR whenever your firewall supports interface and source restrictions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Inventory the cluster before changing rules

Firewall changes are safer when you first write down the traffic you intend to permit. Record:

  • Every manager and worker address, including the subnet used for node-to-node communication.
  • Which interface carries Swarm control and overlay traffic.
  • Whether the cluster uses encrypted overlay networks.
  • The data-path UDP port selected at initialization. A cluster created with docker swarm init --data-path-port 14789, for example, needs UDP 14789 rather than UDP 4789.
  • Every port published by docker service create or docker service update, with its protocol and the client networks that should reach it.
  • Any external load balancer, reverse proxy, monitoring system, or backup host that must connect to a published service.

Keep manager and worker addresses in a small, explicit source set. A broad “allow from the whole data center” rule is easier to create but increases the consequence of a compromised host.

Understand Docker’s iptables chains

Docker creates and maintains several chains, including DOCKER-USER, DOCKER-FORWARD, DOCKER, DOCKER-BRIDGE, DOCKER-INTERNAL, DOCKER-CT, and DOCKER-INGRESS. Docker’s generated rules handle forwarding, address translation, bridges, and Swarm ingress.

DOCKER-USER is the administrator insertion point for forwarded container traffic. Docker processes it before DOCKER-FORWARD and DOCKER-INGRESS. An accept or drop there can prevent later chains from being evaluated, which makes it the right place for source allowlists and published-port restrictions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Do not flush or delete Docker’s chains as a way to “start clean.” Disabling Docker’s iptables management without replacing all required forwarding and translation rules can break bridge networking, overlay networks, ingress, and service publication. Also inspect the host’s FORWARD policy: Docker may enable IP forwarding and set that policy to DROP, so the resulting rule path must be intentional.

Build the host-level Swarm rules with iptables

Node control and overlay packets arrive at the host itself, so place their source-restricted permits in the host input path. The following example uses 10.20.0.0/24 as the private Swarm-node network; substitute the actual node CIDR and, where appropriate, add an interface match.

  1. Allow manager control traffic:
    iptables -I INPUT -s 10.20.0.0/24 -p tcp --dport 2377 -j ACCEPT
  2. Allow membership and discovery on both protocols:
    iptables -I INPUT -s 10.20.0.0/24 -p tcp --dport 7946 -j ACCEPT
    iptables -I INPUT -s 10.20.0.0/24 -p udp --dport 7946 -j ACCEPT
  3. Allow the overlay data path:
    iptables -I INPUT -s 10.20.0.0/24 -p udp --dport 4789 -j ACCEPT
    Use the configured custom UDP port if the cluster was initialized with one.
  4. If encrypted overlays are enabled, allow IP protocol 50 between the participating nodes. Keep this rule limited to the node network and the interface that carries overlay traffic.
  5. Review the resulting order with iptables-save and confirm that an earlier drop rule is not reached first.

These permits should not be opened to 0.0.0.0/0. If managers and workers use more than one private subnet, add one narrowly scoped rule per subnet instead of replacing the source restriction with “any.”

Enforce encrypted overlay traffic

When encrypted overlay networking is in use, Docker recommends accepting only encrypted packets on the data-path port. Its documented example drops unencrypted inbound VXLAN packets with:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iptables -I INPUT -m udp --dport 4789 -m policy --dir in --pol none -j DROP

Adapt the port, rule position, and interface to your host. Insert the allow rule for the trusted node network before this drop when needed, and test a real encrypted overlay afterward. A custom data-path port must replace 4789 in both the allow and drop logic.

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Put published-service policy in DOCKER-USER

Swarm’s routing mesh listens on a published port on every node. A request sent to a worker that has no local task can still be forwarded to a task on another node. Consequently, a firewall rule on only the node currently running a container is insufficient.

Create a separate allowlist for each published application port and apply it to every node. For example, if TCP 8443 is intended only for clients in 192.0.2.0/24, a forwarded-traffic policy can be organized as follows:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Permit return traffic before restrictive rules:
    iptables -I DOCKER-USER -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
  2. Permit the approved client network to the published port:
    iptables -I DOCKER-USER -s 192.0.2.0/24 -p tcp --dport 8443 -j ACCEPT
  3. Drop other attempts to that published port:
    iptables -I DOCKER-USER -p tcp --dport 8443 -j DROP

Place the rules in an order that preserves the established-connection exception and the approved source permit. If several client networks are valid, add each source-specific accept before the final drop. Repeat the pattern for UDP services, using the service’s actual published port. Do not add a blanket drop in DOCKER-USER without first accounting for other container traffic that the host must continue to forward.

Docker may perform address translation before a packet reaches the user chain. Verify which destination and port are visible on your Docker Engine release, and use counters or logs to confirm that the intended rule is matching.

Using UFW without losing Docker’s rules

UFW is a front end, not a replacement for Docker’s generated chains. Use it to express host input policy for the Swarm ports, with the node CIDR as the source. For the example private network, the rule forms are:

  • ufw allow from 10.20.0.0/24 to any port 2377 proto tcp
  • ufw allow from 10.20.0.0/24 to any port 7946 proto tcp
  • ufw allow from 10.20.0.0/24 to any port 7946 proto udp
  • ufw allow from 10.20.0.0/24 to any port 4789 proto udp

Use the custom data-path port when applicable. Add the encrypted-overlay requirement separately if the deployment uses protocol 50; UFW’s ordinary TCP/UDP syntax does not express every IP-protocol policy, so retain an iptables rule for that case.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Published Docker ports require special care. Confirm that UFW’s generated rules and Docker’s chains produce the intended result, then put source restrictions in DOCKER-USER when UFW’s high-level rules do not constrain forwarded container traffic. Never assume that a successful ufw status display proves the routing mesh is restricted.

firewalld and other distribution front ends

firewalld, nftables command sets, and persistence packages differ by distribution. The policy remains the same: permit the three inter-node port groups only from the node network, permit ESP when encrypted overlays require it, and maintain a separate allowlist for every published application port.

When a front end reloads, inspect the actual iptables rules afterward. Confirm that Docker’s chains still exist, that DOCKER-USER is reached before Docker’s forwarding chains, and that the host’s FORWARD policy has not changed in a way that blocks overlay or ingress traffic. Use the distribution’s documented mechanism to save and restore rules across reboot; there is no single persistence command that applies to every Linux distribution.

Why nftables native mode is a Swarm problem

Docker documents its nftables backend as experimental. Overlay-network rules have not been migrated to that backend, so Docker states that nftables cannot be enabled while the daemon is running in Swarm mode. A system may provide an iptables-nft compatibility command, but that does not by itself mean Docker is using a supported native nftables backend for Swarm.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check the Docker Engine release documentation and packaging on the host before changing backends. Do not switch a live Swarm to native nftables merely because other services on the server use it. Keep the supported iptables path until Docker explicitly documents overlay and Swarm support for the backend you intend to use.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Persist and reload safely

Runtime iptables or UFW changes disappear unless the distribution saves them. After adding rules:

  1. Save the active rules with the mechanism supplied by the distribution or firewall package.
  2. Reload the firewall in a maintenance window, preferably with console access or an out-of-band channel in case remote access is blocked.
  3. Restarting Docker must not erase your DOCKER-USER policy. Verify the chain and its rule order after a Docker restart.
  4. Reboot a test node, restore the saved rules, and confirm that Swarm membership, overlay traffic, and published services recover.

Do not rely on a rule count alone. A persistence system can restore rules into a different table or chain order than the one you tested.

Verification plan

Test from three perspectives: an allowed client, a deliberately denied client, and each Swarm node.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • From every node, test TCP 2377 to each manager address and TCP/UDP 7946 and the selected UDP data-path port to every participating node.
  • Inspect membership with docker node ls. A node that repeatedly changes between Ready and Down often indicates blocked control or membership traffic.
  • Create or use a test overlay service and verify that tasks on different nodes can communicate.
  • From an approved client network, connect to each node’s published application port, not only the node currently running the task.
  • From a denied network, confirm that the same published port is rejected or times out according to your intended policy.
  • Inspect counters with iptables -L -v -n and the complete configuration with iptables-save. Counters should increase on the expected allow or drop rule.
  • If overlays are encrypted, verify that encrypted traffic works and that an unencrypted packet cannot use the data-path port.

Run these checks after firewall reloads, Docker upgrades, node replacement, and changes to service publication. A test that succeeds only from the manager is not enough because routing mesh behavior is node-wide.

Troubleshooting common failures

Symptom Likely firewall cause What to inspect
Worker cannot join the Swarm TCP 2377 is blocked or limited to the wrong source network Manager input rules, advertised address, and the source CIDR
Nodes join but show intermittent membership failures TCP or UDP 7946 is blocked in one direction Both protocols on every node and intermediate firewalls
Overlay service traffic fails across hosts The UDP data-path port is blocked, or a custom port was overlooked The initialization setting, node routes, and UDP counters
Encrypted overlay does not establish ESP protocol 50 is blocked, or the data-path policy drops required packets Protocol-50 permits and the order of the policy match/drop rules
A published service works on one node but not another The routing-mesh port is allowed only on the node holding the task Published-port rules on every node and DOCKER-USER counters
All containers lose connectivity after a firewall change Docker chains were flushed, disabled, or bypassed by a broad forward drop DOCKER-USER, DOCKER-FORWARD, DOCKER-INGRESS, and the FORWARD policy
Rules vanish after reboot or Docker restart The distribution’s persistence mechanism was not configured, or chain order changed Saved rules, service startup order, and post-restart iptables-save output

Choosing a firewall approach

There is no universally best front end. Compare the implementation you plan to deploy against these operational requirements:

Decision axis Questions to answer
Docker and Swarm support Is the backend supported by the Docker Engine release, especially while the daemon runs in Swarm mode?
Network scoping Can rules be limited to the node CIDR and the interface carrying Swarm traffic?
Docker chain integrity Will Docker’s generated chains remain intact and will administrator policy still enter through DOCKER-USER?
Routing-mesh control Can you restrict each published port on every node, rather than only on nodes running tasks?
Persistence Are rules restored after reboot, firewall reload, and Docker restart?
Observability Can operators inspect counters, logs, and the effective order of rules?

A simple, auditable iptables policy is preferable to a sophisticated backend that Docker does not support for Swarm overlays. Whichever front end you select, document the node CIDRs, data-path port, encrypted-overlay requirement, published ports, and rollback procedure beside the cluster configuration.

Operational hardening checklist

  • Allow TCP 2377 only between trusted managers and workers.
  • Allow TCP and UDP 7946 between every participating node.
  • Allow UDP 4789, or the configured replacement port, only across the node network.
  • Allow IP protocol 50 when encrypted overlays are deployed.
  • Never expose VXLAN UDP 4789 to an untrusted perimeter.
  • Keep Docker’s generated chains and place forwarded container policy in DOCKER-USER.
  • List every published service port and its approved client networks.
  • Apply routing-mesh restrictions on every node, including nodes without a local task.
  • Check the FORWARD policy after enabling IP forwarding.
  • Persist rules using the host distribution’s supported mechanism.
  • Test allowed, denied, cross-node, encrypted-overlay, reboot, and Docker-restart paths.

Safe change and rollback procedure

For a live cluster, add narrowly scoped allow rules first, verify connectivity, and only then add restrictive drops. Keep an existing administrative session open while testing and have console access available. If a change blocks membership or overlay traffic, remove the newest restrictive rule from the affected chain, restore the last known-good saved ruleset, and retest one node before propagating the correction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When changing the data-path port, treat it as a cluster-wide change: update the firewall on all participating nodes and ensure every intermediate firewall permits the same UDP port. A node left with the old port can appear healthy for control traffic while overlay applications fail, so include cross-node service tests in the change window.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Container NetworkingDocker networkingDocker SwarmiptablesLinux firewallUFW

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.