Cannot Get Install To Work

I’ve spent hours trying to get MongoDB to work.

My server was hacked after I reset the firewall and forgot to disable the port. After, Mongo wasn’t starting and I chose to reinstall. So I’ve tried to completely uninstall everything many times, and time after time it just doesn’t work!

When I try to install latest/6.0, it just fails to start with the error:
“mongod.service: Failed with result ‘core-dump’…”
“mongod.service Failed with result core-dump / Mongodb stop working: Aborted (core dumped)”

So alright, I looked up some guides and apparently that was an issue with versions 5.0+. So I installed 4.4.

Now, when starting I either get the error:
“mongod.service: Main process exited, code=exited, status=14/n/a”

But now, I’m just getting NO connection! I just cannot connect to it. Through localhost, externally (setting bind port to & allowing firewall access to my ip), or any other way. Keep in mind, I’ve completely removed any SHRED of a trace of mongo from my machine with find, before reinstalling at least 7 times now.

I’m just about done, I cannot get a connection. ‘mongo’ just times out, every time. I’ve fiddled with the bindIp option in the setting then restarting the service, or even the machine to no success.

Starting mongodb (systemctl start mongod && systemctl status mongod):

● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-10-03 19:47:05 EDT; 3s ago
   Main PID: 12681 (mongod)
     Memory: 157.3M
     CGroup: /system.slice/mongod.service
             └─12681 /usr/bin/mongod --config /etc/mongod.conf


MongoDB shell version v4.4.17
connecting to: mongodb://
Error: couldn't connect to server, connection attempt failed: SocketException: Error connecting to :: caused by :: Connection timed out :
exception: connect failed
exiting with code 1

cat /var/log/mongodb/mongod.log:

Any help would be much appreciated!

Mirror link

Hi @Cooper, and welcome to the MongoDB Community forums! :wave:

Sorry to hear you’re having so much trouble in getting MongoDB up and running once more on your system.

From the log file we can see on line 27 that the server is up and listening:

{"t":{"$date":"2022-10-03T19:49:05.268-04:00"},"s":"I",  "c":"NETWORK",  "id":23016,   "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}

On line 6 we can see that the config file used to start MongoDB up is binding to only IP on port 27017:

{"t":{"$date":"2022-10-03T19:49:04.959-04:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"config":"/etc/mongod.conf","net":{"bindIp":"","port":27017},"processManagement":{"timeZoneInfo":"/usr/share/zoneinfo"},"storage":{"dbPath":"/var/lib/mongodb","journal":{"enabled":true}},"systemLog":{"destination":"file","logAppend":true,"path":"/var/log/mongodb/mongod.log"}}}}

What I don’t understand is why you are not able to connect from that machine using mongo.

Can you try running the following commands from the machine that is running the mongod process and paste the results here:

  • telnet 27017
  • netstat -na | grep 27017

Hey, thank you so much for the reply!
The output from the commands are:

telnet 27017:
This command didn’t work with a hostname error (telnet: could not resolve Servname not supported for ai_socktype), but trying telnet 27017 resulted in no response.

netstat -na | grep 27017:

tcp        0      0*               LISTEN     
unix  2      [ ACC ]     STREAM     LISTENING     42857    /tmp/mongodb-27017.sock

I’m equally as confused, as clearly Mongo did bind from what I’ve looked at, yet no response. I’m wondering if somehow the firewall is messing with localhost connections? I have somewhat messed it up trying to restore it. Thanks again for the response.

Thanks for posting the results Cooper.

The results from netstat -na | grep 27017 does indeed show that there is a service listening on localhost port 27017. It is shows that it’s accepting requests from any host/port combination (the* part).

At this time I would say look at the firewall as you proposed. MongoDB doesn’t appear to be the problem, so it’s the connection between the client (mongo / mongosh) and the server (mongod). You could temporarily disable your firewall for testing purposes. If you are able to connect with the firewall disabled, then you can be reenable it and try to figure to the right set of rules to keep unwanted traffic out, but allow the connection to the MongoDB instance.


Disabling the firewall did work! I cannot believe I didn’t think of trying that. I guess I will try to wipe my firewall rules and start again.

Thank you so much for the help!

1 Like

Hi @Cooper,

The MongoDB manual has some information on Configuring Linux iptables Firewall for MongoDB that may be a helpful starting point.

I also recommend reviewing the MongoDB Security Checklist for common security measures.



Thanks for the iptables link.

1 Like

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