vpn.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/bash
  2. #
  3. # By EvoTeamMalaysia
  4. # ==================================================
  5. # initialisasi var
  6. export DEBIAN_FRONTEND=noninteractive
  7. OS=`uname -m`;
  8. MYIP=$(wget -qO- https://icanhazip.com);
  9. MYIP2="s/xxxxxxxxx/$MYIP/g";
  10. ANU=$(ip -o $ANU -4 route show to default | awk '{print $5}');
  11. # Install OpenVPN dan Easy-RSA
  12. apt install openvpn easy-rsa unzip -y
  13. apt install openssl iptables iptables-persistent -y
  14. mkdir -p /etc/openvpn/server/easy-rsa/
  15. cd /etc/openvpn/
  16. wget https://raw.githubusercontent.com/EvoTeamMalaysia/AutoScript/main/vpn.zip
  17. unzip vpn.zip
  18. rm -f vpn.zip
  19. chown -R root:root /etc/openvpn/server/easy-rsa/
  20. cd
  21. mkdir -p /usr/lib/openvpn/
  22. cp /usr/lib/x86_64-linux-gnu/openvpn/plugins/openvpn-plugin-auth-pam.so /usr/lib/openvpn/openvpn-plugin-auth-pam.so
  23. # nano /etc/default/openvpn
  24. sed -i 's/#AUTOSTART="all"/AUTOSTART="all"/g' /etc/default/openvpn
  25. # restart openvpn dan cek status openvpn
  26. systemctl enable --now openvpn-server@server-tcp-1194
  27. systemctl enable --now openvpn-server@server-udp-2200
  28. /etc/init.d/openvpn restart
  29. /etc/init.d/openvpn status
  30. # aktifkan ip4 forwarding
  31. echo 1 > /proc/sys/net/ipv4/ip_forward
  32. sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf
  33. # Buat config client TCP 1194
  34. cat > /etc/openvpn/client-tcp-1194.ovpn <<-END
  35. ########## SELAMAT DATANG ############
  36. ########## OKKAY KAYYO VPN ###########
  37. client
  38. dev tun
  39. proto tcp
  40. remote xxxxxxxxx 1194
  41. resolv-retry infinite
  42. route-method exe
  43. nobind
  44. persist-key
  45. persist-tun
  46. auth-user-pass
  47. comp-lzo
  48. verb 3
  49. END
  50. sed -i $MYIP2 /etc/openvpn/client-tcp-1194.ovpn;
  51. # Buat config client UDP 2200
  52. cat > /etc/openvpn/client-udp-2200.ovpn <<-END
  53. ########## SELAMAT DATANG ###########
  54. ########## EvoTeam VPN ##########
  55. client
  56. dev tun
  57. proto udp
  58. remote xxxxxxxxx 2200
  59. resolv-retry infinite
  60. route-method exe
  61. nobind
  62. persist-key
  63. persist-tun
  64. auth-user-pass
  65. comp-lzo
  66. verb 3
  67. END
  68. sed -i $MYIP2 /etc/openvpn/client-udp-2200.ovpn;
  69. # Buat config client SSL
  70. cat > /etc/openvpn/client-tcp-ssl.ovpn <<-END
  71. ########## SELAMAT DATANG ############
  72. ########## EvoTeam VPN ###########
  73. client
  74. dev tun
  75. proto tcp
  76. remote xxxxxxxxx 442
  77. resolv-retry infinite
  78. route-method exe
  79. nobind
  80. persist-key
  81. persist-tun
  82. auth-user-pass
  83. comp-lzo
  84. verb 3
  85. END
  86. sed -i $MYIP2 /etc/openvpn/client-tcp-ssl.ovpn;
  87. cd
  88. # pada tulisan xxx ganti dengan alamat ip address VPS anda
  89. /etc/init.d/openvpn restart
  90. # masukkan certificatenya ke dalam config client TCP 1194
  91. echo '<ca>' >> /etc/openvpn/client-tcp-1194.ovpn
  92. cat /etc/openvpn/server/ca.crt >> /etc/openvpn/client-tcp-1194.ovpn
  93. echo '</ca>' >> /etc/openvpn/client-tcp-1194.ovpn
  94. echo '<key>' >> /etc/openvpn/client-tcp-1194.ovpn
  95. cat /etc/openvpn/server/server.key >> /etc/openvpn/client-tcp-1194.ovpn
  96. echo '</key>' >> /etc/openvpn/client-tcp-1194.ovpn
  97. # Copy config OpenVPN client ke home directory root agar mudah didownload ( TCP 1194 )
  98. cp /etc/openvpn/client-tcp-1194.ovpn /home/vps/public_html/client-tcp-1194.ovpn
  99. # masukkan certificatenya ke dalam config client UDP 2200
  100. echo '<ca>' >> /etc/openvpn/client-udp-2200.ovpn
  101. cat /etc/openvpn/server/ca.crt >> /etc/openvpn/client-udp-2200.ovpn
  102. echo '</ca>' >> /etc/openvpn/client-udp-2200.ovpn
  103. echo '<key>' >> /etc/openvpn/client-udp-2200.ovpn
  104. cat /etc/openvpn/server/server.key >> /etc/openvpn/client-udp-2200.ovpn
  105. echo '</key>' >> /etc/openvpn/client-udp-2200.ovpn
  106. # Copy config OpenVPN client ke home directory root agar mudah didownload ( UDP 2200 )
  107. cp /etc/openvpn/client-udp-2200.ovpn /home/vps/public_html/client-udp-2200.ovpn
  108. # masukkan certificatenya ke dalam config client SSL
  109. echo '<ca>' >> /etc/openvpn/client-tcp-ssl.ovpn
  110. cat /etc/openvpn/server/ca.crt >> /etc/openvpn/client-tcp-ssl.ovpn
  111. echo '</ca>' >> /etc/openvpn/client-tcp-ssl.ovpn
  112. # Copy config OpenVPN client ke home directory root agar mudah didownload ( SSL )
  113. cp /etc/openvpn/client-tcp-ssl.ovpn /home/vps/public_html/client-tcp-ssl.ovpn
  114. #firewall untuk memperbolehkan akses UDP dan akses jalur TCP
  115. iptables -t nat -I POSTROUTING -s 10.6.0.0/24 -o $ANU -j MASQUERADE
  116. iptables -t nat -I POSTROUTING -s 10.7.0.0/24 -o $ANU -j MASQUERADE
  117. iptables-save > /etc/iptables.up.rules
  118. chmod +x /etc/iptables.up.rules
  119. iptables-restore -t < /etc/iptables.up.rules
  120. netfilter-persistent save
  121. netfilter-persistent reload
  122. # Restart service openvpn
  123. systemctl enable openvpn
  124. systemctl start openvpn
  125. /etc/init.d/openvpn restart
  126. # Delete script
  127. history -c
  128. rm -f /root/vpn.sh