1

Infrastructure : I have 3 virtual machines ip in a DMZ on a same lan. one of them is running mongodb . OS : RHEL

Mongod.conf : I have commented out the bindIP option

But still mongodb is not accpeting connection from other servers on LAN. Telnet is failing from other 2 servers

the netstat output is

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      24251/./mongod
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1508/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1621/master
tcp6       0      0 :::22                   :::*                    LISTEN      1508/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1621/master

i m guessing the foreign address for 27017 port should also look like ":::*" I m not able to catch the problem here.Please help!

  • The :::* syntax is the IPv6 equivalent of IPv4's 0.0.0.0:* (aka "all addresses"). I would check for firewall rules that may be blocking inbound access to 27017. – Stennie Aug 1 '16 at 22:35
  • @Stennie the local firewall is already disabled – Tarik Setia Aug 2 '16 at 13:53
3

If you have firewall running, allow connections on port 27017, MongoDB default port.

Not sure which RHEL version you are running so below commands might change.

1. Any connections can connect to MongoDB on port 27017

iptables -A INPUT -p tcp --dport 27017 -j ACCEPT

2. Only certain IP can connect to MongoDB on port 27017

iptables -A INPUT -s <ip-address> -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -d <ip-address> -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT


For Eg:

    iptables -A INPUT -s 192.168.6.100 -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
    iptables -A OUTPUT -d 192.168.6.101 -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT

Also i personally believe commenting bind option is not a good idea.

Instead you can use below in /etc/Mongod.conf :

# Listen to local and LAN interfaces.
bind_ip = 127.0.0.1,x.x.x.x, x.x.x.x

and then

service mongod restart
0

Alongwith the above Answer provided by @Sachin Singh

Please Check /etc/hosts file and add your IPaddress and Hostname, not sure which RHEL version you are running so below commands might change.

Ex:

 192.168.6.100        hostname.domainname.com       hostname 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.