Toolman

What port does MongoDB use?

MongoDB uses port 27017 over TCP.

PortProtocolNameWhat it is for
27017TCPMongoDBThe 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

Port 27017 in full · Every service · All port numbers