eibgrad

tomato-ftp-remote-port.sh

Feb 3rd, 2018 (edited)
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.15 KB | None | 0 0
  1. #!/bin/sh
  2. export DEBUG= # uncomment/comment to enable/disable debug mode
  3.  
  4. #         name: tomato-ftp-remote-port.sh
  5. #      version: 1.1.0, 10-jun-2021, by eibgrad
  6. #      purpose: assign external ftp port without changing internal ftp port
  7. #  script type: firewall
  8. # installation:
  9. #   1. make sure ftp server is configured as "Yes, WAN and LAN"
  10. #   2. choose preferred external/remote port
  11. #   3. install this script in firewall script
  12. #   4. reboot
  13.  
  14. (
  15. [ ${DEBUG+x} ] && set -x
  16.  
  17. LAN_IP="$(nvram get lan_ipaddr)"
  18. FTP_LPORT="$(nvram get ftp_port)"
  19. FTP_RPORT=2121 # change to preferred external/remote port
  20. NUL_PORT=65535 # any *unused* internal port on router
  21.  
  22. ipt() {
  23.     local rule="$@"
  24.  
  25.     # precede insert/append w/ deletion to avoid dupes
  26.     while iptables ${rule/-[IA]/-D} 2>/dev/null; do :; done
  27.     iptables $rule
  28. }
  29.  
  30. # deny access over WAN to internal/local ftp port
  31. ipt -t nat -I WANPREROUTING -p tcp --dport $FTP_LPORT -j DNAT --to $LAN_IP:$NUL_PORT
  32.  
  33. # redirect external/remote ftp port to internal/local ftp port
  34. ipt -t nat -I WANPREROUTING -p tcp --dport $FTP_RPORT -j DNAT --to $LAN_IP:$FTP_LPORT
  35.  
  36. ) 2>&1 | logger -t $(basename $0)[$$]
Advertisement
Add Comment
Please, Sign In to add comment