connecting to mongodb on ec2 instance using the private IP address





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















Im trying to connect to my MongoDB that is on my EC2 instance. I am able to connect to using the public dns with this statement:




mongoClient = new
MongoClient("ec2-3-92-197-163.compute-1.amazonaws.com", 27021);




but if I tried to replace the "ec2-3-92...." with the private IP address, as such:




mongoClient = new MongoClient("172.31.90.193", 27021);




It gives me the error:




INFO: Exception in monitor thread while connecting to server
172.31.90.193:27021 com.mongodb.MongoSocketOpenException: Exception opening socket at
com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
at
com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
at
com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
at java.base/java.lang.Thread.run(Thread.java:844) Caused by:
java.net.SocketTimeoutException: connect timed out at
java.base/java.net.PlainSocketImpl.socketConnect(Native Method) at
java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400)
at
java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243)
at
java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225)
at
java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402)
at java.base/java.net.Socket.connect(Socket.java:591) at
com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)
at
com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
at
com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
... 3 more



Exception in thread "main" com.mongodb.MongoTimeoutException: Timed
out after 30000 ms while waiting to connect. Client view of cluster
state is {type=UNKNOWN, servers=[{address=172.31.90.193:27021,
type=UNKNOWN, state=CONNECTING,
exception={com.mongodb.MongoSocketOpenException: Exception opening
socket}, caused by {java.net.SocketTimeoutException: connect timed
out}}] at
com.mongodb.internal.connection.BaseCluster.getDescription(BaseCluster.java:182)
at
com.mongodb.internal.connection.SingleServerCluster.getDescription(SingleServerCluster.java:41)
at
com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:136)
at
com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:94)
at
com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:249)
at
com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:172)
at
com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:132)
at
com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:86)
at
com.mongodb.client.internal.MongoIterableImpl.forEach(MongoIterableImpl.java:110)
at App.main(App.java:46)




Is there something I'm missing that is preventing me from connecting to mongo using the private IP address?



I have set up the inbound rules as such:



enter image description here



and this is what my mongod.conf file looks like:



  # mongod.conf

# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data. systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log

# Where and how to store data. storage: dbPath: /var/lib/mongo journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:

# how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo

# network interfaces net: port: 27017
# bindIp: 172.31.90.193 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

#security:

#operationProfiling:

replication: replSetName: Midterm sharding: clusterRole: configsvr
## Enterprise-Only Options

#auditLog:

#snmp:


Note: I have not set any permission or add credentials in my admin db's collection.









share





























    0















    Im trying to connect to my MongoDB that is on my EC2 instance. I am able to connect to using the public dns with this statement:




    mongoClient = new
    MongoClient("ec2-3-92-197-163.compute-1.amazonaws.com", 27021);




    but if I tried to replace the "ec2-3-92...." with the private IP address, as such:




    mongoClient = new MongoClient("172.31.90.193", 27021);




    It gives me the error:




    INFO: Exception in monitor thread while connecting to server
    172.31.90.193:27021 com.mongodb.MongoSocketOpenException: Exception opening socket at
    com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
    at
    com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
    at
    com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
    at java.base/java.lang.Thread.run(Thread.java:844) Caused by:
    java.net.SocketTimeoutException: connect timed out at
    java.base/java.net.PlainSocketImpl.socketConnect(Native Method) at
    java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400)
    at
    java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243)
    at
    java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225)
    at
    java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402)
    at java.base/java.net.Socket.connect(Socket.java:591) at
    com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)
    at
    com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
    at
    com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
    ... 3 more



    Exception in thread "main" com.mongodb.MongoTimeoutException: Timed
    out after 30000 ms while waiting to connect. Client view of cluster
    state is {type=UNKNOWN, servers=[{address=172.31.90.193:27021,
    type=UNKNOWN, state=CONNECTING,
    exception={com.mongodb.MongoSocketOpenException: Exception opening
    socket}, caused by {java.net.SocketTimeoutException: connect timed
    out}}] at
    com.mongodb.internal.connection.BaseCluster.getDescription(BaseCluster.java:182)
    at
    com.mongodb.internal.connection.SingleServerCluster.getDescription(SingleServerCluster.java:41)
    at
    com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:136)
    at
    com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:94)
    at
    com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:249)
    at
    com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:172)
    at
    com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:132)
    at
    com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:86)
    at
    com.mongodb.client.internal.MongoIterableImpl.forEach(MongoIterableImpl.java:110)
    at App.main(App.java:46)




    Is there something I'm missing that is preventing me from connecting to mongo using the private IP address?



    I have set up the inbound rules as such:



    enter image description here



    and this is what my mongod.conf file looks like:



      # mongod.conf

    # for documentation of all options, see:
    # http://docs.mongodb.org/manual/reference/configuration-options/

    # where to write logging data. systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log

    # Where and how to store data. storage: dbPath: /var/lib/mongo journal:
    enabled: true
    # engine:
    # mmapv1:
    # wiredTiger:

    # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo

    # network interfaces net: port: 27017
    # bindIp: 172.31.90.193 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

    #security:

    #operationProfiling:

    replication: replSetName: Midterm sharding: clusterRole: configsvr
    ## Enterprise-Only Options

    #auditLog:

    #snmp:


    Note: I have not set any permission or add credentials in my admin db's collection.









    share

























      0












      0








      0








      Im trying to connect to my MongoDB that is on my EC2 instance. I am able to connect to using the public dns with this statement:




      mongoClient = new
      MongoClient("ec2-3-92-197-163.compute-1.amazonaws.com", 27021);




      but if I tried to replace the "ec2-3-92...." with the private IP address, as such:




      mongoClient = new MongoClient("172.31.90.193", 27021);




      It gives me the error:




      INFO: Exception in monitor thread while connecting to server
      172.31.90.193:27021 com.mongodb.MongoSocketOpenException: Exception opening socket at
      com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
      at
      com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
      at
      com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
      at java.base/java.lang.Thread.run(Thread.java:844) Caused by:
      java.net.SocketTimeoutException: connect timed out at
      java.base/java.net.PlainSocketImpl.socketConnect(Native Method) at
      java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400)
      at
      java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243)
      at
      java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225)
      at
      java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402)
      at java.base/java.net.Socket.connect(Socket.java:591) at
      com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)
      at
      com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
      at
      com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
      ... 3 more



      Exception in thread "main" com.mongodb.MongoTimeoutException: Timed
      out after 30000 ms while waiting to connect. Client view of cluster
      state is {type=UNKNOWN, servers=[{address=172.31.90.193:27021,
      type=UNKNOWN, state=CONNECTING,
      exception={com.mongodb.MongoSocketOpenException: Exception opening
      socket}, caused by {java.net.SocketTimeoutException: connect timed
      out}}] at
      com.mongodb.internal.connection.BaseCluster.getDescription(BaseCluster.java:182)
      at
      com.mongodb.internal.connection.SingleServerCluster.getDescription(SingleServerCluster.java:41)
      at
      com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:136)
      at
      com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:94)
      at
      com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:249)
      at
      com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:172)
      at
      com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:132)
      at
      com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:86)
      at
      com.mongodb.client.internal.MongoIterableImpl.forEach(MongoIterableImpl.java:110)
      at App.main(App.java:46)




      Is there something I'm missing that is preventing me from connecting to mongo using the private IP address?



      I have set up the inbound rules as such:



      enter image description here



      and this is what my mongod.conf file looks like:



        # mongod.conf

      # for documentation of all options, see:
      # http://docs.mongodb.org/manual/reference/configuration-options/

      # where to write logging data. systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log

      # Where and how to store data. storage: dbPath: /var/lib/mongo journal:
      enabled: true
      # engine:
      # mmapv1:
      # wiredTiger:

      # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo

      # network interfaces net: port: 27017
      # bindIp: 172.31.90.193 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

      #security:

      #operationProfiling:

      replication: replSetName: Midterm sharding: clusterRole: configsvr
      ## Enterprise-Only Options

      #auditLog:

      #snmp:


      Note: I have not set any permission or add credentials in my admin db's collection.









      share














      Im trying to connect to my MongoDB that is on my EC2 instance. I am able to connect to using the public dns with this statement:




      mongoClient = new
      MongoClient("ec2-3-92-197-163.compute-1.amazonaws.com", 27021);




      but if I tried to replace the "ec2-3-92...." with the private IP address, as such:




      mongoClient = new MongoClient("172.31.90.193", 27021);




      It gives me the error:




      INFO: Exception in monitor thread while connecting to server
      172.31.90.193:27021 com.mongodb.MongoSocketOpenException: Exception opening socket at
      com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
      at
      com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
      at
      com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
      at java.base/java.lang.Thread.run(Thread.java:844) Caused by:
      java.net.SocketTimeoutException: connect timed out at
      java.base/java.net.PlainSocketImpl.socketConnect(Native Method) at
      java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400)
      at
      java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243)
      at
      java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225)
      at
      java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402)
      at java.base/java.net.Socket.connect(Socket.java:591) at
      com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)
      at
      com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)
      at
      com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)
      ... 3 more



      Exception in thread "main" com.mongodb.MongoTimeoutException: Timed
      out after 30000 ms while waiting to connect. Client view of cluster
      state is {type=UNKNOWN, servers=[{address=172.31.90.193:27021,
      type=UNKNOWN, state=CONNECTING,
      exception={com.mongodb.MongoSocketOpenException: Exception opening
      socket}, caused by {java.net.SocketTimeoutException: connect timed
      out}}] at
      com.mongodb.internal.connection.BaseCluster.getDescription(BaseCluster.java:182)
      at
      com.mongodb.internal.connection.SingleServerCluster.getDescription(SingleServerCluster.java:41)
      at
      com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:136)
      at
      com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:94)
      at
      com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:249)
      at
      com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:172)
      at
      com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:132)
      at
      com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:86)
      at
      com.mongodb.client.internal.MongoIterableImpl.forEach(MongoIterableImpl.java:110)
      at App.main(App.java:46)




      Is there something I'm missing that is preventing me from connecting to mongo using the private IP address?



      I have set up the inbound rules as such:



      enter image description here



      and this is what my mongod.conf file looks like:



        # mongod.conf

      # for documentation of all options, see:
      # http://docs.mongodb.org/manual/reference/configuration-options/

      # where to write logging data. systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log

      # Where and how to store data. storage: dbPath: /var/lib/mongo journal:
      enabled: true
      # engine:
      # mmapv1:
      # wiredTiger:

      # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo

      # network interfaces net: port: 27017
      # bindIp: 172.31.90.193 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

      #security:

      #operationProfiling:

      replication: replSetName: Midterm sharding: clusterRole: configsvr
      ## Enterprise-Only Options

      #auditLog:

      #snmp:


      Note: I have not set any permission or add credentials in my admin db's collection.







      mongodb aws amazon-ec2





      share












      share










      share



      share










      asked 9 mins ago









      tom dinhtom dinh

      325




      325






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f234155%2fconnecting-to-mongodb-on-ec2-instance-using-the-private-ip-address%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f234155%2fconnecting-to-mongodb-on-ec2-instance-using-the-private-ip-address%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          SQL Server 17 - Attemping to backup to remote NAS but Access is denied

          Always On Availability groups resolving state after failover - Remote harden of transaction...

          Restoring from pg_dump with foreign key constraints