MongoDB Remote connection Error - connect ETIMEDOUT 40.76.229.226:27017

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

Hi @Dhamodharan_23277 and welcome to MongoDB community forums!!

In order to understand the error in depth, could you help me with the below information:
1.

The IP address that is mentions here, is this a public IP or a Private IP address for the service?
2. Are you able to connect from the remote shell server?
3. Can you ping the IP address from the remote server mentioned above and confirm if you are able to connect?
4. Does this timeout happens in all the login or does it happen under certain circumstances. ?

You can also refer to the below related post for more informations.

  1. Issues accessing MongoDB remotely
  2. Cannot connect remotely to mongodb - #2 by steevej

Regards
Aasawari

Hi , Thanks for the response and sorry about the late reply. Issue is resolved after disabling the firewall daemon in the linux server.

systemctl disable firewalld

Thanks
Dhamodharan L

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.