fix mistake from recent commit
[distro-setup] / vpn-mail-forward
1 #!/bin/bash
2
3 set -eE -o pipefail
4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
5
6 do-forward() {
7 cmd=$1; shift
8 for port; do
9 /sbin/iptables -t nat $cmd PREROUTING -i eth0 -p tcp -m tcp --dport $port -j DNAT --to-destination 10.8.0.4:$port
10 done
11 }
12
13 ports=(25 143)
14 case $1 in
15 start)
16 do-forward -A ${ports[@]}
17 ;;
18 stop)
19 do-forward -D ${ports[@]}
20 ;;
21 *)
22 echo "$0: error: expected 1 argument of start or stop"
23 exit 1
24 ;;
25 esac