I am trying to bind multiple IP to mongodb config file, one is 0.0.0.0
and other is 127.0.0.1
. I did the following change in configuration file
/etc/mongod.conf
# network interfaces
net:
port: 27017
bindIp: "0.0.0.0,127.0.0.1"
Than I reloaded the configuration by the following command
sudo mongod --config /etc/mongod.conf
Than checked if the server is listening on localhost as well or not by the following command.
netstat -tlpn
It shows the output only for 0.0.0.0
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:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN -
Why is it not listening to localhost as well?
0.0.0.0
means all IP v4 addresses (which includes127.0.0.1
). You could achieve the same outcome by not specifying anybindIp
address, as "bind to all IP addresses" is the default behaviour as at MongoDB 3.2. Have you tried connecting tomongod
via localhost, and if so was there any error? What are you trying to achieve with multiple IP addresses? ThebindIp
configuration determines what IP address(es)mongod
listens on if your server has multiple addresses, but you still need to configure appropriate firewall settings. – Stennie Nov 29 '15 at 3:21