Advertisement
MrEfendi

iptables openvpn transfer

Nov 28th, 2020 (edited)
1,099
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.69 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. # Skrypt pozwalający łatwo przy bootowaniu dodać adresy do routowania
  5. # pomiędzy internetem a OpenVPN
  6. #
  7. # Dodać do wykonia after boot!
  8. #
  9. # v1.0 Filipczyk.net
  10. #
  11.  
  12. trybTestowy=0; #1 = test | 0 = dzialanie
  13.  
  14. declare -a PubliczneIP=(
  15.     "51.83.232.187" "51.83.232.188"
  16. )
  17. declare -a PrywatneIP=(
  18.     "10.8.0.2" "10.8.0.3"
  19. )
  20. declare -a PortyDoPrzekierowania=(
  21.     "21" "25" "53" "80" "110" "143" "443" "465" "587" "993" "995"
  22. )
  23.  
  24. counter=0;
  25. for i in "${PubliczneIP[@]}"
  26. do
  27.     for j in "${PortyDoPrzekierowania[@]}"
  28.     do
  29.         iptables -t nat -A PREROUTING -d ${PubliczneIP[counter]} -p tcp --dport $j -j DNAT --to-dest ${PrywatneIP[counter]}:$j
  30.         iptables -t filter -A INPUT -p tcp -d ${PrywatneIP[counter]} --dport $j -j ACCEPT
  31.     done
  32.    
  33.     # RDP 33891 to local 3389
  34.     iptables -t nat -A PREROUTING -d ${PubliczneIP[counter]} -p tcp --dport 33891 -j DNAT --to-dest ${PrywatneIP[counter]}:3389
  35.     iptables -t filter -A INPUT -p tcp -d ${PrywatneIP[counter]} --dport 33891 -j ACCEPT
  36.     iptables -t nat -A PREROUTING -d ${PubliczneIP[counter]} -p udp --dport 33891 -j DNAT --to-dest ${PrywatneIP[counter]}:3389
  37.     iptables -t filter -A INPUT -p udp -d ${PrywatneIP[counter]} --dport 33891 -j ACCEPT
  38.    
  39.     # SSH 22111 to local 22
  40.     iptables -t nat -A PREROUTING -d ${PubliczneIP[counter]} -p tcp --dport 22111 -j DNAT --to-dest ${PrywatneIP[counter]}:22
  41.     iptables -t filter -A INPUT -p tcp -d ${PrywatneIP[counter]} --dport 22111 -j ACCEPT
  42.     iptables -t nat -A PREROUTING -d ${PubliczneIP[counter]} -p udp --dport 22111 -j DNAT --to-dest ${PrywatneIP[counter]}:22
  43.     iptables -t filter -A INPUT -p udp -d ${PrywatneIP[counter]} --dport 22111 -j ACCEPT
  44.    
  45.     let "counter=counter+1"
  46. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement