Can't connect from another host (bindIp 127.0.0.1) MongoDB Origin: Data OSI layer 4 · Transport Last updated 5 Nov 2026

MongoDB: connection refused / timed out from a remote host — mongod bindIp defaults to 127.0.0.1

MongoDB only listens on localhost by default, so remote clients can't connect.

Exact message you may see MongoDB remote connection refused bindIpmongod only listening on 127.0.0.1MongoNetworkError: connect ETIMEDOUT <remote>:27017couldn't connect to server remote host:27017 connection refusedMongoServerSelectionError: connect ETIMEDOUT
Seen on: MongoDB Linux

Meaning

Set net.bindIp: 127.0.0.1,<private-ip> in /etc/mongod.conf, restart, and open the port only to trusted hosts via firewall/security group. Enable authentication and TLS first — never expose MongoDB without auth (bindIp: 0.0.0.0 on the public internet gets hijacked).

Common causes

  • bindIp left at 127.0.0.1
  • Firewall/security group blocks 27017
  • Cloud private network not configured
  • mongod config not reloaded
  • Auth not enabled when opening

⚡ Quick fix

  1. Edit /etc/mongod.conf: net: { port: 27017, bindIp: 127.0.0.1,10.0.0.5 } and sudo systemctl restart mongod
  2. Open 27017 only to app servers
  3. Enable security.authorization: enabled

Detailed fix by platform

Linux

  1. sudo ss -ltnp | grep mongod and nc -vz DB_IP 27017 from the client

Code examples

/etc/mongod.conf

yaml
net:
  port: 27017
  bindIp: 127.0.0.1,10.0.0.5     # never 0.0.0.0 on a public IP without firewall + auth
security:
  authorization: enabled

How to diagnose

  1. Bind — Interfaces listed?
  2. Firewall — Port restricted?
  3. Auth — Enabled?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

Atlas: bad auth: Authentication failed — MongoServerError: bad auth : Authentication failed. (Atlas user / special characters in password) (MongoDB)Atlas: bad auth: Auth…BSONObj size is invalid / exceeds maximum document size (16MB) — MongoServerError: BSONObj size: 17825792 (0x1100000) is invalid. Size must be between 0 and 16793600(16MB) (MongoDB)BSONObj size is inval…CannotPullContainerError — ECS task stopped: CannotPullContainerError: pull image manifest has been retried ... / ref pull has been retried (AWS)CannotPullContainerEr…CursorNotFound: cursor id not found — MongoServerError: cursor id 1234567890 not found (CursorNotFound) (MongoDB)CursorNotFound: curso…default backend - 404 — Ingress returns "404 Not Found" / "default backend - 404" (ingress-nginx) (Kubernetes)default backend - 404DNS in pod — DNS not working inside a Kubernetes pod (could not resolve host / nslookup: can't resolve) (Kubernetes)DNS in podFailedCreatePodSandBox — Failed to create pod sandbox: plugin type="calico" failed (add): ... (FailedCreatePodSandBox) (Kubernetes)FailedCreatePodSandBoxiptables: No chain/target/match — driver failed programming external connectivity on endpoint: iptables: No chain/target/match by that name (Docker)iptables: No chain/ta…Can't con…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.