port-wg.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. red='\e[1;31m'
  3. green='\e[0;32m'
  4. NC='\e[0m'
  5. MYIP=$(wget -qO- https://icanhazip.com);
  6. NIC=$(ip -o $ANU -4 route show to default | awk '{print $5}');
  7. echo "Checking VPS"
  8. clear
  9. wg="$(cat ~/log-install.txt | grep -i Wireguard | cut -d: -f2|sed 's/ //g')"
  10. echo -e " Change Port $wg"
  11. read -p "New Port Wireguard: " wg2
  12. if [ -z $wg2 ]; then
  13. echo "Please Input Port"
  14. exit 0
  15. fi
  16. cek=$(netstat -nutlp | grep -w $wg2)
  17. if [[ -z $cek ]]; then
  18. sed -i "s/$wg/$wg2/g" /etc/wireguard/wg0.conf
  19. sed -i "s/$wg/$wg2/g" /etc/wireguard/params
  20. sed -i "s/ - Wireguard : $wg/ - Wireguard : $wg2/g" /root/log-install.txt
  21. iptables -D INPUT -i $NIC -p udp --dport $wg -j ACCEPT
  22. iptables -I INPUT -i $NIC -p udp --dport $wg2 -j ACCEPT
  23. iptables-save > /etc/iptables.up.rules
  24. iptables-restore -t < /etc/iptables.up.rules
  25. netfilter-persistent save > /dev/null
  26. netfilter-persistent reload > /dev/null
  27. systemctl reload wg-quick@wg0 > /dev/null
  28. echo -e "\e[032;1mPort $wg2 modified successfully\e[0m"
  29. else
  30. echo "Port $wg2 is used"
  31. fi