Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I have a Linode server running Ubuntu 12.04 LTS and MongoDB instance (service is running and CAN connect locally) that I can't connect to from an outside source.

I have added these two rules to my IP tables, where < ip address > is the server I want to connect FROM (as outlined in this MongoDB reference):

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

And I see the rule in my IP table allowing connections on 27017 to and from < ip address > however when I try to connect from, < ip address > to my mongo database using a command like this:

mongo databasedomain/databasename -u username -p password

I get this error:

2014-07-22T23:54:03.093+0000 warning: Failed to connect to databaseserverip:27017, reason: errno:111 Connection refused

2014-07-22T23:54:03.094+0000 Error: couldn't connect to server < ip address >:27017 (databaseserverip), connection attempt failed at src/mongo/shell/mongo.js:148

exception: connect failed

Any help is VERY APPRECIATED!!!! Thanks!!!

2 Answers

0 votes
by (106k points)

To get the connection back you should try something as mentioned below:-

sudo rm /var/lib/mongodb/mongod.lock 

sudo service mongodb restart

0 votes
by (107k points)

It is an iptable conflict. Always keep in mind that you have to edit the /etc/mongod.conf file and set your bind_ip = 0.0.0.0 in order to make connections externally. And also make sure that you don't have conflicting rules in your iptable for the port mongo.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Feb 12, 2020 in Web Technology by ashely (50.2k points)
0 votes
1 answer
0 votes
2 answers
asked Oct 16, 2019 in Web Technology by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...