What port does MongoDB use?
MongoDB uses port 27017 over TCP.
| Port | Protocol | Name | What it is for |
|---|---|---|---|
| 27017 | TCP | MongoDB | The default MongoDB port. |
Exposing it
Older versions bound to all interfaces with no authentication, which led to mass ransoming of exposed databases. Enable auth and bind privately.
Checking it is listening
sudo lsof -i :27017 # macOS, Linux
netstat -ano | findstr :27017 # Windows
nc -zv host 27017 # from elsewhere
An "address already in use" error on a port nothing appears to be holding usually means the socket is in TIME_WAIT rather than that a process has it — the ports reference covers that and the ephemeral range.
Frequently asked questions
What port does MongoDB use?
MongoDB uses port 27017 over TCP. The default MongoDB port.
Is port 27017 safe to expose to the internet?
Older versions bound to all interfaces with no authentication, which led to mass ransoming of exposed databases. Enable auth and bind privately.
How do I check whether MongoDB is listening?
sudo lsof -i :27017 on macOS or Linux, netstat -ano | findstr :27017 on Windows. From another machine, nc -zv host 27017 says whether anything answers.
Other services
- What port does Redis use?
- What port does Memcached use?
- What port does Elasticsearch use?
- What port does DNS use?
- What port does NTP use?
- What port does SMB use?
- What port does NFS use?
- What port does SNMP use?
- What port does Syslog use?
- What port does RabbitMQ use?
- What port does Prometheus use?
- What port does SMTP use?