redirect-ports.sh 907 B

1234567891011121314151617
  1. #!/bin/bash
  2. # redirects ports below 1024 to a higher range using iptables, so they can be used without elevated rights
  3. # MySQL SIP (3306 and 5060) are left out because they are >= 1024 anyways
  4. # ECHO FTP HTTP HTTPS SMB (NETBIOS UDP & TCP) SSH TELNET
  5. protocol=( "tcp" "tcp" "tcp" "tcp" "udp" "udp" "tcp" "tcp" "tcp" "tcp" )
  6. origin=( 7 21 80 443 137 138 137 139 22 23 )
  7. destination=( 28144 28169 28217 28580 28274 28275 28274 28276 28159 28160 ) # simply offset by 1024 + 27113
  8. length=${#protocol[@]} # count protocol elements
  9. for (( i=0; i<$length; i++ ))
  10. do
  11. # echo ${protocol[$i]} ${origin[$i]} ${destination[$i]} # debug
  12. iptables -t nat -A PREROUTING -p ${protocol[$i]} --dport ${origin[$i]} -j REDIRECT --to-ports ${destination[$i]}
  13. iptables -t nat -A OUTPUT -p ${protocol[$i]} --dport ${destination[$i]} -j REDIRECT --to-ports ${origin[$i]}
  14. done