openvpn.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/bin/bash
  2. clear
  3. if [[ "$EUID" -ne 0 ]]; then
  4. echo -e "\033[1;31mScript need to be run as root!\033[0m"; exit 1
  5. fi
  6. apt-get -qq update
  7. apt-get -y -qq install easy-rsa
  8. apt-get -y -qq install openvpn
  9. systemctl disable openvpn
  10. systemctl stop openvpn
  11. alamat_ip=$(wget -qO- ipv4.icanhazip.com)
  12. alamat_hos=$(cat /etc/environment | grep 'DOMAIN' | cut -d '=' -f 2 | head -n 1)
  13. cd /usr/share/easy-rsa
  14. ./easyrsa --batch init-pki &>/dev/null
  15. ./easyrsa --batch build-ca nopass &>/dev/null
  16. ./easyrsa --batch gen-dh &>/dev/null
  17. ./easyrsa --batch build-server-full server nopass &>/dev/null
  18. cp -R /usr/share/easy-rsa/pki /etc/openvpn/ && cd
  19. [[ -d /etc/openvpn/server ]] && rm -d /etc/openvpn/server
  20. echo "# OVPN SERVER-TCP CONFIG
  21. # ----------------------------
  22. port 1194
  23. proto tcp
  24. dev tun
  25. ca /etc/openvpn/pki/ca.crt
  26. cert /etc/openvpn/pki/issued/server.crt
  27. key /etc/openvpn/pki/private/server.key
  28. dh /etc/openvpn/pki/dh.pem
  29. verify-client-cert none
  30. server 10.8.0.0 255.255.255.0
  31. ifconfig-pool-persist ipp.txt
  32. push \"redirect-gateway def1 bypass-dhcp\"
  33. push \"dhcp-option DNS 8.8.8.8\"
  34. push \"dhcp-option DNS 8.8.4.4\"
  35. keepalive 10 120
  36. cipher AES-256-CBC
  37. user nobody
  38. group nogroup
  39. persist-key
  40. persist-tun
  41. status openvpn-status.log
  42. log openvpn.log
  43. verb 3
  44. mute 10
  45. plugin /usr/lib/x86_64-linux-gnu/openvpn/plugins/openvpn-plugin-auth-pam.so login
  46. username-as-common-name" > /etc/openvpn/server-tcp.conf
  47. echo "# OVPN CLIENT-TCP CONFIG
  48. # ----------------------------
  49. client
  50. dev tun
  51. proto tcp
  52. remote $alamat_ip 1194
  53. remote $alamat_hos 1194
  54. resolv-retry infinite
  55. nobind
  56. persist-key
  57. persist-tun
  58. remote-cert-tls server
  59. cipher AES-256-CBC
  60. auth SHA256
  61. verb 3
  62. auth-user-pass
  63. http-proxy-retry
  64. http-proxy $alamat_ip 3128
  65. ;http-proxy-option CUSTOM-HEADER Protocol HTTP/1.1
  66. ;http-proxy-option CUSTOM-HEADER Host HOSTNAME" > /etc/openvpn/client/client-tcp.ovpn
  67. echo "" >> /etc/openvpn/client/client-tcp.ovpn
  68. echo "<ca>" >> /etc/openvpn/client/client-tcp.ovpn
  69. cat /etc/openvpn/pki/ca.crt >> /etc/openvpn/client/client-tcp.ovpn
  70. echo "</ca>" >> /etc/openvpn/client/client-tcp.ovpn
  71. echo "# OVPN SERVER-UDP CONFIG
  72. # ----------------------------
  73. port 994
  74. proto udp
  75. dev tun
  76. ca /etc/openvpn/pki/ca.crt
  77. cert /etc/openvpn/pki/issued/server.crt
  78. key /etc/openvpn/pki/private/server.key
  79. dh /etc/openvpn/pki/dh.pem
  80. verify-client-cert none
  81. server 10.8.0.0 255.255.255.0
  82. ifconfig-pool-persist ipp.txt
  83. push \"redirect-gateway def1 bypass-dhcp\"
  84. push \"dhcp-option DNS 8.8.8.8\"
  85. push \"dhcp-option DNS 8.8.4.4\"
  86. keepalive 10 120
  87. cipher AES-256-CBC
  88. user nobody
  89. group nogroup
  90. persist-key
  91. persist-tun
  92. status openvpn-status.log
  93. log openvpn.log
  94. verb 3
  95. mute 10
  96. plugin /usr/lib/x86_64-linux-gnu/openvpn/plugins/openvpn-plugin-auth-pam.so login
  97. username-as-common-name" > /etc/openvpn/server-udp.conf
  98. echo "# OVPN CLIENT-UDP CONFIG
  99. # ----------------------------
  100. client
  101. dev tun
  102. proto udp
  103. remote $alamat_ip 994
  104. remote $alamat_hos 994
  105. resolv-retry infinite
  106. nobind
  107. persist-key
  108. persist-tun
  109. remote-cert-tls server
  110. cipher AES-256-CBC
  111. auth SHA256
  112. verb 3
  113. auth-user-pass" > /etc/openvpn/client/client-udp.ovpn
  114. echo "" >> /etc/openvpn/client/client-udp.ovpn
  115. echo "<ca>" >> /etc/openvpn/client/client-udp.ovpn
  116. cat /etc/openvpn/pki/ca.crt >> /etc/openvpn/client/client-udp.ovpn
  117. echo "</ca>" >> /etc/openvpn/client/client-udp.ovpn
  118. echo "# OVPN SERVER-TLS CONFIG
  119. # ----------------------------
  120. port 587
  121. proto tcp
  122. dev tun
  123. ca /etc/openvpn/pki/ca.crt
  124. cert /etc/openvpn/pki/issued/server.crt
  125. key /etc/openvpn/pki/private/server.key
  126. dh /etc/openvpn/pki/dh.pem
  127. verify-client-cert none
  128. server 10.8.0.0 255.255.255.0
  129. ifconfig-pool-persist ipp.txt
  130. script-security 2
  131. up /etc/openvpn/update-resolv-conf
  132. down /etc/openvpn/update-resolv-conf
  133. route $alamat_ip 255.255.255.255 net_gateway
  134. push \"redirect-gateway def1 bypass-dhcp\"
  135. push \"dhcp-option DNS 8.8.8.8\"
  136. push \"dhcp-option DNS 8.8.4.4\"
  137. keepalive 10 120
  138. cipher AES-256-CBC
  139. user nobody
  140. group nogroup
  141. persist-key
  142. persist-tun
  143. status openvpn-status.log
  144. log openvpn.log
  145. verb 3
  146. mute 10
  147. plugin /usr/lib/x86_64-linux-gnu/openvpn/plugins/openvpn-plugin-auth-pam.so login
  148. username-as-common-name" > /etc/openvpn/server-tls.conf
  149. echo "# OVPN CLIENT-TLS CONFIG
  150. # ----------------------------
  151. client
  152. dev tun
  153. proto tcp
  154. remote $alamat_ip 587
  155. remote $alamat_hos 587
  156. resolv-retry infinite
  157. nobind
  158. persist-key
  159. persist-tun
  160. remote-cert-tls server
  161. script-security 2
  162. up /etc/openvpn/update-resolv-conf
  163. down /etc/openvpn/update-resolv-conf
  164. route $alamat_ip 255.255.255.255 net_gateway
  165. cipher AES-256-CBC
  166. auth SHA256
  167. verb 3
  168. auth-user-pass" > /etc/openvpn/client/client-tls.ovpn
  169. echo "" >> /etc/openvpn/client/client-tls.ovpn
  170. echo "<ca>" >> /etc/openvpn/client/client-tls.ovpn
  171. cat /etc/openvpn/pki/ca.crt >> /etc/openvpn/client/client-tls.ovpn
  172. echo "</ca>" >> /etc/openvpn/client/client-tls.ovpn
  173. systemctl enable openvpn@server-tcp
  174. systemctl start openvpn@server-tcp
  175. systemctl enable openvpn@server-udp
  176. systemctl start openvpn@server-udp
  177. systemctl enable openvpn@server-tls
  178. systemctl start openvpn@server-tls
  179. echo
  180. echo -e "\033[1;32mTahniah, Kami telah selesai dengan pemasangan openvpn.\033[0m"
  181. echo
  182. echo 'Use my referral link https://m.do.co/c/a28a40414d6a'
  183. echo 'to gets $100 credit into your DigitalOcean account.'
  184. echo
  185. echo 'Hak Cipta 2021 Doctype, Dikuasakan oleh Cybertize.'
  186. sleep 5