change mongodb default port
change mongodb default port

How to Change MongoDB Default Port in 🐧 Ubuntu/CentOS/Windows

Summary:

The default port that MongoDB runs on is 27017 and to change it we have to edit MongoDB’s main configuration file, which for Linux Ubuntu/CentOS is mongod.conf and for Windows its mongod.cfg.

The default port that MongoDB runs on is 27017 and to change it we have to edit MongoDB’s main configuration file, which for Linux Ubuntu/CentOS is mongod.conf and for Windows its mongod.cfg.

So open the file with your favorite editor and locate the line that says:

port: 27017

And change the value to your new port number:

port: 25000

Then you have to restart the mongod service:

systemctl restart mongod.service

or

service mongodb restart

In CentOS you also need to configure Selinux to allow new port:

semanage port -a -t mongod_port_t -p tcp 25000

whoami
Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.