Skip to content

Instantly share code, notes, and snippets.

@mrlesmithjr
Last active November 11, 2015 05:31
Show Gist options
  • Save mrlesmithjr/b4d1c4d7df2c9d2c1e20 to your computer and use it in GitHub Desktop.
Save mrlesmithjr/b4d1c4d7df2c9d2c1e20 to your computer and use it in GitHub Desktop.
#!/bin/bash
# check for iptables-persistent package and install if not already installed
script_name="iptablesrules.sh"
# change user to the account you wish to use on the remote nodes
user="root"
tee $script_name <<EOF
if apt-get -qq install iptables-persistent; then
echo "Successfully detected iptables-persistent"
else
echo "Error installing iptables-persistent"
apt-get -y install iptables-persistent
fi
EOF
clear
echo "Enter firewall rule(s) below to apply to cluster:"
echo "Example... iptables -A INPUT -p tcp --dport 22 -j ACCEPT"
echo "Note: You can add more than one rule at a time"
echo "enter the rules below (Enter "done" to end rules)"
while read LINE
do
echo $LINE >> $script_name
if [ "$LINE" = "done" ];then
break
fi
done
chmod +x $script_name
sed -i -e 's|done||' $script_name
echo "service iptables-persistent save" >> $script_name
echo "Applying the following rule $iptablesrule"
for node in $(cat nodes.txt); do
scp $script_name $user@$node:/tmp
ssh $user@$node "/tmp/$script_name"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment