Skip to content

Instantly share code, notes, and snippets.

@YoniFeng
Last active October 8, 2018 17:32
Show Gist options
  • Save YoniFeng/feb774af0d74f5ba04fe9938dc980be2 to your computer and use it in GitHub Desktop.
Save YoniFeng/feb774af0d74f5ba04fe9938dc980be2 to your computer and use it in GitHub Desktop.
Bash script to enable/disable remote access to MongoDB server
# 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