forked from MrAminiNezhad/Auto-tunnel-iptables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
76 lines (60 loc) · 1.87 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
wget -N --no-check-certificate "https://raw.githubusercontent.com/MrAminiNezhad/tcp_optimizer_hybla/main/hybla.sh"
chmod +x "hybla.sh"
bash "hybla.sh"
echo "please wait"
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root."
exit 1
fi
update_process=$(apt update 2>&1)
if [[ $? -ne 0 ]]; then
echo "An error occurred while updating the package list."
echo "$update_process"
exit 1
fi
autoremove_process=$(apt autoremove -y 2>&1)
if [[ $? -ne 0 ]]; then
echo "An error occurred while removing unused packages."
echo "$autoremove_process"
exit 1
fi
clean_process=$(apt clean 2>&1)
if [[ $? -ne 0 ]]; then
echo "An error occurred while cleaning up the package cache."
echo "$clean_process"
exit 1
fi
echo "server update successful."
install_iptables=$(apt-get install iptables -y 2>&1)
if [[ $? -ne 0 ]]; then
echo "An error occurred while installing the iptables package."
echo "$install_iptables"
exit 1
fi
read -p "enter iranIP: " iranip
read -p "enter kharejIP: " kharegip
sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 22 -j DNAT --to-destination "$iranip"
iptables -t nat -A PREROUTING -j DNAT --to-destination "$kharegip"
iptables -t nat -A POSTROUTING -j MASQUERADE
rc_local_commands=(
"#! /bin/bash"
"sysctl net.ipv4.ip_forward=1"
"iptables -t nat -A PREROUTING -p tcp --dport 22 -j DNAT --to-destination $iranip"
"iptables -t nat -A PREROUTING -j DNAT --to-destination $kharegip"
"iptables -t nat -A POSTROUTING -j MASQUERADE"
"exit 0"
)
rc_local_path="/etc/rc.local"
{
for command in "${rc_local_commands[@]}"; do
echo "$command"
done
} >>"$rc_local_path"
echo "added successful $rc_local_path"
chmod +x "$rc_local_path"
echo "added successful $rc_local_path"
echo "permission changed successful $rc_local_path."
echo "End Config enjoy now"
exit 0