运行环境:Ubuntu-server-22.04 lts.
#!/bin/bash
# Disable IPv6
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
# Wait for a few seconds
sleep 5
# Enable IPv6
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=0
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0
# Show the IPv6 status
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
设置定时运行脚本:
# Edit the cron table
crontab -e
# Add the following line to run the script every day at 1 AM
0 1 * * * /path/to/reset-ipv6-script.sh
根据你的实际需要定时重启ipv6即可。
声明:本站所有文章,如无特殊说明或标注,均为本站(王大神)原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。