Port / TCP
27017MongoDB
The default MongoDB listener for driver connections, replication, and administrative tools.
If it is internet-facing: Finding 27017 open to the internet is a finding in its own right — it warrants an explanation, not just a rule.
Exposure
Trusted network only
Transport
Encryption optional
Risk if public
High
Exposure verdict
Port 27017 belongs on a trusted internal network. If a perimeter scan finds it answering, treat that as a firewall defect rather than a configuration preference.
Encryption is available but negotiated or configured rather than guaranteed. A client that does not insist on it will silently fall back to plaintext.
Registered with IANA on request, but bindable by any unprivileged user. Registration records intent — it does not reserve the port, so collisions between products are common.
Grouped with the other databases & caches ports so a rule written for one can be checked against its neighbours.
What actually goes wrong
2 notes- Old defaults bound to all interfaces with no authentication, producing years of leaked and ransomed databases.
- Enable authorization, bind to a private address, and require TLS for connections that leave the host.
Recommended firewall rule
Allow only from 10.0.0.0/8, drop the rest
Swap in the CIDR your administrators or application tier actually come from — the point is that the default answer is no.
ufw
sudo ufw allow from 10.0.0.0/8 to any port 27017 proto tcpiptables
sudo iptables -A INPUT -p tcp -s 10.0.0.0/8 --dport 27017 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 27017 -j DROPIf you do need it open to everyone
sudo ufw allow 27017/tcpWrite down why. An unexplained allow rule outlives the person who added it, and the next reviewer has no way to tell a deliberate exception from an accident.
Check what is really there
Listening locally
sudo ss -tlpn 'sport = :27017'The bind address is the answer that matters: 127.0.0.1 is local-only, 0.0.0.0 and :: mean every interface.
Listening (macOS)
sudo lsof -nP -iTCP:27017 -sTCP:LISTENmacOS ships lsof rather than ss; this names the owning process and user.
From outside
nmap -sV -Pn -p 27017 <host>A version probe confirms whether MongoDB is actually what answers, rather than trusting the number. Only scan hosts you are authorised to test.
Reachability
nc -vz <host> 27017The quick yes/no when you only need to know whether a path exists through the firewall.