#!/usr/bin/env bash
#append this script to rc.local file
#enable iptables rules
iptables -F
iptables -X
iptables -Z
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
#unmute alsa audio
amixer set 'Master' 80% unmute
amixer set 'Headphone' 80% unmute
#modify default dns server
chattr -i /etc/resolv.conf
chmod 777 /etc/resolv.conf
echo "nameserver 127.0.0.1" > /etc/resolv.conf
chmod 444 /etc/resolv.conf
chattr +i /etc/resolv.conf
#wireless static random ip address and static random mac address, need to install macchanger and Modify NET_ADDR
MAC_ADDR=`echo $RANDOM|md5sum|sed 's/../&:/g'|cut -c 1-17`
NET_ADDR="192.168.30"
HOSTNUM=$(($RANDOM%254+2))
ip link set wlan0 down
macchanger -m${MAC_ADDR} wlan0
ip addr flush dev wlan0
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
ip addr add ${NET_ADDR}.${HOSTNUM}/24 broadcast ${NET_ADDR}.255 dev wlan0
ip route add default via ${NET_ADDR}.1
ip link set wlan0 up