What port should i use for mongodb?
Show The following table lists the default TCP ports used by MongoDB:
Though this is - strictly speaking - not a programming related question and would rather belong on http://dba.stackexchange.com or on http://www.serverfault.com, I will answer it, since it might be useful for programmers. Putting software on a nonstandard port does in no way enhance security from a conceptional point of view. This is because a determined attacker (I don't talk of script kiddies) will do a well hidden port scan on the machines of your network anyway. And since most servers identify who they are and what they do, it is quite easy for an attacker to determine which software is running on which open (aka reachable) ports of a machine. Actually, there are signature available, mapping the answers of various versions of the most important software (openssh, Apache httpd and MySQL) to known vulnerabilities of said versions of the software. Putting a software on a nonstandard port for security reasons does not help. And it creates problems for the network and system administrators to configure the firewalls and system services correctly, resulting in increased maintenance work. As @senfo correctly pointed out, you should use firewalls to restrict access. Measures offered by MongoDB to enhance security are authentication and authorization as well as keyfiles. In order to prevent sniffing attacks, you might want to use a tool like stunnel or recompile the MongoDB packages you plan to use with SSL support. So, keep the ports where they belong to: at their defaults. Introduction to MongoDB portMongoDB port is the address where the protocol tries to establish the connection. There are some default ports supported by MongoDB such as 27017. However, we can also explicitly modify the default ports. MongoDB is a request-response kind of application that involves establishing a connection between its client and server involving multiple requests and responses which is based on sockets and the protocol used is TCP/ IP (Transport Layer Protocol) socket protocol. For exchanging the information, data, requests, and responses the sockets have their associated ports. Which port needs to be considered while communicating depends upon the internal configuration settings. In this article, we will have a look at some of the default ports used by Mongo DB and also have a look at the process of changing the default ports. List of default portsLet us have a look at all the related default ports used by Mongo DB database management system. For this check out the following table –
Syntax: Let us understand the syntax of the URL used for establishing the connection. Consider a sample URL for studying the various components present inside it –
Let us discuss one by one all the components used in the above statement – Mongodb:// – This is the definition of the protocol. Hence, when using the mongo db the protocol specification is given by using mongodb:// Localhost:27017c- It is the part that represents the address of the server with which we are trying to establish the connection. Localhost – It is the address of the server 27017 – This is the port address that is considered for identification of socket by default when using MongoDB. Changing the default port address of MongoDB There are plenty of ways using which we can modify the port which is being used by Mongo DB for a specific task. Before you go for modifying any of the default ports to a port of your choice, you need to make sure that there is no other application that is using the same port number you are trying to set the Mongo DB port to. Let us have a look at some of the methods to change the default port address one by one in the upcoming section – First Method We will have to begin the server of Mongo DB by specifying – port argument in its statement while firing the command. For this, we have to make sure that while opening the command prompt we open it with administrator privileges and role, and then we have to navigate to the bin folder present in Mongo DB installation directory. Further, you need to enter the command specified below –
After firing the above command, you will observe that the connection waiting message is displayed as shown below – Further, the next step to perform is to open a new instance of the command prompt with the role and privileges of the administrator and then navigate to the bin folder of MongoDB installation directory and type the same command that is shown below –
The output of the above command will be as shown below which means that the mongo DB is now running on the specified port address 20000 instead of its default port address – In this way, by using the above methodology and commands we can initiate the Mongo DB server at any custom port as per our requirement. Only the thing to be taken care of is that there should not be any service or application that is running on the port on which we are trying to establish the Mongo DB connection. Second Method In the second method, we will have to modify the configuration file of Mongo DB and modify the port address specified in the configuration details. For this, you will have to follow the below steps –
The output of above command is as shown in the below image – Let us have a look at one of the sample configuration files. For this refer to the below image. We can observe that the file contains the port specification as 20000 which was kept as per our requirement. You can change this port value by specifying the required port number in the commands used above. We can now observe the process of changing the port is successfully completed. By using either of the two methods, you can change the default port number of Mongo DB to whichever address you want. After this, your next step will be establishing the connection with Mongo DB. ConclusionThe default port of the Mongo DB is already predefined and set for the Mongo and Mongod instances when using configsvr or shardvsr option while runtime operations or even when observing the status in web pages which are mentioned in the table. We can even modify the port number by using either of the two methods specified in the above article. Recommended ArticlesThis is a guide to MongoDB port. Here we discuss the introduction, List of default ports with some methods respectively. You may also have a look at the following articles to learn more –
What ports does MongoDB use?MongoDB uses TCP as its transport layer protocol. The predefined default port for connection is 27017.
Why is port 27017 used?The port 27017 is used for mongoDB server, an important module for EAP Controller.
How do I connect to a MongoDB server?How to connect to your remote MongoDB server. Set up your user. First ssh into your server and enter the mongo shell by typing mongo . ... . Enable auth and open MongoDB access up to all IPs. Edit your MongoDB config file. ... . Open port 27017 on your EC2 instance. ... . Last step: restart mongo daemon (mongod). How do I access MongoDB?To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.
|