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.
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 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
bindIpleft 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
- Edit
/etc/mongod.conf:net: { port: 27017, bindIp: 127.0.0.1,10.0.0.5 }andsudo systemctl restart mongod - Open 27017 only to app servers
- Enable
security.authorization: enabled
Detailed fix by platform
Linux
sudo ss -ltnp | grep mongodandnc -vz DB_IP 27017from the client
Code examples
/etc/mongod.conf
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: enabledHow to diagnose
- Bind — Interfaces listed?
- Firewall — Port restricted?
- 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:
Similar errors
- Atlas: bad auth: Authentication failed MongoServerError: bad auth : Authentication failed. (Atlas user / special characters in password)
- BSONObj size is invalid / exceeds maximum document size (16MB) MongoServerError: BSONObj size: 17825792 (0x1100000) is invalid. Size must be between 0 and 16793600(16MB)
- CannotPullContainerError ECS task stopped: CannotPullContainerError: pull image manifest has been retried ... / ref pull has been retried
Most viewed in MongoDB
- Document failed validation MongoDB: MongoServerError: Document failed validation (code 121)
- MongoParseError MongoDB: MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
- bad auth : Authentication failed MongoDB: MongoServerError: bad auth : Authentication failed (code 8000 / 18)
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 5 Nov 2026