Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Docker warns that IPv4 forwarding is disabled

ErrorWARNING: IPv4 forwarding is disabled

Short answer

Docker containers need the Linux kernel setting net.ipv4.ip_forward to be 1 on the host. The warning means dockerd saw 0. Most often a hardening file in /etc/sysctl.d resets it, or you use Docker's nftables backend, which never turns it on. In rootless mode the warning can also be wrong. Read the real value first.

  • Applies to Docker Engine 28, Ubuntu 24.04, systemd 255
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the kernel value on the host. 1 means forwarding is on; 0 means something has it off.

    cat /proc/sys/net/ipv4/ip_forward
    grep -rn "ip_forward" /etc/sysctl.conf /etc/sysctl.d/ /usr/lib/sysctl.d/ /run/sysctl.d/ 2>/dev/null
  2. 2Match what you see, then jump to its fix

    1. 1The value is 0 and grep finds net.ipv4.ip_forward = 0 in a security-baseline file. The warning may appear only right after a reboot.A sysctl file sets ip_forward to 0 (common on hardened servers)Fix
    2. 2Docker was switched to the nftables firewall backend, and forwarding is 0.Docker uses the nftables backend, which does not enable forwardingFix
    3. 3You run Docker rootless, the host value is 0, and containers can still reach the network.Rootless Docker prints the warning although forwarding worksFix

What does the error look like?

  • WARNING: IPv4 forwarding is disabled
  • IPv4 forwarding is disabled. Networking will not work.

Cause 1 of 3

A sysctl file sets ip_forward to 0 (common on hardened servers)

1Check

Docker turns forwarding on when it starts, but a sysctl file that systemd-sysctl applies later can set it back to 0. The Moby maintainers described exactly this ordering race on a host hardened to a CIS benchmark.

systemctl status systemd-sysctl --no-pager

2Fix

Make the setting 1 in a file that sorts after the one that sets 0 (the last file name in lexical order wins), or exempt IP forwarding from the baseline, because Docker networking depends on it. Then apply the files.

# /etc/sysctl.d/99-docker.conf
net.ipv4.ip_forward=1

3Verify

Re-apply the sysctl files, restart Docker, and read the value again.

sudo systemctl restart systemd-sysctl
sudo systemctl restart docker
cat /proc/sys/net/ipv4/ip_forward

Confirmed by man7.org

Did this fix it?

Cause 2 of 3

Docker uses the nftables backend, which does not enable forwarding

1Check

With the nftables backend Docker does not enable IP forwarding itself. If forwarding is needed and off, Docker reports an error. The same happens after a move from the iptables backend, if nothing else turns forwarding on after a reboot.

cat /etc/docker/daemon.json

2Fix

Set the sysctl yourself on the host and keep it in a file under /etc/sysctl.d. Also add firewall rules that block forwarding between non-Docker interfaces you do not want connected.

# /etc/sysctl.d/99-docker.conf
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1

3Verify

Apply the file, restart Docker and start a container.

sudo systemctl restart systemd-sysctl
sudo systemctl restart docker
docker run --rm alpine true

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 3

Rootless Docker prints the warning although forwarding works

1Check

In rootless mode the network runs in a separate namespace, and affected daemon versions read the host's value instead of that namespace's value. The Moby project fixed the wrong check and tracked it for the 29.6.0 release.

docker version --format '{{.Server.Version}}'
docker run --rm alpine wget -q -O /dev/null https://example.com && echo network ok

2Fix

If the test above prints network ok, the warning is harmless: update to a release that includes the fix. If it fails, you are in a different cause, so use the causes above.

# update Docker Engine through your package manager, then restart the Docker service

3Verify

Run the network test again after the update.

docker run --rm alpine wget -q -O /dev/null https://example.com && echo network ok

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • When you apply a hardening baseline, allow net.ipv4.ip_forward=1 on Docker hosts.
  • Keep the Docker setting in a clearly named /etc/sysctl.d file and review it after OS upgrades.
  • When you switch Docker to the nftables backend, set the forwarding sysctls in the same change.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.