Why can't I access my CouchDB instance externally on Ubuntu 9.04 server?

Update: I got it working now. Jim Zajkowski's answer helped me detect that my /etc/init.d/couchdb reboot calls weren't actually rebooting the instance. After I manually killed the CouchDB processes and started a new instance, it picked up the required BindAddress change.

I have installed CouchDB via

aptitude install couchdb

From my server, I can connect via

telnet localhost 5984

and execute RESTful commands. When I try to access the server from another machine on our network or from a machine external of our network, I get a The connection was reset error. I've set up port forwarding on the router, and the server is otherwise accessible via Apache, Tomcat, SSH, etc.

I'm new to Linux/Ubuntu, so I wasn't sure if there was a default firewall blocking the connection, so I ran:

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

but it didn't help.

Here is the dump from running iptables -L -n -v

Chain INPUT (policy ACCEPT 2121K packets, 1319M bytes)
 pkts bytes target     prot opt in     out     source               destination
   70  3864 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:5984
    9  1647 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8080
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8080

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 1708K packets, 1136M bytes)
 pkts bytes target     prot opt in     out     source               destination

I assume the bytes showing as transfered for 5984 are due to my localhost connection.

Here is the dump from running netstat -an | grep 5984

tcp        0      0 127.0.0.1:5984          0.0.0.0:*               LISTEN

I configured couch.ini to have "BindAddress=0.0.0.0" and rebooted, so it should be listening on all interfaces. When I run "sudo /etc/init.d/couchdb stop" then run netstat, however, I still see the above entry. It looks like CouchDB isn't actually stopping at all. This may explain my problem, because it means it may mean that CouchDB never actually rebooted and never picked up the BindAddress change.

I manually killed the CouchDB process and started it up again. Now netstat shows:

 tcp        0      0 127.0.0.1:5984          0.0.0.0:*               LISTEN
 tcp        0      0 127.0.0.1:5984          127.0.0.1:35366         TIME_WAIT

I still can't connect though, even from another machine on the LAN.


Solution 1:

What does netstat -an | grep 5984 say? Does it say 127.0.0.1:5984 or *:5984? If it's 127.0.0.1, then couchdb needs to be set to listen to either all interfaces.

Solution 2:

You have to change the bind_address in /etc/couchdb/default.ini. Then restart the service and try again.

Solution 3:

I noticed that in order for this to work you must manually kill the running erlang process for some reason.ps ax | grep beam ought to reveal the erlang process, you should get something along lines of 0:00 /usr/lib/erlang/erts somewhere in the output. If you kill this process and then run /etc/init.d/couchdb restart the new config file will be loaded.

Solution 4:

On home PC/Mac run this command:

ssh -L 5984:localhost:5984 YOUR-SERVER-IP-HERE

next open in your browser localhost:5984/_utils ... It works for me