Mongodbsrvr is a RHEL 8 virtual machine hosted in Azure. Inbound, outbound rules attached to this NSG allow all the ips from all ports and protocols.
The Port is opened in the server.
[root@mongodbsrvr etc]# netstat -lntu |grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN
mongod.conf
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# wiredTiger:
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
security:
authorization: enabled
[root@mongodbsrvr etc]# systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2023-11-15 08:46:51 UTC; 2s ago
Docs: https://docs.mongodb.org/manual
Main PID: 463975 (mongod)
Memory: 170.0M
CGroup: /system.slice/mongod.service
└─463975 /usr/bin/mongod -f /etc/mongod.conf
Nov 15 08:46:51 mongodbsrvr systemd[1]: Started MongoDB Database Server.
Nov 15 08:46:51 mongodbsrvr mongod[463975]: {"t":{"$date":"2023-11-15T08:46:51.898Z"},"s":"I", "c":"CONTROL",>```
mongodb user created with the below roles and settings.
admin> db.getUsers({
... showCredentials: true
... })
{
users: [
{
_id: 'admin.dbadmin',
userId: new UUID("f69a6392-8837-4313-97a4-9170e8755bdb"),
user: 'dbadmin',
db: 'admin',
credentials: {
'SCRAM-SHA-1': {
iterationCount: 10000,
salt: 'tkH2uB48K2CzzkzNNkgplA==',
storedKey: 'JtDTL280008DoNBIGw8yVbEv2p8=',
serverKey: 'zperJRJSzGITJIiK0KNXhKfQFeQ='
},
'SCRAM-SHA-256': {
iterationCount: 15000,
salt: 'cE7Z8Iuk3VNjAK2PySJgvZ1SWYTo692fsWK6Nw==',
storedKey: 'Rp0uZKm/TeLHbQMb2pU6Caiqb71cHrF35oEvxwtIFVI=',
serverKey: '8kbAHScLS3xrSHf5yRHF2f87HPUBx4ArfezEGIFe6uI='
}
},
roles: [
{ role: 'readWriteAnyDatabase', db: 'admin' },
{ role: 'userAdminAnyDatabase', db: 'admin' },
{ role: 'dbAdminAnyDatabase', db: 'admin' }
],
mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ]
}
],
ok: 1
}
admin>
Local connection works fine.
[root@mongodbsrvr etc]# mongosh
Current Mongosh Log ID: 655487392c55b0ea8b8e2626
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.2
Using MongoDB: 6.0.11
Using Mongosh: 2.0.2
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
test>
But while connecting remotely from my laptop using a compass I got the below error.
connect ETIMEDOUT 40.76.229.226:27017