Skip to content

Commit

Permalink
v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
deathline94 authored May 24, 2023
1 parent 8ccd3ad commit ed4ba8e
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions LazyTunnel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ mainland_ip=$(curl -s https://api.ipify.org)

if [[ "$1" == "uninstall" ]]; then
echo "Uninstalling..."
iptables -t nat -D PREROUTING -p tcp --dport 22 -j DNAT --to-destination ${mainland_ip}
iptables -t nat -D PREROUTING -j DNAT --to-destination ${foreign_ip}
iptables -t nat -D POSTROUTING -j MASQUERADE
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
systemctl stop iptables
systemctl disable iptables
rm /etc/systemd/system/iptables.service
rm /root/ip.txt
rm /root/LazyTunnel.sh
systemctl daemon-reload
rm "${script_path}"
foreign_ip=$(cat /root/ip.txt)
sudo iptables -t nat -D PREROUTING -p tcp --dport 22 -j DNAT --to-destination ${mainland_ip}
sudo iptables -t nat -D PREROUTING -j DNAT --to-destination ${foreign_ip}
sudo iptables -t nat -D POSTROUTING -j MASQUERADE
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 FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo systemctl stop iptables
sudo systemctl disable iptables
sudo rm /etc/systemd/system/iptables.service
sudo rm /root/ip.txt
sudo systemctl daemon-reload
sudo rm "${script_path}"
exit 0
fi

# Check if the rules are already in place
if iptables -t nat -C PREROUTING -p tcp --dport 22 -j DNAT --to-destination ${mainland_ip} 2>/dev/null; then
if sudo iptables -t nat -C PREROUTING -p tcp --dport 22 -j DNAT --to-destination ${mainland_ip} 2>/dev/null; then
echo "IPTables rules are already set, nothing to do."
exit 0
fi
Expand All @@ -40,9 +40,9 @@ echo ${foreign_ip} > /root/ip.txt

sysctl net.ipv4.ip_forward=1

iptables -t nat -A PREROUTING -p tcp --dport 22 -j DNAT --to-destination ${mainland_ip}
iptables -t nat -A PREROUTING -j DNAT --to-destination ${foreign_ip}
iptables -t nat -A POSTROUTING -j MASQUERADE
sudo iptables -t nat -A PREROUTING -p tcp --dport 22 -j DNAT --to-destination ${mainland_ip}
sudo iptables -t nat -A PREROUTING -j DNAT --to-destination ${foreign_ip}
sudo iptables -t nat -A POSTROUTING -j MASQUERADE

echo "[Unit]
Description=Persistent IPTables NAT rules
Expand All @@ -51,10 +51,10 @@ Before=network.target
ExecStart=/sbin/iptables-restore /root/ip.txt
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/iptables.service
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/iptables.service > /dev/null

systemctl enable iptables
systemctl start iptables
sudo systemctl enable iptables
sudo systemctl start iptables

# Save a copy of the script locally
cp "$0" "${script_path}"

0 comments on commit ed4ba8e

Please sign in to comment.