3

I've recently installed mongodb on my CentOS 6 VM running on Vagrant.

I added port forwarding to Vagrantfile to forward the mongo port

config.vm.forward_port 27017, 127017

I configured mongod to start automatically when the server starts and have confirmed that the service starts as intended.

however when i run mongo localhost:127017 from my host machine (not vagrant) i get the following error

MongoDB shell version: 1.8.2
connecting to: localhost:127017/test
Fri Jan 20 13:58:28 getaddrinfo("127.0.0.1") failed: nodename nor servname provided, or not known
Fri Jan 20 13:58:28 Error shell/mongo.js:81
exception: connect failed

any ideas?

khr055
  • 28,690
  • 16
  • 36
  • 48
joseym
  • 1,332
  • 4
  • 20
  • 34
  • I'm not able to reproduce using centos 6.2 w/ mongodb 2.0.2. What kind of box are you running and where did you get it from? – Tyler Brock Jan 24 '12 at 15:33
  • This issue comes from trying to query the mongo server on vagrant (centos 6) from the host machine (MacOSX) – joseym Jan 24 '12 at 17:54
  • do you have any other ports forwarded that are working (80, 22)? Also, port forwarding requires a virtual machine restart, or VirtualBox won't pick up the ports. – Adam Comerford Jan 24 '12 at 18:41
  • Does telnetting into that port form OSX work for you? I think it could be a firewall issue, and unless you setup the virtualbox box yourself I wouldn't trust it. Could have all sorts of issues. – Tyler Brock Jan 24 '12 at 23:41
  • Adam C - Yes, port 80 successfully forwards to 8080 and i have rebooted the vm several times. – joseym Jan 25 '12 at 16:38
  • My next suggestion would be to try connecting to that port (27017) locally from within the VM - essentially that will prove that mongod is running and listening (also "lsof -i | grep mongod") - once that is done you have essentially proved it some sort of forwarding/firewall issue – Adam Comerford Jan 25 '12 at 23:29

4 Answers4

19

You will need to set the mongod bind_ip to 0.0.0.0 instead of 127.0.0.1 (which is the loopback address) so that all interfaces can access it.

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
9

TCP port numbers are 16-bit unsigned, which mean the max value is 65535 (2^16), and you're trying with 127017.

milan
  • 11,872
  • 3
  • 42
  • 49
0

Can you connect to the mongo server from vagrant ssh? If not, you might want to make sure that mongod is running.

Do you have an ip_bind set up in your mongodb.conf or mongod startup script? (If you do, you might want to unset it--not exactly sure how vagrant's port forwarding works, but this might be what's causing the problem.)

Eve Freeman
  • 32,467
  • 4
  • 86
  • 101
  • yes, I am able to do a mongo query from vagrant ssh. This issue comes from trying to query the mongo server from the host machine (MacOSX) – joseym Jan 24 '12 at 17:53
-3

bind_ip to 0.0.0.0 does not work. Try bind_ip=127.0.0.1,10.0.0.25, that worked for me.

campagnolo_1
  • 2,710
  • 1
  • 17
  • 25
ttanai
  • 1