|
前提:面板已经调整IPv6完毕; OS为Debian Ubuntu; CentOS不适用
常见问题: 如果出现 Debian 或者 Ubuntu长期不动,说明面板IPv6没有调整好。Debian需要重启生效。有的VPS调整不出来,只能删除重开
使用方法:全部粘贴到root提示符号下面,或者做成sh采用bash执行
已经测试: Ubuntu 20.04, Debian 11
非甲骨文IPv6: 理论上也适用, 没有测试过
优点: 只需运行脚本一次,VPS重启IPv6仍然有效; 自动识别OS
原创脚本,转帖请标注
- Debian_IPv6(){iName=$(ip add | grep "^2: " | awk -F'[ :]' '{print $3}')dhclient -6 $iName #临时开启IPv6echo $iName #人工查看网卡是否正确cp /etc/network/interfaces /rootsed -i "$ a iface $iName inet6 dhcp" /etc/network/interfacesecho "Reboot... & ping ipv6.google.com After reboot"reboot}Ubuntu_IPv6(){yamlName=$(find /etc/netplan/ -iname "*.yaml")iName=$(ip add | grep "^2: " | awk -F'[ :]' '{print $3}')dhclient -6 $iNameMAC=$(ip add | grep "link/ether.*brd" | awk -F' ' '{print $2}')IPv6=$(ip add | grep "inet6.*global" | awk -F' ' '{print $2}')if [[ ${#IPv6} -lt 5 ]]; then echo "Can't IPv6"; exit 1; ficp $yamlName /root/cat <<0099 >$yamlNamenetwork: ethernets: ens3: dhcp4: true dhcp6: false match: macaddress: $MAC addresses: - $IPv6 set-name: $iName version: 20099netplan applysleep 2sping ipv6.google.com}myOS=$(hostnamectl | sed -n 's_.*System: \(\S*\).*_\1_p')#Ubuntu, Debianif [[ "$myOS" =~ "Ubuntu" ]]; then echo "Ubuntu" Ubuntu_IPv6elif [[ "$myOS" =~ "Debian" ]]; then echo "Debian" Debian_IPv6fi
复制代码 |
|