I am currently using port 27017 for mongodb and everything is working proper. We want to configure new port for security purpose.
Can you help me how we can configure this?
This way,
While startiing mongo pass port argument
mongod --port your desired port
mongod --port 19000
Start Mongo with port:
mongo --port your desired port
mongo --port 19000
2.change the port in the mongodb.config file and pass the config file as input.
port = Ur desired port
Change the /etc/mongod.conf file for persistence
change net: section as
net:
bindIp: 127.0.0.1
port: <The port number you want to listen>
Command line option --port <port> can also be used but will not remain persistent and you need to specify the same every time you start Mongod
Related
Something wrong happens when I'm trying to setup mongod.conf for connection from remote server.
When I paste my server ip address Mongo doesn't allow connection from it.
# network interfaces
net:
port: 27017
bindIp: 111.111.11.111 #my server ip
When I allow connection from any server, mongo allows to connect from my server.
net:
port: 27017
bindIp: 0.0.0.0
I want to have an access to Mongo from localhost and from my server. I'm trying to paste these ip's both but Mongo allow connection from localhost only.
net:
port: 27017
bindIp: 127.0.0.1 111.111.11.111
What's wrong and how to use bindIp ?
According to documentation the value is a string, i.e. a single value.
Try following:
Use only 111.111.11.111, localhost may work by default anyway.
Try these ones:
net:
port: 27017
bindIp:
- 127.0.0.1
- 111.111.11.111
net:
port: 27017
bindIp: 127.0.0.1,111.111.11.111
net:
port: 27017
bindIp: [127.0.0.1,111.111.11.111]
Otherwise use a firewall, either an external one or the internal firewall of your operating system.
I thought there has to be the IP address of the remote server. It's not right. There can be ip addresses of the network interfaces of the current machine.
Looking for here:
ifconfig -a | grep "inet"
I have mongoDB container which runs on azure VM, and I'm trying to connect it to my mongoDB compass.
I have Public IP address to my VM, the port 27017 is open in my vm and also in my mongo container.
I have authentication, so to connect my mongo I'm Enter the mongo container and write the command "mongo -u username -p password --authenticationDatabase admin" (Relevant).
When I'm trying to connect I get "connection timed out" error message.
docker container ls
Open ports on the VM
My compass login page
I solved it by changing the configuration file of the mongoDB container.
Step 1:, make sure port 27017 is open on the VM:
Step 2:, create a mongoDB configuration file as below, name it mongod.conf, and change the bindIp field to your host IP (change < Host IP> to your host IP).
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /data/db
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,<Host IP>
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
security:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
Step 3: Copy the mogod.conf file into your VM, and save it wherever you want.
Step 4: Run the command:
docker run -d -v <FolderPathOnTheVM>/mongod.conf:/etc/mongod.conf -p 27017:27017 mongo -f /etc/mongod.conf
Make sure you changed the < FolderPathOnTheVM> to the path of the mongod.conf file on the VM (The path of step 3).
Do netstat on 27017 and check if its running on localhost or public IP. If its running on localhost, then change it to your public IP in mongodb config file and then retry. Also, telnet from your local machine to the mongodb IP and port to check if its working locally.
I am running Mongodb on AWS windows instance, I changed my config setting as following:
net:
port: 30000
bindIp: 0.0.0.0
As far as my knowledge, Server should get started on port 30000, it can listen request from other ip as well
However, on restarting mongod, it is still running on localhost and listening to port 27017
I have the same problem with you. What I did is a workaround it. I start the service with specifying the port and ip.
mongod --auth --port 30000 --dbpath /data/db --bind_ip_all
Basically I'm trying to change the default port of mongodb by changing the port in mongod.conf file . Then I'm starting the db by mongod --fork --logpath /var/log/mongod.log command . The db is being started in the background but the problem is it's still running on the port 27017.
mongod.conf:
net:
port: 15031
bindIp: 192.168.1.7
Add the parament mongod -f /etc/mongod.conf to specify the configuration file.
net:
port: 15031
Configuration file is written in YAML
You have to use SPACE characters instead of TAB characters for indentation.
Or pass the --port argument when you start mongod
mongod --port 15031
Got errno:61 Connection refused when I type mongo --port 27003 on mac osx terminal
but simply mongo it's working fine
By default mongod runs on 27017 port.
When you type "mongo" it connects to that port and not 27003.
Try this "mongo --port 27017"
If you want to run mongod on a different port
Open : /etc/mongodb.conf
Change
port: 27003
Restart mongod service
sudo service mongod restart