-
-
Save yegorg/3ef8404c13f44dd928e7 to your computer and use it in GitHub Desktop.
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
#!/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