-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·47 lines (39 loc) · 842 Bytes
/
entrypoint.sh
File metadata and controls
executable file
·47 lines (39 loc) · 842 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
# iptables -F
# iptables -t nat -F
# iptables -X
iptables \
-t nat \
-A POSTROUTING \
-j MASQUERADE
# Check if iptable fail
if [ $? -ne 0 ]; then
echo "Failed executing iptable command. Maybe you execute this container without `NET_ADMIN` capabilitie?"
exit 1
fi
# Loop over every param into $REROUTER delimited by ',' character
for i in ${REROUTER//,/ }
do
# Split every ReRoute by first ':' character
IFS=':' read -r in_port dest <<-EOF
$(echo $i)
EOF
iptables \
-t nat \
-A PREROUTING \
-p tcp \
--dport $in_port \
-j DNAT \
--to-destination $dest
# Check if iptable fail applying desired rule
if [ $? -eq 0 ]; then
echo "ReRouted port '$in_port' to '$dest'."
else
echo
echo
echo "!!! FAILED !!! ReRouting port '$in_port' to '$dest'."
echo
fi
done
# Exec desired command
exec "$@"