Firewalld Configuration on Centos 7.2

Phyticist picture Phyticist · Jun 2, 2016 · Viewed 8.1k times · Source

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.

Answer

chenrici picture chenrici · Mar 12, 2018

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