MongoDB through the firewall

To find all posts about MongoDB, click on the MongoDB category at the bottom of this post to find all posts tagged with that keyword.

So far, I have been working with MongoDB on a Windows instance. I have instances on my local Windows 8.1 workstation, and Windows Server 2012 on Azure. To test the firewall settings though, I brought up an instance on one of my local Windows 2012 servers.

From everything I gathered, I put together this script file, to enable to the correct ports in a Windows firewall:

@echo off
    
REM ** Optional - to reset to defaults
REM echo Resetting firewall rules...
REM netsh advfirewall reset

echo Adding MongoD port 27017
netsh advfirewall firewall add rule name="Open mongod port 27017" dir=in action=allow protocol=TCP localport=27017

echo Adding MongoD shared port 27017
netsh advfirewall firewall add rule name="Open mongod shard port 27017" dir=in action=allow protocol=TCP localport=27017
    
echo Adding MongoD program through the firewall
netsh advfirewall firewall add rule name="Allowing mongod" dir=in action=allow program=" C:mongodbbinmongod.exe"
    
echo Adding MongoS program through the firewall
netsh advfirewall firewall add rule name="Allowing mongos" dir=in action=allow program=" C:mongodbbinmongos.exe"
    
echo Done.
pause

On my local server instance, it worked great! I could use mongo.exe on my workstation and connect to the instance on my local server. Whereas, I couldn’t before I made that change.

The bad news is that when I tried this on the Azure VM – I got no errors and everything looked OK, but I still can’t connect to it from my local machine. I remember Azure having another layer of security where only certain external IP addresses could access certain resources. However, Azure has changed so much (and continues to change so much) that I can’t figure out where to fix that in the Azure console.

So, in my Azure VM, I have opened up the firewall on that server – but an Azure-hosted app, nor my local machine can connect. I’m at a dead-end with that.

Aside from that though, the script above should work for opening the Windows firewall so that other machines can connect to your instance.

Posted in MongoDB, NoSQL, Uncategorized
One comment on “MongoDB through the firewall
  1. Tor says:

    Guess you have configured your mongo db to only listen to local addresses and not LAN interfaces. See the net / bindIp configuration

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 2 other followers

%d bloggers like this: