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:
And change the value to your new port number:
Then you have to restart the mongod service:
systemctl restart mongod.service
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