wgmtu.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. #!/bin/bash
  2. # WireGuard 管理使用命令 bash wgmtu 短网址: https://git.io/wgmtu
  3. # Usage: wget https://git.io/wgmtu && bash wgmtu
  4. # 修改mtu数值
  5. setmtu(){
  6. echo -e "${GreenBG}WireGuard 修改服务器端MTU值,提高效率;默认值MTU=1420${Font}"
  7. read -p "请输入数字(1200--1500): " num
  8. if [[ ${num} -ge 1200 ]] && [[ ${num} -le 1500 ]]; then
  9. mtu=$num
  10. else
  11. mtu=1420
  12. fi
  13. ip link set mtu $num up dev wg0
  14. wg-quick save wg0
  15. echo -e "${SkyBlue}:: 服务器端MTU值已经修改!${Font}"
  16. }
  17. # 修改端口号
  18. setport(){
  19. echo -e "${GreenBG}修改 WireGuard 服务器端端口号,客户端要自行修改${Font}"
  20. read -p "请输入数字(100--60000): " num
  21. if [[ ${num} -ge 100 ]] && [[ ${num} -le 60000 ]]; then
  22. port=$num
  23. wg set wg0 listen-port $port
  24. wg-quick save wg0
  25. echo -e "${SkyBlue}:: 端口号已经修改, 客户端请手工修改! ${Font}"
  26. else
  27. echo -e "${Red}:: 没有修改端口号!${Font}"
  28. fi
  29. }
  30. # 显示客户端配置和手机二维码
  31. conf_QRcode(){
  32. echo -e "${Yellow}:: 显示客户端配置和手机二维码 (默认2号),请输入数字${Font}\c"
  33. read -p "(2-9): " x
  34. if [[ ${x} -ge 2 ]] && [[ ${x} -le 9 ]]; then
  35. i=$x
  36. else
  37. i=2
  38. fi
  39. host=$(hostname -s)
  40. echo -e "${SkyBlue}:: 客户端配置文件: wg_${host}_$i.conf ${Font}"
  41. cat /etc/wireguard/wg_${host}_$i.conf
  42. echo -e "${SkyBlue}:: 请使用组合键 Ctrl+Ins 复制文本给Windows客户端使用${Font}"
  43. cat /etc/wireguard/wg_${host}_$i.conf | qrencode -o - -t UTF8
  44. echo -e "${Green}:: 配置文件: wg_${host}_$i.conf 生成二维码,请用手机客户端扫描使用${Font}"
  45. echo -e "${SkyBlue}:: 安卓手机WireGuard官方APP目前支持纯IPV6连接,是否显示IPV6二维码?${Font}\c"
  46. read -p "(Y/N): " key
  47. case $key in
  48. Y)
  49. ipv6_QRcode $i
  50. ;;
  51. y)
  52. ipv6_QRcode $i
  53. ;;
  54. esac
  55. echo -e "${SkyBlue}:: SSH工具推荐Git-Bash 2.20; GCP_SSH(浏览器)字体Courier New 二维码正常${Font}"
  56. }
  57. # 显示IPV6手机客户端二维码
  58. ipv6_QRcode(){
  59. if [[ $# > 0 ]]; then
  60. i="$1"
  61. fi
  62. get_serverip
  63. serveripv6=$(curl -6 ip.sb)
  64. if [[ -z $serveripv6 ]]; then
  65. echo -e "${Red}:: 获取IPV6地址不正确,你的服务器可能没有IPV6网络支持!${Font}"
  66. else
  67. cat /etc/wireguard/wg_${host}_$i.conf | sed "s/${serverip}/[${serveripv6}]/g" | qrencode -o - -t UTF8
  68. echo -e "${Green}:: IPV6地址: [${serveripv6}] 请确认服务器和本地网络支持IPV6!${Font}"
  69. fi
  70. }
  71. get_serverip(){
  72. if [ ! -e '/var/ip_addr' ]; then
  73. echo -n $(curl -s https://262235.xyz/ip/) > /var/ip_addr
  74. fi
  75. serverip=$(cat /var/ip_addr)
  76. ipv6_range="fd08:620c:4df0:65eb::"
  77. }
  78. # 重置 WireGuard 客户端配置和数量
  79. wg_clients(){
  80. echo -e "${Red}:: 注意原来的客户端配置都会删除,按 Ctrl+ C 可以紧急撤销 ${Font}"
  81. # 转到wg配置文件目录
  82. cd /etc/wireguard
  83. cp wg0.conf conf.wg0.bak
  84. echo -e "${SkyBlue}:: 输入客户端Peer总数${Font}\c"
  85. read -p "(2--200): " num_x
  86. if [[ ${num_x} -ge 2 ]] && [[ ${num_x} -le 200 ]]; then
  87. wg_num=OK
  88. else
  89. num_x=3
  90. fi
  91. # 服务器 IP 和 端口
  92. port=$(wg show wg0 listen-port) && host=$(hostname -s)
  93. get_serverip
  94. # 删除原配置,让IP和ID号对应; 保留原来服务器的端口等配置
  95. rm /etc/wireguard/wg_${host}_* >/dev/null 2>&1
  96. line_num=$(cat -n wg0.conf | grep 'AllowedIPs' | head -n 1 | awk '{print $1}')
  97. head -n ${line_num} conf.wg0.bak > wg0.conf
  98. # 重启wg服务器
  99. wg-quick down wg0 >/dev/null 2>&1
  100. wg-quick up wg0 >/dev/null 2>&1
  101. # 重新生成用户配置数量
  102. for i in `seq 2 200`
  103. do
  104. ip=10.0.0.${i}
  105. ip6=${ipv6_range}${i}
  106. wg genkey | tee cprivatekey | wg pubkey > cpublickey
  107. wg set wg0 peer $(cat cpublickey) allowed-ips "${ip}/32, ${ip6}"
  108. cat <<EOF >wg_${host}_$i.conf
  109. [Interface]
  110. PrivateKey = $(cat cprivatekey)
  111. Address = $ip/24, $ip6/64
  112. DNS = 8.8.8.8, 2001:4860:4860::8888
  113. [Peer]
  114. PublicKey = $(wg show wg0 public-key)
  115. Endpoint = $serverip:$port
  116. AllowedIPs = 0.0.0.0/0, ::0/0
  117. PersistentKeepalive = 25
  118. EOF
  119. cat wg_${host}_$i.conf | qrencode -o wg_${host}_$i.png
  120. if [ $i -ge $num_x ]; then break; fi
  121. done
  122. wg-quick save wg0
  123. clear && display_peer
  124. cat /etc/wireguard/wg_${host}_2.conf
  125. echo -e "${SkyBlue}:: 使用${GreenBG} bash wg5 ${SkyBlue}命令,可以临时网页下载配置和二维码${Font}"
  126. }
  127. # 安装 WireGuard+Speeder+Udp2Raw 和 SS+Kcp+Udp2RAW 配置
  128. ss_kcp_udp2raw_wg_speed(){
  129. # 下载/编译 shadowsocks-libev
  130. wget -qO- git.io/fhExJ | bash
  131. wget -O ~/ss_wg_set_raw git.io/fpKnF >/dev/null 2>&1
  132. bash ~/ss_wg_set_raw
  133. rm ~/ss_wg_set_raw
  134. }
  135. # 常用工具和配置
  136. get_tools_conf(){
  137. apt install -y htop tmux curl wget vim psmisc bash-completion ca-certificates locales
  138. # yum install -y vim htop tmux screen iperf3 >/dev/null 2>&1
  139. cd ~
  140. wget -O .vimrc --no-check-certificate https://raw.githubusercontent.com/hongwenjun/srgb/master/vim/_vimrc
  141. wget -O .bashrc --no-check-certificate https://raw.githubusercontent.com/hongwenjun/srgb/master/vim/_bashrc
  142. wget -O .tmux.conf --no-check-certificate https://raw.githubusercontent.com/hongwenjun/tmux_for_windows/master/.tmux.conf
  143. }
  144. # 慎用 authorized_keys
  145. authorized_keys(){
  146. mkdir -p ~/.ssh && cd ~/.ssh
  147. cat <<EOF >> authorized_keys
  148. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDm5IXhVxCp317F3X+VEKmLPNiIGigbX4eot3EPIizbHHVURVOEXbxlN5tqQPmFt62qex4GhXmOfcMmLcaDwrkci7A3dPlnjRukYBDK3jQtzjVexTvNqcblTKj2aEpZg5Z8Z5vCOVrOfCdXOngqi/NkItvsid2DLzqi7KTpdFpgZGSwpV2h3E3U0N18uBLQwDj3ag2mUT7X2kx4t4DYbQDWyGt+bbivnTHV0k/BZJPwqnPD2tpyH19lKWvL3fm3gjoMkTtxDzEXHpTmTe95Z1AKzOfY1reEZ+dHAWy0wHmCA1by1XJtagoeTVqa+IS1wfOimwJE/oIofhDjSNjsMk63 root
  149. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDB1yzgEUtS0t5GUW2lVeZpWEn6YDI8x3nIMzjQscIL3Z9QDvyONohC58t6kHQtgj7+/5pQnzaPOz0qFuDolqQOp9D8tiUJIEYHc8PA7WGxRKwS7L2j0ia7FleGAKyhi9tR6TqY4T9Vny9g8VetRBzaMz+WAv8FHYDLfQq+Wcrx1GJgYiiNp0UWEMWrY50K1vub6rtk7xNUhiDGlfEsLxgKTaDUwQ/sEcyu/ZTEIlaaSPLsIuaWKJvIrnicmYIP7jZ3S4k7De/UZo87EXo6PQGhyJCDBYWXPd0Ng7XavXbm8MoRb5+Go9zn04f8oBHuqLJhSyrLFIFhPmEogKvpJ/Xd vip@cloudshell
  150. EOF
  151. }
  152. # 主菜单输入数字 88 # 隐藏功能:从源VPS克隆服务端配置,获得常用工具和配置
  153. scp_conf(){
  154. echo -e "${RedBG}:: 警告: 警告: 警告:${Yellow} VPS服务器已经被GFW防火墙关照,按 Ctrl+ C 可以紧急逃离! ${Font}"
  155. # echo_SkyBlue ":: 隐藏功能: 从源VPS克隆服务端配置,共用客户端配置"
  156. # read -p ":: 请输入源VPS的IP地址(域名):" vps_ip
  157. # cmd="scp root@${vps_ip}:/etc/wireguard/* /etc/wireguard/. "
  158. # echo -e "${GreenBG}# ${cmd} ${Font} 现在运行scp命令,按提示输入yes,源vps的root密码"
  159. # ${cmd}
  160. # wg-quick down wg0 >/dev/null 2>&1
  161. # wg-quick up wg0 >/dev/null 2>&1
  162. # echo -e "${RedBG} 我真不知道WG服务器端是否已经使用源vps的配置启动! ${Font}"
  163. authorized_keys
  164. get_tools_conf
  165. }
  166. # DEBIAN LOCALE LANGUAGE SETTINGS
  167. en_US()
  168. {
  169. cat <<EOF >/etc/default/locale
  170. LANG=en_US.UTF-8
  171. EOF
  172. echo -e "Please log in again on Debian tty1"
  173. }
  174. zh_CN()
  175. {
  176. cat <<EOF >/etc/default/locale
  177. # 中文显示
  178. LANG="zh_CN.UTF-8"
  179. LANGUAGE="zh_CN:zh"
  180. EOF
  181. echo -e ":: 仅支持本身中文系统切换回中文!"
  182. echo -e "Please log in again on Debian tty1"
  183. }
  184. ipinfo(){
  185. echo_GreenBG ":: 统计自己电信服务商IP动态变化 ::"
  186. echo -e "${Green}"
  187. # 应用: 统计自己电信服务商IP动态变化
  188. cat /var/log/udp2raw.log \
  189. | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort | uniq -c| sort -nrk 1
  190. echo -e
  191. echo_RedBG ":: 抠脚大叔在窥视你的小鸡 ::"
  192. echo -e "${Red}"
  193. # 统计哪些IP在扫描你的vps
  194. cat /var/log/auth.log \
  195. | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | sort | uniq -c| sort -nrk 1
  196. echo -e
  197. echo_GreenBG ":: 查询IP信息和物理地址 https://www.ipip.net/ipquery.html"
  198. echo -e
  199. echo_Yellow ":: 当前${RedBG} 服务器IP: ${Yellow} $(cat /var/ip_addr) ${Font} ::"
  200. }
  201. # 创建容器: qbittorrent
  202. docker_qb(){
  203. docker run --name=qbittorrent \
  204. -e PUID=1000 -e PGID=1000 \
  205. -e TZ=Asia/ShangHai \
  206. -e UMASK_SET=022 -e \
  207. WEBUI_PORT=8080 \
  208. -p 59902:59902 \
  209. -p 59902:59902/udp \
  210. -p 8080:8080 \
  211. -v /mnt/config:/config \
  212. -v /mnt/downloads:/downloads \
  213. --restart unless-stopped \
  214. -d linuxserver/qbittorrent
  215. # 浏览器中输入网址管理
  216. echo -e http://$(curl -s https://262235.xyz/ip/):8080
  217. echo -e "${GreenBG}:: qbittorrent 网页管理地址和密码 ${Yellow}"
  218. echo -e "${SkyBlue}:: 默认用户名 ${RedBG} admin ${SkyBlue} 密码 ${RedBG} adminadmin ${Font} "
  219. echo -e ":: 请登陆配置Peer端口(59902)和密码, 重启命令: ${GreenBG} docker restart qbittorrent ${Font}"
  220. }
  221. # 安装tcping
  222. tcping_install(){
  223. wget https://github.com/cloverstd/tcping/releases/download/v0.1.1/tcping-linux-amd64-v0.1.1.tar.gz
  224. tar xf tcping-linux-amd64-v0.1.1.tar.gz
  225. mv tcping /usr/bin/tcping
  226. tcping 1.1.1.1 53
  227. rm tcping-linux-amd64-v0.1.1.tar.gz
  228. }
  229. # 安装 autopt 自动PT
  230. autopt_install(){
  231. wget git.io/autopt.sh && bash autopt.sh
  232. }
  233. # 一键 WordPress 博客安装脚本
  234. lnmp_install(){
  235. wget git.io/lnmp.sh && bash lnmp.sh
  236. }
  237. # 安装Docker可视化界面Portainer
  238. portainer_install(){
  239. docker run --name Portainer \
  240. --restart=always -d -p 9000:9000 \
  241. -v /var/run/docker.sock:/var/run/docker.sock \
  242. -v /opt/portainer_data:/data \
  243. portainer/portainer
  244. # 浏览器中输入网址管理
  245. echo -e "${GreenBG}:: Docker可视化界面Portainer 管理地址 ${Yellow}"
  246. echo -e http://$(curl -s https://262235.xyz/ip/):9000
  247. }
  248. # 部署 nginx-php 和 php 相册
  249. photo_install(){
  250. downloads=/mnt/downloads
  251. docker run -d -p 80:80 -p 443:443 \
  252. --cpus 0.6 --restart=always \
  253. -v ${downloads}:/var/www/html \
  254. --name nginx-php \
  255. hongwenjun/nginx-php
  256. cd ${downloads}
  257. wget https://github.com/hongwenjun/srgb/raw/master/files.photo.gallery/index.php
  258. mkdir -p _files
  259. chown -R www-data:www-data _files
  260. chmod 0777 _files/
  261. echo -e "${GreenBG}:: 部署nginx-php和php相册,挂载目录: ${SkyBlue} ${downloads} ${Font}"
  262. echo -e http://$(curl -s https://262235.xyz/ip/)
  263. }
  264. # 定义文字颜色
  265. Green="\033[32m" && Red="\033[31m" && GreenBG="\033[42;37m" && RedBG="\033[41;37m"
  266. Font="\033[0m" && Yellow="\033[0;33m" && SkyBlue="\033[0;36m"
  267. echo_SkyBlue(){
  268. echo -e "${SkyBlue}$1${Font}"
  269. }
  270. echo_Yellow(){
  271. echo -e "${Yellow}$1${Font}"
  272. }
  273. echo_GreenBG(){
  274. echo -e "${GreenBG}$1${Font}"
  275. }
  276. echo_RedBG(){
  277. echo -e "${RedBG}$1${Font}"
  278. }
  279. # Vps_Setup 一键脚本 藏经阁
  280. onekey_plus(){
  281. echo_RedBG " 一键安装设置全家桶 by 蘭雅sRGB "
  282. echo_GreenBG " 开源项目:https://github.com/hongwenjun/vps_setup "
  283. echo_SkyBlue " # 一键安装 WireGuard Shadowsocks V2Ray 服务端三合一脚本"
  284. echo_Yellow " bash <(curl -L -s https://git.io/vps.sh)"
  285. echo_SkyBlue " # 下载 IPTABLES 设置防火墙规则 脚本 By 蘭雅sRGB"
  286. echo_Yellow " wget -qO safe_iptables.sh git.io/fhUSe && bash safe_iptables.sh"
  287. echo_SkyBlue " # Google Cloud Platform GCP实例开启密码与root用户登陆"
  288. echo_Yellow " wget -qO- git.io/fpQWf | bash"
  289. echo_SkyBlue " # 一键安装 vnstat 流量检测 by 蘭雅sRGB"
  290. echo_Yellow " bash <(curl -L -s https://git.io/fxxlb) setup"
  291. echo_SkyBlue " # 一键安装wireguard 脚本 For Debian_9 Ubuntu Centos_7"
  292. echo_Yellow " wget -qO- git.io/fptwc | bash"
  293. echo_SkyBlue " # 一键安装 SS+Kcp+Udp2Raw 脚本 快速安装 for Debian 9"
  294. echo_Yellow " wget -qO- git.io/fpZIW | bash"
  295. echo_SkyBlue " # 一键安装 SS+Kcp+Udp2Raw 脚本 for Debian 9 Ubuntu (编译安装)"
  296. echo_Yellow " wget -qO- git.io/fx6UQ | bash"
  297. echo_SkyBlue " # Telegram 代理 MTProxy Go版 一键脚本(源:逗比网)"
  298. echo_Yellow " wget -qO mtproxy_go.sh git.io/fpWo4 && bash mtproxy_go.sh"
  299. echo_SkyBlue " # linux下golang环境搭建自动脚本 by 蘭雅sRGB"
  300. echo_Yellow " wget -qO- https://git.io/fp4jf | bash"
  301. echo_SkyBlue " # SuperBench.sh 一键测试服务器的基本参数"
  302. echo_Yellow " wget -qO- git.io/superbench.sh | bash"
  303. echo_SkyBlue " # 使用BestTrace查看VPS的去程和回程"
  304. echo_Yellow " wget -qO- git.io/fp5lf | bash"
  305. echo_SkyBlue " # 挂载GD网盘 安装rclone官方脚本"
  306. echo_Yellow " curl https://rclone.org/install.sh | sudo bash"
  307. echo_SkyBlue " # 安装Docker软件一键脚本"
  308. echo_Yellow " curl -fsSLo- get.docker.com | /bin/sh"
  309. echo_SkyBlue " # 另一个Linux服务器基准脚本"
  310. echo_Yellow " curl -sL yabs.sh | bash"
  311. }
  312. safe_iptables(){
  313. # IPTABLES 设置防火墙规则 脚本 By 蘭雅sRGB 特别感谢 TaterLi 指导
  314. wget -qO safe_iptables.sh git.io/fhUSe && bash safe_iptables.sh
  315. }
  316. # 更新wgmtu脚本
  317. update_self(){
  318. # 安装 bash wgmtu 脚本用来设置服务器
  319. wget -O ~/wgmtu https://git.io/wgmtu >/dev/null 2>&1
  320. }
  321. # 更新 WireGuard
  322. wireguard_update(){
  323. yum update -y wireguard-dkms wireguard-tools >/dev/null 2>&1
  324. apt update -y wireguard-dkms wireguard-tools >/dev/null 2>&1
  325. echo -e "${RedBG} 更新完成 ${Font}"
  326. }
  327. # 卸载 WireGuard
  328. wireguard_remove(){
  329. wg-quick down wg0
  330. yum remove -y wireguard-dkms wireguard-tools >/dev/null 2>&1
  331. apt remove -y wireguard-dkms wireguard-tools >/dev/null 2>&1
  332. rm -rf /etc/wireguard/
  333. echo -e "${RedBG} 卸载完成 ${Font}"
  334. }
  335. # 更新/安装 UDP2RAW KCPTUN UDPspeeder 工具
  336. udp2raw_update()
  337. {
  338. systemctl stop rc-local
  339. # 下载 UDP2RAW
  340. udp2raw_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/wangyu-/udp2raw-tunnel/releases/latest | grep 'tag_name' | cut -d\" -f4)
  341. wget https://github.com/wangyu-/udp2raw-tunnel/releases/download/${udp2raw_ver}/udp2raw_binaries.tar.gz
  342. tar xf udp2raw_binaries.tar.gz
  343. mv udp2raw_amd64 /usr/bin/udp2raw
  344. rm udp2raw* -rf
  345. rm version.txt
  346. # 下载 KCPTUN
  347. kcp_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/xtaci/kcptun/releases/latest | grep 'tag_name' | cut -d\" -f4)
  348. kcp_gz_ver=${kcp_ver:1:8}
  349. kcptun_tar_gz=kcptun-linux-amd64-${kcp_gz_ver}.tar.gz
  350. wget https://github.com/xtaci/kcptun/releases/download/${kcp_ver}/$kcptun_tar_gz
  351. tar xf $kcptun_tar_gz
  352. mv server_linux_amd64 /usr/bin/kcp-server
  353. rm $kcptun_tar_gz
  354. rm client_linux_amd64
  355. # 下载 UDPspeeder
  356. udpspeeder_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/wangyu-/UDPspeeder/releases/latest | grep 'tag_name' | cut -d\" -f4)
  357. wget https://github.com/wangyu-/UDPspeeder/releases/download/${udpspeeder_ver}/speederv2_binaries.tar.gz
  358. tar xf speederv2_binaries.tar.gz
  359. mv speederv2_amd64 /usr/bin/speederv2
  360. rm speederv2* -rf
  361. rm version.txt
  362. systemctl restart rc-local
  363. ps aux | grep -e kcp -e udp -e speed -e ss-server
  364. ss-server -h | head -2 && kcp-server -v && udp2raw -h | head -2 && speederv2 -h | head -2
  365. }
  366. rc-local_remove(){
  367. echo -e "${RedBG} 卸载Udp2Raw套接服务配置 /etc/rc.local ${Font}"
  368. systemctl stop rc-local
  369. rm /usr/bin/udp2raw /usr/bin/kcp-server /usr/bin/speederv2
  370. ps aux | grep -e kcp -e udp -e speed
  371. mv /etc/rc.local ~/rc.local
  372. echo -e "${RedBG} 卸载完成,备份在 /root/rc.local ${Font}"
  373. }
  374. update_remove_menu(){
  375. echo -e "${RedBG} 更新/卸载 WireGuard服务端和Udp2Raw ${Font}"
  376. echo -e "${Green}> 1. 更新 WireGuard 服务端"
  377. echo -e "> 2. 卸载 WireGuard 服务端"
  378. echo -e "> 3. 更新 Udp2Raw KCPTUN UDPspeeder 软件"
  379. echo -e "> 4. 卸载 Udp2Raw KCPTUN UDPspeeder 服务套件"
  380. echo -e "> 5. 退出${Font}"
  381. echo
  382. read -p "请输入数字(1-5):" num_x
  383. case "$num_x" in
  384. 1)
  385. wireguard_update
  386. ;;
  387. 2)
  388. wireguard_remove
  389. ;;
  390. 3)
  391. udp2raw_update
  392. ;;
  393. 4)
  394. rc-local_remove
  395. ;;
  396. 5)
  397. exit 1
  398. ;;
  399. *)
  400. ;;
  401. esac
  402. }
  403. # 删除末尾的Peer
  404. del_last_peer(){
  405. peer_key=$(wg show wg0 allowed-ips | tail -1 | awk '{print $1}')
  406. wg set wg0 peer $peer_key remove
  407. wg-quick save wg0
  408. echo -e "${SkyBlue}:: 删除客户端 peer: ${Yellow} ${peer_key} ${SkyBlue} 完成.${Font}"
  409. }
  410. # 显示激活Peer表
  411. display_peer(){
  412. # peer和ip表写临时文件
  413. wg show wg0 allowed-ips > /tmp/peer_list
  414. # 显示 peer和ip表
  415. echo -e "${RedBG} ID ${GreenBG} Peer: <base64 public key> ${SkyBlue} IP_Addr: ${Font}"
  416. i=1
  417. while read -r line || [[ -n $line ]]; do
  418. peer=$(echo $line | awk '{print $1}')
  419. ip=$(echo $line | awk '{print $2}')
  420. line="> ${Red}${i} ${Yellow}${peer}${Font} ${ip}"
  421. echo -e $line && let i++
  422. done < /tmp/peer_list
  423. }
  424. # 选择删除Peer客户端
  425. del_peer(){
  426. display_peer
  427. echo
  428. echo -e "${RedBG}请选择 IP_Addr 对应 ID 号码,指定客户端配置将删除! ${Font}"
  429. read -p "请输入ID号数字(1-X):" x
  430. peer_cnt=$(cat /tmp/peer_list | wc -l)
  431. if [[ ${x} -ge 1 ]] && [[ ${x} -le ${peer_cnt} ]]; then
  432. i=$x
  433. peer_key=$(cat /tmp/peer_list | head -n $i | tail -1 | awk '{print $1}')
  434. wg set wg0 peer $peer_key remove
  435. wg-quick save wg0
  436. echo -e "${SkyBlue}:: 删除客户端 peer: ${Yellow} ${peer_key} ${SkyBlue} 完成.${Font}"
  437. else
  438. echo -e "${SkyBlue}:: 命令使用: ${GreenBG} wg set wg0 peer <base64 public key> remove ${Font}"
  439. fi
  440. rm /tmp/peer_list
  441. }
  442. # 添加新的客户端peer
  443. add_peer(){
  444. # 服务器 IP 端口 ,新客户端 序号和IP
  445. port=$(wg show wg0 listen-port)
  446. get_serverip && host=$(hostname -s) && cd /etc/wireguard
  447. wg genkey | tee cprivatekey | wg pubkey > cpublickey
  448. ipnum=$(wg show wg0 allowed-ips | tail -1 | awk '{print $2}' | awk -F '[./]' '{print $4}')
  449. i=$((10#${ipnum}+1)) && ip=10.0.0.${i} ip6=${ipv6_range}${i}
  450. # 生成客户端配置文件
  451. cat <<EOF >wg_${host}_$i.conf
  452. [Interface]
  453. PrivateKey = $(cat cprivatekey)
  454. Address = $ip/24, $ip6/64
  455. DNS = 8.8.8.8, 2001:4860:4860::8888
  456. [Peer]
  457. PublicKey = $(wg show wg0 public-key)
  458. Endpoint = $serverip:$port
  459. AllowedIPs = 0.0.0.0/0, ::0/0
  460. PersistentKeepalive = 25
  461. EOF
  462. # 在wg服务器中生效客户端peer
  463. wg set wg0 peer $(cat cpublickey) allowed-ips "${ip}/32, ${ip6}"
  464. wg-quick save wg0
  465. # 显示客户端
  466. cat /etc/wireguard/wg_${host}_$i.conf | qrencode -o wg_${host}_$i.png
  467. cat /etc/wireguard/wg_${host}_$i.conf | qrencode -o - -t UTF8
  468. echo -e "${SkyBlue}:: 新客户端peer添加完成; 文件:${Yellow} /etc/wireguard/wg_${host}_$i.conf ${Font}"
  469. cat /etc/wireguard/wg_${host}_$i.conf
  470. }
  471. wg_clients_menu(){
  472. echo -e "${RedBG} 添加/删除 WireGuard Peer 客户端管理 ${Font}"
  473. echo -e "${Green}> 1. 添加一个 WireGuard Peer 客户端配置"
  474. echo -e "> 2. 删除末尾 WireGuard Peer 客户端配置"
  475. echo -e "> 3. 指定删除 WireGuard Peer 客户端配置"
  476. echo "------------------------------------------------------"
  477. echo -e "${SkyBlue}> 4. 退出"
  478. echo -e "> 5.${RedBG} 重置 WireGuard 客户端 Peer 数量 ${Font}"
  479. echo
  480. read -p "请输入数字(1-5):" num_x
  481. case "$num_x" in
  482. 1)
  483. add_peer
  484. ;;
  485. 2)
  486. del_last_peer
  487. ;;
  488. 3)
  489. del_peer
  490. ;;
  491. 4)
  492. display_peer
  493. exit 1
  494. ;;
  495. 5)
  496. wg_clients
  497. ;;
  498. *)
  499. ;;
  500. esac
  501. }
  502. # 设置菜单
  503. start_menu(){
  504. clear
  505. echo -e "${RedBG} 一键安装 WireGuard 脚本 For Debian_9 Ubuntu Centos_7 ${Font}"
  506. echo -e "${GreenBG} 开源项目: https://github.com/hongwenjun/vps_setup ${Font}"
  507. echo -e "${Green}> 1. 显示客户端配置和二维码 (手机支持纯IPV6,稳定性有待测试)"
  508. echo -e "> 2. 修改 WireGuard 服务器端 MTU 值"
  509. echo -e "> 3. 修改 WireGuard 端口号"
  510. echo -e "> 4. 安装 WireGuard+Speeder+Udp2Raw 和 SS+Kcp+Udp2RAW 一键脚本"
  511. echo "----------------------------------------------------------"
  512. echo -e "${SkyBlue}> 5. 添加/删除 WireGuard Peer 客户端管理"
  513. echo -e "> 6. 更新/卸载 WireGuard服务端和Udp2Raw"
  514. echo -e "> 7. Replace the Script itself with Simplified Chinese to English"
  515. echo -e "> 8. ${RedBG} IPTABLES 防火墙设置脚本 ${Font}"
  516. echo
  517. echo_SkyBlue "Usage: ${GreenBG} bash wgmtu ${SkyBlue} [ setup | remove | vps | bench | -U ] "
  518. echo_SkyBlue " [ v2ray | vnstat | log | trace | -h ] "
  519. echo_SkyBlue " [ tr|qb | docker |rclone|ip|en |yabs] "
  520. echo_SkyBlue " [ tcping|autopt|portainer|photo|lnmp] "
  521. echo
  522. read -p "请输入数字(1-8):" num
  523. case "$num" in
  524. 1)
  525. conf_QRcode
  526. ;;
  527. 2)
  528. setmtu
  529. ;;
  530. 3)
  531. setport
  532. ;;
  533. 4)
  534. ss_kcp_udp2raw_wg_speed
  535. ;;
  536. 5)
  537. wg_clients_menu
  538. ;;
  539. 6)
  540. update_remove_menu
  541. update_self
  542. exit 1
  543. ;;
  544. 7)
  545. wget -O ~/wgmtu https://raw.githubusercontent.com/hongwenjun/vps_setup/english/wgmtu.sh
  546. bash wgmtu
  547. exit 1
  548. ;;
  549. 777)
  550. # Vps_Setup 一键脚本 藏经阁
  551. onekey_plus
  552. ;;
  553. 8)
  554. safe_iptables
  555. ;;
  556. ip)
  557. ipinfo
  558. ;;
  559. tr)
  560. # Debian 安装 Transmission 一键脚本
  561. wget https://raw.githubusercontent.com/hongwenjun/vps_setup/master/rclone/transmission.sh
  562. bash transmission.sh
  563. ;;
  564. qb)
  565. docker_qb
  566. ;;
  567. autopt)
  568. autopt_install
  569. ;;
  570. lnmp)
  571. lnmp_install
  572. ;;
  573. portainer)
  574. portainer_install
  575. ;;
  576. photo)
  577. photo_install
  578. ;;
  579. tcping)
  580. tcping_install
  581. ;;
  582. # 菜单输入 管理命令 bash wgmtu 命令行参数
  583. setup)
  584. ss_kcp_udp2raw_wg_speed
  585. ;;
  586. remove)
  587. wireguard_remove
  588. rc-local_remove
  589. ;;
  590. 88)
  591. scp_conf
  592. ;;
  593. 9999)
  594. bash <(curl -L -s https://git.io/fpnQt) 9999
  595. ;;
  596. -U)
  597. update_self
  598. ;;
  599. -h)
  600. wgmtu_help
  601. ;;
  602. vps)
  603. bash <(curl -L -s https://git.io/vps.sh)
  604. ;;
  605. docker)
  606. curl -fsSLo- get.docker.com | /bin/sh
  607. ;;
  608. rclone)
  609. curl https://rclone.org/install.sh | bash
  610. ;;
  611. en)
  612. en_US
  613. ;;
  614. cn)
  615. zh_CN
  616. ;;
  617. vnstat)
  618. bash <(curl -L -s https://git.io/fxxlb) setup
  619. ;;
  620. bench)
  621. wget -qO- git.io/superbench.sh | bash
  622. ;;
  623. yabs)
  624. curl -sL yabs.sh | bash
  625. ;;
  626. trace)
  627. wget -qO- git.io/fp5lf | bash
  628. ;;
  629. v2ray)
  630. bash <(curl -L -s https://git.io/v2ray.ss)
  631. ;;
  632. log)
  633. cat vps_setup.log
  634. ;;
  635. *)
  636. display_peer
  637. ;;
  638. esac
  639. }
  640. wgmtu_help(){
  641. echo_SkyBlue "Usage: ${GreenBG} bash wgmtu ${SkyBlue} [ setup | remove | vps | bench | -U ] "
  642. echo_SkyBlue " [ v2ray | vnstat | log | trace | -h ] "
  643. echo_SkyBlue " [ tr|qb | docker |rclone|ip|en |yabs] "
  644. echo_SkyBlue " [ tcping|autopt|portainer|photo|lnmp] "
  645. echo
  646. echo_Yellow "[setup 惊喜 | remove 卸载 | vps 脚本 | bench 基准测试 | -U 更新]"
  647. echo_Yellow "[v2ray 你懂 | vnstat 流量 | log 信息 | trace 网络回程 | -h 帮助]"
  648. echo_Yellow "[tr|qb PT下载 | docker 容器安装 | rclone G D网盘 | yabs 测试]"
  649. echo_Yellow "[tcping工具|autopt 自动PT|portainer 管理|photo相册 |lnmp wp博客]"
  650. }
  651. # WireGuard 管理命令 bash wgmtu 命令行参数
  652. if [[ $# > 0 ]]; then
  653. key="$1"
  654. case $key in
  655. setup)
  656. ss_kcp_udp2raw_wg_speed
  657. ;;
  658. remove)
  659. wireguard_remove
  660. rc-local_remove
  661. ;;
  662. 88)
  663. scp_conf
  664. ;;
  665. 9999)
  666. bash <(curl -L -s https://git.io/fpnQt) 9999
  667. ;;
  668. -U)
  669. update_self
  670. ;;
  671. -h)
  672. wgmtu_help
  673. ;;
  674. vps)
  675. bash <(curl -L -s https://git.io/vps.sh)
  676. ;;
  677. ip)
  678. ipinfo
  679. ;;
  680. tr)
  681. # Debian 安装 Transmission 一键脚本
  682. wget https://raw.githubusercontent.com/hongwenjun/vps_setup/master/rclone/transmission.sh
  683. bash transmission.sh
  684. ;;
  685. qb)
  686. docker_qb
  687. ;;
  688. docker)
  689. curl -fsSLo- get.docker.com | /bin/sh
  690. ;;
  691. autopt)
  692. autopt_install
  693. ;;
  694. lnmp)
  695. lnmp_install
  696. ;;
  697. portainer)
  698. portainer_install
  699. ;;
  700. photo)
  701. photo_install
  702. ;;
  703. tcping)
  704. tcping_install
  705. ;;
  706. rclone)
  707. curl https://rclone.org/install.sh | bash
  708. ;;
  709. en)
  710. en_US
  711. ;;
  712. cn)
  713. zh_CN
  714. ;;
  715. vnstat)
  716. bash <(curl -L -s https://git.io/fxxlb) setup
  717. ;;
  718. bench)
  719. wget -qO- git.io/superbench.sh | bash
  720. ;;
  721. yabs)
  722. curl -sL yabs.sh | bash
  723. ;;
  724. trace)
  725. wget -qO- git.io/fp5lf | bash
  726. ;;
  727. v2ray)
  728. bash <(curl -L -s https://git.io/v2ray.ss)
  729. ;;
  730. log)
  731. cat vps_setup.log
  732. ;;
  733. esac
  734. else
  735. start_menu
  736. fi