Last active
February 22, 2017 04:33
-
-
Save yubik9/e3f5a07f51a9d423b800edb754bb4e06 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 | |
| # HOSTLIST="ips" bash < <(curl -fsSL https://gist.github.com/fanminjian/e3f5a07f51a9d423b800edb754bb4e06/raw) | |
| # Hostname | |
| node=`ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' | sed -r 's!/.*!!; s!.*\.!!'` | |
| hostname="node$node" | |
| echo $hostname > /etc/hostname | |
| sed "s/127.0.1.1.*/127.0.1.1\t$hostname\t$hostname/g" /etc/hosts > /etc/hosts | |
| # Update system | |
| DEBIAN_FRONTEND=noninteractive apt-get update | |
| DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade | |
| # Required System Packages | |
| DEBIAN_FRONTEND=noninteractive apt-get -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install iptables-persistent linux-image-virtual | |
| # Firewalls | |
| for i in $HOSTLIST | |
| do | |
| iptables -A INPUT -s $i -j ACCEPT | |
| done | |
| iptables -A INPUT -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT | |
| iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT | |
| iptables -A INPUT -i eth0 -p tcp --dport 443 -j ACCEPT | |
| iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT | |
| iptables -A INPUT -i eth0 -p icmp --icmp-type echo-request -j ACCEPT | |
| iptables -A INPUT -i eth0 -j DROP | |
| iptables-save >/etc/iptables/rules.v4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment