Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb listen to localhost and lan ip only

I have an Ubuntu server with mongodb installed. Is it possible to configure mongodb in such a way that I can connect to it using only localhost and its LAN IP address.

The default mongo configuration works fine for connecting using localhost:

bind_ip = 127.0.0.1

If I change to the LAN IP, then I am only able to connect using that IP, and not using localhost:

bind_ip = 10.10.10.10

If I try to add both, then I get an address in use error and doesn't start:

bind_ip = 127.0.0.1, 10.10.10.10

If I remove the bind_ip setting, then both work, but I am also able to connect with the servers external IP (which I do not want).

#bind_ip = 127.0.0.1, 10.10.10.10

So, how can I tell mongo to listen on the local interface, but allow connections from both localhost and its LAN IP?

like image 732
pqvst Avatar asked Jan 09 '23 03:01

pqvst


1 Answers

With the help of @wdberkeley's comment, I realized that the problem was the space after the , in the list of IP addresses the bind to. However, it seems that this issue only affects the old config file format (not YAML).

# This Works:
bind_ip = 127.0.0.1,10.10.10.10

# This doesn't work:
bind_ip = 127.0.0.1, 10.10.10.10
like image 104
pqvst Avatar answered Jan 16 '23 22:01

pqvst