-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_IPTables.sh
More file actions
26 lines (19 loc) · 832 Bytes
/
Copy pathserver_IPTables.sh
File metadata and controls
26 lines (19 loc) · 832 Bytes
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
#!/bin/bash
#echo 1 > /proc/sys/net/ipv4/ip_forward
interfaceName="eth0"
tunInterface="tun0"
clientIP="192.168.255.6"
serverIP="192.168.255.1"
declare -a ports
ports=( 443 32400 )
##Allow crosstalk
iptables -A FORWARD -i ${tunInterface} -o ${interfaceName} -j ACCEPT
iptables -A FORWARD -i ${interfaceName} -o ${tunInterface} -j ACCEPT
iptables -A FORWARD -i ${interfaceName} -o ${tunInterface} -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i ${tunInterface} -o ${interfaceName} -m state --state ESTABLISHED,RELATED -j ACCEPT
for port in "${ports[@]}"
do
echo $port
iptables -t nat -A PREROUTING -i ${interfaceName} -p tcp --dport $port -j DNAT --to-destination ${clientIP}:$port
iptables -t nat -A POSTROUTING -p tcp -d ${clientIP} --dport $port -j SNAT --to-source ${serverIP}
done