Jun 1, 2024 05:27 PM
(This post was last modified: Jun 1, 2024 05:32 PM by Burger.)
I have recently found a script that I created awhile back that utilizes Private Internet Access (PIA VPN) and Tor to create a secure network for your server or personal computer running Linux. This was created on Debian and has been used with Deb / Ubuntu!
Take a peek and try it out pretty simple code and easy to configure, message me if you have any problems!
I have never charged for my scripts / help however I would love to get the byte awards and make some flips today so please give me a Quick Love and or a donation of bytes if you use this!
Take a peek and try it out pretty simple code and easy to configure, message me if you have any problems!
I have never charged for my scripts / help however I would love to get the byte awards and make some flips today so please give me a Quick Love and or a donation of bytes if you use this!
Code
#!/bin/bash
# Line 27- Change bangbang to hostname
# Tor must be installed - apt-get install tor
# PIA must be installed - install-pia.sh -> Manual Download will be needed easy to install!
PIA_HOSTNAMES="sweden france ca germany swiss us-california us-seattle us-texas nl uk-london us-east us-midwest us-florida israel ro hk us-west uk-southampton"
VPN_IPS=""
# Flush all rules
sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "Flushed."
if [ "$1" == "flush" ]; then
exit 0
fi
echo "Preparing resolv.conf"
sudo echo 1 > /proc/sys/net/ipv4/ip_forward
sudo echo -ne "domain BANGBANG\nsearch BANGBANG\nnameserver 8.8.8.8\n" >> /etc/resolv.conf
sudo echo -e "127.0.0.1\tlocalhost" > /etc/hosts
sudo echo -e "127.0.0.1\tsecure" >> /etc/hosts
echo "Resolving all PIA hostnames"
for HOSTNAME in $PIA_HOSTNAMES
do
DIG_OUTPUT=$(dig "$HOSTNAME".privateinternetaccess.com +short)
for IADDR in $DIG_OUTPUT
do
VPN_IPS=$(echo "$VPN_IPS $IADDR/32")
sudo echo -e "$IADDR\t$HOSTNAME.privateinternetaccess.com" >> /etc/hosts
done
done
VPN_IPS=$(echo "$VPN_IPS" | sed 's/^ *//')
# Drop everything by default
echo "Dropping all traffic"
sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT DROP
sudo iptables -P FORWARD DROP
# Whitelist all VPN IPs
echo "Whitelisting PIA IP addresses on eth0"
for IP in $VPN_IPS
do
sudo iptables -A INPUT -s $IP -i eth0 -j ACCEPT
sudo iptables -A OUTPUT -d $IP -o eth0 -j ACCEPT
done
# Allow the tun0 device
echo "Allowing only 'debian-tor' to communicate via tun0"
sudo iptables -A INPUT -i tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -o tun0 -m owner --uid-owner debian-tor -j ACCEPT
echo "Allow communication with Google's DNS servers"
sudo iptables -A INPUT -s 8.8.8.8 -j ACCEPT
sudo iptables -A OUTPUT -d 8.8.8.8 -j ACCEPT
# Allow local interface
echo "Enable communicating with loopback interface"
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A OUTPUT -o lo -j ACCEPT
# Allow outgoing and incoming NTP traffic to/from NIST.
echo "Enable NTP traffic to NIST"
sudo iptables -A OUTPUT -p udp -m iprange --dst-range 129.6.15.28-129.6.15.30 --dport 123 -j ACCEPT
sudo iptables -A INPUT -p udp -m iprange --src-range 129.6.15.28-129.6.15.30 --sport 123 -j ACCEPT

![[Image: sig.gif]](https://i.ibb.co/S7Bg7Yn/sig.gif)

