vpn.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #!/bin/bash
  2. #
  3. # By geo
  4. # ==================================================
  5. # initialisasi var
  6. export DEBIAN_FRONTEND=noninteractive
  7. OS=`uname -m`;
  8. MYIP=$(wget -qO- 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/senowahyu62/freesc/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. client
  36. dev tun
  37. proto tcp
  38. remote xxxxxxxxx 1194
  39. resolv-retry infinite
  40. dhcp-option DNS 8.8.8.8
  41. dhcp-option DNS 8.8.4.4
  42. allow-recursive-routing
  43. ifconfig-nowarn
  44. connect-retry-max 1
  45. connect-retry 1 300
  46. resolv-retry 60
  47. connect-timeout 5
  48. tun-mtu 1342
  49. tun-mtu-extra 32
  50. mssfix 1450
  51. sndbuf 167772q6
  52. rcvbuf 16777216
  53. persist-key
  54. persist-tun
  55. ping 0
  56. ping-restart 0
  57. ping-timer-rem
  58. reneg-sec 0
  59. route-method exe
  60. nobind
  61. persist-key
  62. persist-tun
  63. pull
  64. fast-io
  65. cipher AES-256-CBC
  66. auth-user-pass
  67. comp-lzo
  68. verb 1
  69. END
  70. sed -i $MYIP2 /etc/openvpn/client-tcp-1194.ovpn;
  71. # Buat config client UDP 2200
  72. cat > /etc/openvpn/client-udp-2200.ovpn <<-END
  73. client
  74. dev tun
  75. proto udp
  76. remote xxxxxxxxx 2200
  77. resolv-retry infinite
  78. dhcp-option DNS 8.8.8.8
  79. dhcp-option DNS 8.8.4.4
  80. allow-recursive-routing
  81. ifconfig-nowarn
  82. connect-retry-max 1
  83. connect-retry 1 300
  84. resolv-retry 60
  85. connect-timeout 5
  86. tun-mtu 1342
  87. tun-mtu-extra 32
  88. mssfix 1450
  89. sndbuf 16777216
  90. rcvbuf 16777216
  91. route-method exe
  92. nobind
  93. persist-key
  94. persist-tun
  95. pull
  96. fast-io
  97. cipher AES-256-CBC
  98. auth-user-pass
  99. comp-lzo
  100. verb 1
  101. END
  102. sed -i $MYIP2 /etc/openvpn/client-udp-2200.ovpn;
  103. # Buat config client SSL
  104. cat > /etc/openvpn/client-tcp-ssl.ovpn <<-END
  105. client
  106. dev tun
  107. proto tcp
  108. remote xxxxxxxxx 442
  109. dhcp-option DNS 8.8.8.8
  110. dhcp-option DNS 8.8.4.4
  111. allow-recursive-routing
  112. ifconfig-nowarn
  113. connect-retry-max 1
  114. connect-retry 1 300
  115. resolv-retry 60
  116. connect-timeout 5
  117. tun-mtu 1342
  118. tun-mtu-extra 32
  119. mssfix 1450
  120. sndbuf 16777216
  121. rcvbuf 16777216
  122. route-method exe
  123. nobind
  124. persist-key
  125. persist-tun
  126. pull
  127. fast-io
  128. cipher AES-256-CBC
  129. auth-user-pass
  130. comp-lzo
  131. verb 1
  132. END
  133. sed -i $MYIP2 /etc/openvpn/client-tcp-ssl.ovpn;
  134. cd
  135. # pada tulisan xxx ganti dengan alamat ip address VPS anda
  136. /etc/init.d/openvpn restart
  137. # masukkan certificatenya ke dalam config client TCP 1194
  138. echo '<ca>' >> /etc/openvpn/client-tcp-1194.ovpn
  139. cat /etc/openvpn/server/ca.crt >> /etc/openvpn/client-tcp-1194.ovpn
  140. echo '</ca>' >> /etc/openvpn/client-tcp-1194.ovpn
  141. # Copy config OpenVPN client ke home directory root agar mudah didownload ( TCP 1194 )
  142. cp /etc/openvpn/client-tcp-1194.ovpn /home/vps/public_html/client-tcp-1194.ovpn
  143. # masukkan certificatenya ke dalam config client UDP 2200
  144. echo '<ca>' >> /etc/openvpn/client-udp-2200.ovpn
  145. cat /etc/openvpn/server/ca.crt >> /etc/openvpn/client-udp-2200.ovpn
  146. echo '</ca>' >> /etc/openvpn/client-udp-2200.ovpn
  147. # Copy config OpenVPN client ke home directory root agar mudah didownload ( UDP 2200 )
  148. cp /etc/openvpn/client-udp-2200.ovpn /home/vps/public_html/client-udp-2200.ovpn
  149. # masukkan certificatenya ke dalam config client SSL
  150. echo '<ca>' >> /etc/openvpn/client-tcp-ssl.ovpn
  151. cat /etc/openvpn/server/ca.crt >> /etc/openvpn/client-tcp-ssl.ovpn
  152. echo '</ca>' >> /etc/openvpn/client-tcp-ssl.ovpn
  153. # Copy config OpenVPN client ke home directory root agar mudah didownload ( SSL )
  154. cp /etc/openvpn/client-tcp-ssl.ovpn /home/vps/public_html/client-tcp-ssl.ovpn
  155. #firewall untuk memperbolehkan akses UDP dan akses jalur TCP
  156. iptables -t nat -I POSTROUTING -s 10.6.0.0/24 -o $ANU -j MASQUERADE
  157. iptables -t nat -I POSTROUTING -s 10.7.0.0/24 -o $ANU -j MASQUERADE
  158. iptables-save > /etc/iptables.up.rules
  159. chmod +x /etc/iptables.up.rules
  160. iptables-restore -t < /etc/iptables.up.rules
  161. netfilter-persistent save
  162. netfilter-persistent reload
  163. # Restart service openvpn
  164. systemctl enable openvpn
  165. systemctl start openvpn
  166. /etc/init.d/openvpn restart
  167. # Delete script
  168. history -c
  169. rm -f /root/vpn.sh