4

I have installed MongoDB on my CentOS 7.2 VPS and trying to access to the DB via Robomongo from my client. However, when I try to connect the server from the 27017 port, I get "Network is unreachable" error.

I have enabled the firewalld on the server and added an exception for 27017 port.

firewall-cmd --list-all

Result:

Result:

I got this result after I've permanently added the exception and reloaded the firewalld via --reload.

When I query the port by using:

firewall-cmd --query-port=27017/tcp

I get a "yes" from the system. However when I try to connect via Robomongo or query the port via a port checker service like http://ping.eu/port-chk/ I get a negative result.

Do you have any suggestions regarding to my case?

Thank you.

Phyticist
  • 566
  • 1
  • 8
  • 20

2 Answers2

15

I had the same issue, but running mongod in a Centos 7 Vm.

First i had to open the mongodb port with firewall-cmd:

 sudo firewall-cmd --zone=public --add-port=27017/tcp --permanent

 sudo firewall-cmd --reload

Then i had to change the net Configuration entry in /etc/mongodb.conf See also : https://docs.mongodb.com/manual/reference/configuration-options/#net-options

I removed the bindIp: Entry and added bindIpAll: true

net:
  port: 27017
  bindIpAll: true

Using bindIp: according the documentation you need to enter:

The IP addresses and/or full Unix domain socket paths on which mongos and mongod should listen for client connections. You may attach mongos and mongod to any interface. To bind to multiple addresses, enter a list of comma-separated values

The default is:

net:
  port: 27017
  bindIp: 127.0.0.1

which means that mongodb only listens to localhost

4

I was able to solve the issue with the help of the VPS support team via performing the steps below:

Execute,

ss -plnt

to see the socket statistics. My output was like below:

Socket Statistics

As can be seen from the result mongod process is listening 27017 port only on 127.0.0.1 . In order to configure that binding edit the mongod.conf in /etc/ directory and comment out the line

bindIp: 127.0.0.1

Restart the mongodb service and everything should be fine.

Phyticist
  • 566
  • 1
  • 8
  • 20