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

**Code:** `Can't connect from another host (bindIp 127.0.0.1)` · **Category:** MongoDB · **Seen on:** MongoDB, Linux

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/mongodb/bindip-remote-connection-refused)
