Skip to content

Instantly share code, notes, and snippets.

@jaffarc
Forked from joebarbere/mongodb_iptables.sh
Created December 15, 2020 22:51
Show Gist options
  • Save jaffarc/d921d56ccc5a17dd3b2efb79da8071a7 to your computer and use it in GitHub Desktop.
Save jaffarc/d921d56ccc5a17dd3b2efb79da8071a7 to your computer and use it in GitHub Desktop.
mongodb iptables
#!/bin/bash
# Flush all current rules from iptables
iptables -F
# Allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow MongoDB
iptables -A INPUT -s 10.182.226.217 -p tcp --dport 27017 -j ACCEPT
# Allow SSL on non standard port
iptables -A INPUT -p tcp --dport 33333 -j ACCEPT
# Allow local ICMP ping
iptables -A INPUT -s 10.182.226.217 -p icmp --icmp-type echo-request -j ACCEPT
# Drop everything else
iptables -A INPUT -j DROP
# Allow loopback traffic
iptables -I INPUT 1 -i lo -j ACCEPT
# SAVE CHANGES
iptables-save > /etc/iptables.rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment