bitlvl
EN

Port 27017 MongoDB · TCP

MongoDB. Historically bound to all interfaces with no authentication (changed to localhost-only in 3.6), which produced waves of "MongoDB ransom" incidents where exposed databases were wiped and a note left behind.

Port27017
TransportTCP
ServiceMongoDB
CategoryDatabases and caches
Rangeregistered (1024–49151)
EncryptedOptional, must be configured
ExposurePrivate network or VPN only

What runs on port 27017

MongoDB. Historically bound to all interfaces with no authentication (changed to localhost-only in 3.6), which produced waves of "MongoDB ransom" incidents where exposed databases were wiped and a note left behind. Enable authorization, bind to private addresses, use TLS, and use MongoDB Atlas' IP allow-list if hosted. 27018 is for shards, 27019 for config servers.

Software that uses it: MongoDB · MongoDB Atlas · FerretDB (compatible) · mongosh, Compass (clients)

Should port 27017 be open?

Private network or VPN only. Nothing good comes from this port being reachable from the internet. Keep it on an internal network, reach it over a VPN or an SSH tunnel, and firewall it from everything that does not need it.

Check port 27017

# on the host: is anything listening, and which process?
ss -ltnp 'sport = :27017'
sudo lsof -i :27017

# from another machine: is it reachable?
nc -zv host 27017
nmap -p 27017 host
curl -v telnet://host:27017      # raw TCP connect test, Ctrl-C to leave

A port that answers from the internet when it should not is the finding; nmap from a machine outside your network (or a VPS) is the honest test, because scans from inside the LAN pass the firewall you are trying to verify.

Allow or block port 27017

# ufw (Ubuntu/Debian)
sudo ufw allow from 10.0.0.0/8 to any port 27017 proto tcp
sudo ufw deny 27017/tcp

# nftables
nft add rule inet filter input ip saddr 10.0.0.0/8 tcp dport 27017 accept
nft add rule inet filter input tcp dport 27017 drop

# iptables (legacy)
iptables -A INPUT -p tcp --dport 27017 -s 10.0.0.0/8 -j ACCEPT
iptables -A INPUT -p tcp --dport 27017 -j DROP

# firewalld
sudo firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=10.0.0.0/8 port port=27017 protocol=tcp accept'

Replace 10.0.0.0/8 with the networks that need access. Allowing by source address is the rule that matters; "allow 27017" with no source is just "open".

Related ports

Part of the port number reference. Ports are 16-bit numbers; see also the subnet calculator and the packet decoder, which shows ports inside TCP and UDP headers.

Questions

Is port 27017 TCP or UDP?

TCP. MongoDB is a connection-oriented protocol; there is no UDP service on 27017 by default (a scanner reporting UDP 27017 open is usually seeing a filtered port).

Is port 27017 encrypted?

Optional, must be configured. Turn encryption on in the service configuration before using it across any network you do not control.

How do I check whether port 27017 is open?

On the server, ss -ltnp (or -lunp for UDP) shows whether something listens on 27017 and which process. From another machine, nc -zv host 27017 or nmap -p 27017 host tests reachability. "Open" in a scan means something answered; a firewall usually makes the port filtered (no answer) rather than closed (RST).

Can MongoDB run on a different port?

Yes; the number is a convention, not a requirement. Changing it reduces log noise from scanners but does not add security, and every client, firewall rule and monitoring check then needs the new number. Keep the default unless you have a concrete reason.