Home/Network Ports/Port 27017
TCP · Port 27017IANA Registered

Port 27017 — MongoDB

Default TCP port for the MongoDB document-oriented NoSQL database system.

⚡ Primary Use Cases & Environments

  • ✓MERN / MEAN stack web applications
  • ✓NoSQL document storage clusters

🛡️ Security & Vulnerability Analysis

Historically, older MongoDB versions defaulted to no authentication and bound to all network interfaces, causing massive public data leak databases. Always enable "security.authorization: enabled" in mongod.conf and bind strictly to localhost or private VPC networks.

🔧 Network Diagnostics & Inspection

1. Check Active Listening Sockets (Local Host)
Terminal Command
$ sudo ss -tuln | grep :27017
Inspects whether any local process daemon is bound to port 27017.
2. Remote Port & Service Scan (Nmap)
Terminal Command
$ nmap -p 27017 -sV --script mongodb-info <target-ip>
Probes target IP to determine whether port 27017 is open, closed, or filtered.
3. Wireshark Capture / Display Filter
mongodb or tcp.port == 27017Wireshark Filter

🔥 Firewall Configuration Rules (UFW & iptables)

UFW (Uncomplicated Firewall)
Terminal Command
$ sudo ufw allow from <app-ip> to any port 27017 proto tcp
Applies a persistent Linux UFW firewall rule for port 27017.
iptables Command
Terminal Command
$ sudo iptables -A INPUT -p tcp -s <app-ip> --dport 27017 -j ACCEPT
Appends a direct netfilter kernel rule to the INPUT chain for port 27017.

❓ Frequently Asked Questions (FAQ)

How do I verify that MongoDB is not exposed to the public internet?

Run "sudo ss -tuln | grep 27017". The local address should strictly indicate 127.0.0.1:27017, never 0.0.0.0:27017.

How do I test connection to MongoDB from CLI?

Run "mongosh --host 127.0.0.1 --port 27017" or "nc -zv 127.0.0.1 27017".

Related Networking Tools & Guides