DAILY DOCDAILY DOC
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
  • linux
  • bash alias
  • chmod
  • linux useful command
  • date
  • extract translation from git diff
  • fail2ban
  • globbing
  • localhost
  • mail
  • memo 内存测试
  • nohup(no hang up)
  • setup env
  • ssh

    • ssh 教程
    • github clone
    • ssh.localhost.run 端口转发
    • ssh 安全
  • systemd service
  • 分析ubuntu系统登录日志文件
  • vpn

    • vpn 教程
    • Algo
    • clashX
    • firezone
    • lantern
    • pac 代理配置
    • Setup vpn
    • shadowsocks
    • VPN
    • VPN 速度优化
    • wireguard cron
    • 修改wireguard端口
  • webhook

wireguard cron

定时修改 wireguard 端口

details
# echo "Enter your new listenPort:"
# read ListenPort


# # Check if the input is a valid number
# if ! [[ $ListenPort =~ ^[0-9]+$ ]]; then
#   echo "Invalid listenPort Please enter a valid number."
# else
#   # Print the number
#   echo "The new listenPort you entered is: $ListenPort"
# fi



# modify /etc/wireguard/wg0.conf  ListenPort field
# ==================================
# ListenPort=6392
# ==================================
# Replace the ListenPort value in /etc/wireguard/wg0.conf

PreviousListenPort=$(grep '^ListenPort' /etc/wireguard/wg0.conf | cut -d " " -f 3)
defaultNextPort=$((PreviousListenPort + 1))

sed -i "s/ListenPort.*/ListenPort = $defaultNextPort/g" /etc/wireguard/wg0.conf
# Verify the change
grep "ListenPort" /etc/wireguard/wg0.conf
# ufw status
# ufw delete allow $PreviousListenPort/udp
# ufw allow $defaultNextPort/udp
# ufw status
wg-quick down /etc/wireguard/wg0.conf 
wg-quick up /etc/wireguard/wg0.conf
Last Updated:
Contributors: rosendo
Prev
VPN 速度优化
Next
修改wireguard端口