wg.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # Debian 9 & 10 64bit
  3. # Ubuntu 18.04 & 20.04 bit
  4. # Centos 7 & 8 64bit
  5. # Mod By SL
  6. # ==========================================
  7. # Color
  8. RED='\033[0;31m'
  9. NC='\033[0m'
  10. GREEN='\033[0;32m'
  11. ORANGE='\033[0;33m'
  12. BLUE='\033[0;34m'
  13. PURPLE='\033[0;35m'
  14. CYAN='\033[0;36m'
  15. LIGHT='\033[0;37m'
  16. # ==========================================
  17. # Getting
  18. MYIP=$(wget -qO- ipinfo.io/ip);
  19. echo "Checking VPS"
  20. IZIN=$( curl ipinfo.io/ip | grep $MYIP )
  21. if [ $MYIP = $MYIP ]; then
  22. echo -e "${NC}${GREEN}Permission Accepted...${NC}"
  23. else
  24. echo -e "${NC}${RED}Permission Denied!${NC}";
  25. echo -e "${NC}${LIGHT}Fuck You!!"
  26. exit 0
  27. fi
  28. # ==================================================
  29. # Link Hosting Kalian
  30. fisabiliyusri="raw.githubusercontent.com/fisabiliyusri/Mod-Script-SL/main/wireguard"
  31. # Check OS version
  32. if [[ -e /etc/debian_version ]]; then
  33. source /etc/os-release
  34. OS=$ID # debian or ubuntu
  35. elif [[ -e /etc/centos-release ]]; then
  36. source /etc/os-release
  37. OS=centos
  38. fi
  39. Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
  40. Info="${Green_font_prefix}[information]${Font_color_suffix}"
  41. if [[ -e /etc/wireguard/params ]]; then
  42. echo -e "${Info} WireGuard sudah diinstal, silahkan ketik addwg untuk menambah client."
  43. exit 1
  44. fi
  45. echo -e "${Info} Wireguard Script Mod By SL"
  46. # Detect public IPv4 address and pre-fill for the user
  47. # Detect public interface and pre-fill for the user
  48. SERVER_PUB_NIC=$(ip -o $ANU -4 route show to default | awk '{print $5}');
  49. # Install WireGuard tools and module
  50. if [[ $OS == 'ubuntu' ]]; then
  51. apt install -y wireguard
  52. elif [[ $OS == 'debian' ]]; then
  53. echo "deb http://deb.debian.org/debian/ unstable main" >/etc/apt/sources.list.d/unstable.list
  54. printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' >/etc/apt/preferences.d/limit-unstable
  55. apt update
  56. apt install -y wireguard-tools iptables iptables-persistent
  57. apt install -y linux-headers-$(uname -r)
  58. elif [[ ${OS} == 'centos' ]]; then
  59. curl -Lo /etc/yum.repos.d/wireguard.repo https://copr.fedorainfracloud.org/coprs/jdoss/wireguard/repo/epel-7/jdoss-wireguard-epel-7.repo
  60. yum -y update
  61. yum -y install wireguard-dkms wireguard-tools
  62. fi
  63. apt install iptables iptables-persistent -y
  64. # Make sure the directory exists (this does not seem the be the case on fedora)
  65. mkdir /etc/wireguard >/dev/null 2>&1
  66. chmod 600 -R /etc/wireguard/
  67. SERVER_PRIV_KEY=$(wg genkey)
  68. SERVER_PUB_KEY=$(echo "$SERVER_PRIV_KEY" | wg pubkey)
  69. # Save WireGuard settings
  70. echo "SERVER_PUB_NIC=$SERVER_PUB_NIC
  71. SERVER_WG_NIC=wg0
  72. SERVER_WG_IPV4=10.66.66.1
  73. SERVER_PORT=7070
  74. SERVER_PRIV_KEY=$SERVER_PRIV_KEY
  75. SERVER_PUB_KEY=$SERVER_PUB_KEY" >/etc/wireguard/params
  76. source /etc/wireguard/params
  77. # Add server interface
  78. echo "[Interface]
  79. Address = $SERVER_WG_IPV4/24
  80. ListenPort = $SERVER_PORT
  81. PrivateKey = $SERVER_PRIV_KEY
  82. PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o $SERVER_PUB_NIC -j MASQUERADE;
  83. PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o $SERVER_PUB_NIC -j MASQUERADE;" >>"/etc/wireguard/wg0.conf"
  84. iptables -t nat -I POSTROUTING -s 10.66.66.1/24 -o $SERVER_PUB_NIC -j MASQUERADE
  85. iptables -I INPUT 1 -i wg0 -j ACCEPT
  86. iptables -I FORWARD 1 -i $SERVER_PUB_NIC -o wg0 -j ACCEPT
  87. iptables -I FORWARD 1 -i wg0 -o $SERVER_PUB_NIC -j ACCEPT
  88. iptables -I INPUT 1 -i $SERVER_PUB_NIC -p udp --dport 7070 -j ACCEPT
  89. iptables-save > /etc/iptables.up.rules
  90. iptables-restore -t < /etc/iptables.up.rules
  91. netfilter-persistent save
  92. netfilter-persistent reload
  93. systemctl start "wg-quick@wg0"
  94. systemctl enable "wg-quick@wg0"
  95. # Check if WireGuard is running
  96. systemctl is-active --quiet "wg-quick@wg0"
  97. WG_RUNNING=$?
  98. # Tambahan
  99. cd /usr/bin
  100. wget -O addwg "https://${akbarvpn}/addwg.sh"
  101. wget -O delwg "https://${akbarvpn}/delwg.sh"
  102. wget -O renewwg "https://${akbarvpn}/renewwg.sh"
  103. chmod +x addwg
  104. chmod +x delwg
  105. chmod +x renewwg
  106. cd
  107. rm -f /root/wg.sh