Mongodb no route to host while running mongo on a local machine

mongodb

I have installed MongoDB on a local machine by following this tutorial and this one as well. I used my local user (using sudo in all commands) and then I do:

sudo service mongod start

It says start: Job is already running: mongod. Then when I run this command

sudo mongo

I get

MongoDB shell version: 2.6.0
connecting to: test
2014-07-08T12:33:40.360+0200 warning: Failed to connect to 127.0.0.1:27017, reason: errno:113 No route to host
2014-07-08T12:33:40.361+0200 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed

THis is also the output of netstat -tpln

(No info could be read for "-p": geteuid()=1000 but you should be root.)
Active Internet connections (only servers)
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      -

Also this is the output of sudo /sbin/iptables -L -n

Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:80
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:5432
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:8080
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:8443
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:3306
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0            icmptype 255
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
ACCEPT     tcp  --  127.0.0.1            0.0.0.0/0            tcp dpt:27017 state NEW,ESTABLISHED
ACCEPT     tcp  --  127.0.0.1            0.0.0.0/0            tcp dpt:27017 state NEW,ESTABLISHED
ACCEPT     tcp  --  127.0.0.1            0.0.0.0/0            tcp dpt:27017 state NEW,ESTABLISHED

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  0.0.0.0/0            127.0.0.1            tcp spt:27017 state ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            127.0.0.1            tcp spt:27017 state ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            127.0.0.1            tcp spt:27017 state ESTABLISHED

I have followed several proposed solutions and never worked. Any suggestions?

I have followed several proposed solutions and never worked. Any suggestions?

Best Answer

This is most likely a firewall issue in your distro. Based on the output from iptables the mongod process is there listening to 27017 port but you need to get rid of this firewall rule:

REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

This seems to cause of the problem. To find out about it, flush the rules in iptables (-F) and/or disabling ufw in ubuntu may solve the issue.

Related Topic