Last active
October 8, 2018 17:32
-
-
Save YoniFeng/feb774af0d74f5ba04fe9938dc980be2 to your computer and use it in GitHub Desktop.
Bash script to enable/disable remote access to MongoDB server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change 255.255.255.255 to external/public ip address | |
#!/bin/sh | |
cp /etc/mongod.conf /etc/mongodBackup.conf | |
grep -q 'bindIp: 127.0.0.1$' /etc/mongod.conf | |
if [ $? -eq 0 ]; | |
then | |
echo "Mongo will now allow remote connections" | |
sed -i 's/bindIp: 127\.0\.0\.1/bindIp: 127\.0\.0\.1,255\.255\.255\.255/g' /etc/mongod.conf | |
else | |
echo "Mongo will now deny remote connections" | |
sed -i 's/bindIp: 127\.0\.0\.1,255\.255\.255\.255/bindIp: 127\.0\.0\.1/g' /etc/mongod.conf | |
fi | |
systemctl restart mongod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment