Skip to content

Instantly share code, notes, and snippets.

@yubik9
Last active February 22, 2017 04:33
Show Gist options
  • Select an option

  • Save yubik9/e3f5a07f51a9d423b800edb754bb4e06 to your computer and use it in GitHub Desktop.

Select an option

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