port-wg.sh 872 B

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. wg="$(cat ~/log-install.txt | grep -i Wireguard | cut -d: -f2|sed 's/ //g')"
  3. echo -e " Change Port $wg"
  4. read -p "New Port Wireguard: " wg2
  5. if [ -z $wg2 ]; then
  6. echo "Please Input Port"
  7. exit 0
  8. fi
  9. cek=$(netstat -nutlp | grep -w $wg2)
  10. if [[ -z $cek ]]; then
  11. sed -i "s/$wg/$wg2/g" /etc/wireguard/wg0.conf
  12. sed -i "s/$wg/$wg2/g" /etc/wireguard/params
  13. sed -i "s/ - Wireguard : $wg/ - Wireguard : $wg2/g" /root/log-install.txt
  14. iptables -D INPUT -i $NIC -p udp --dport $wg -j ACCEPT
  15. iptables -I INPUT -i $NIC -p udp --dport $wg2 -j ACCEPT
  16. iptables-save > /etc/iptables.up.rules
  17. iptables-restore -t < /etc/iptables.up.rules
  18. netfilter-persistent save > /dev/null
  19. netfilter-persistent reload > /dev/null
  20. systemctl reload wg-quick@wg0 > /dev/null
  21. echo -e "\e[032;1mPort $wg2 modified successfully\e[0m"
  22. else
  23. echo "Port $wg2 is used"
  24. fi