4 # Change this variable to match your private network.
6 PRIVATE_NETWORK
="172.99.0.0/16"
9 # Change this variable to match your public interface - either eth0 or eth1
11 PUBLIC_INTERFACE
="eth0"
14 # Set PATH to find iptables
16 #PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin
19 # Module list where KERNEL_MODULES_NAT are defined.
21 #IPTABLES_MODULE_LIST="/usr/syno/etc/iptables_modules_list"
22 IPTABLES_MODULE_LIST
="/usr/syno/etc.defaults/iptables_modules_list"
23 #source "${IPTABLES_MODULE_LIST}"
26 # My service name - let's make sure we don't conflict with synology
33 IPTABLES
="/sbin/iptables"
35 BIN_IPTABLESTOOL
="/usr/syno/bin/iptablestool"
36 BIN_SYNOMODULETOOL
="/usr/syno/bin/synomoduletool"
42 for mod
in $modules; do
48 # Based on /volume1/@appstore/VPNCenter/scripts/accel-pppd.sh
50 if [ -f "${IPTABLES_MODULE_LIST}" ]; then
51 source ${IPTABLES_MODULE_LIST}
53 for mod
in $KERNEL_MODULES_CORE; do
54 if [ -e "/lib/modules/$mod" ]; then
55 NAT_Mod
="${NAT_Mod} ${mod}"
58 for mod
in $KERNEL_MODULES_COMMON; do
59 if [ -e "/lib/modules/$mod" ]; then
60 NAT_Mod
="${NAT_Mod} ${mod}"
63 for mod
in $KERNEL_MODULES_NAT; do
64 if [ -e "/lib/modules/$mod" ]; then
65 NAT_Mod
="${NAT_Mod} ${mod}"
69 echo >&2 "[x]Cannot find ${IPTABLES_MODULE_LIST} !"
79 # Make sure packet forwarding is enabled.
80 # 'sysctl -w net.ipv4.ip_forward=1' does not work for me
82 echo 1 > /proc
/sys
/net
/ipv
4/ip_forward
84 # Count the number of modules so that we can verify if the module
85 # insertion was successful. We replace whitespaces with newlines
88 MODULE_COUNT
=( ${NAT_Mod} )
89 MODULE_COUNT
=${#MODULE_COUNT[@]}
91 # Load the kernel modules necessary for NAT
93 echo -n "Starting ${SERVICE}: "
94 if [ -x ${BIN_SYNOMODULETOOL} ]; then
95 $BIN_SYNOMODULETOOL --insmod $SERVICE ${NAT_Mod}
97 elif [ -x ${BIN_IPTABLESTOOL} ]; then
98 $BIN_IPTABLESTOOL --insmod $SERVICE ${NAT_Mod}
102 # $BIN_SYNOMODULETOOL returns the number of loaded modules as return value
104 [[ "${RV}" == "${MODULE_COUNT}" ]] ||
{
105 echo >&2 "Error: Modules were not loaded (${RV},${MODULE_COUNT}). The following command failed:"
106 echo >&2 "${BIN_SYNOMODULETOOL}" --insmod "${SERVICE}" ${NAT_Mod}
112 ${IPTABLES} -t nat -F
113 "${IPTABLES}" -t nat -A POSTROUTING -s "${PRIVATE_NETWORK}" -j MASQUERADE -o "${PUBLIC_INTERFACE}"
115 [[ "${RV}" == "0" ]] || {
116 echo >&2 "Error
: MASQUERADE rules could not be added. The following
command failed
:"
117 echo >&2 "${IPTABLES}" -t nat -A POSTROUTING -s "${PRIVATE_NETWORK}" -j MASQUERADE -o "${PUBLIC_INTERFACE}"
122 ${IPTABLES} -t nat -A PREROUTING -p tcp -i eth0 --dport 222 -j DNAT --to-destination 172.99.3.3:22
124 # Log current nat table
126 ${IPTABLES} -L -v -t nat --line-numbers
130 local modules=`reverse_modules "${NAT_Mod}"`
131 echo -n "Shutting down
${SERVICE}: "
132 # https://www.digitalocean.com/community/tutorials/how-to-list-and-delete-iptables-firewall-rules
133 ${IPTABLES} -P INPUT ACCEPT
134 ${IPTABLES} -P FORWARD ACCEPT
135 ${IPTABLES} -P OUTPUT ACCEPT
136 ${IPTABLES} -t nat -F
137 ${IPTABLES} -t mangle -F
140 #echo 0 > /proc/sys/net/ipv4/ip_forward
141 if [ -x ${BIN_SYNOMODULETOOL} ]; then
142 $BIN_SYNOMODULETOOL --rmmod $SERVICE $modules
143 elif [ -x ${BIN_IPTABLESTOOL} ]; then
144 $BIN_IPTABLESTOOL --rmmod $SERVICE $modules
161 echo "Usage
: $0 {start|stop|restart
}"