[Bash shell] 纯文本查看 复制代码 #!/bin/bash
# Author: Ropon
# Blog: [url]https://www.ropon.top[/url]
eth0f="/etc/sysconfig/network-scripts/ifcfg-eth0"
resf="/etc/resolv.conf"
ipv6=""
ipgw=""
restartflag=0
Help() {
echo "Usage: ./$(basename $0) -s[-b] ipv6 [ipv6]"
echo
echo "OPTIONS:"
echo "-s | --single: Binding IPV6"
echo "-b | --batch: Batch Binding IPV6"
echo
echo "Example: ./$(basename $0) -s "
echo "Example: ./$(basename $0) -b "
echo
}
CheckIpv6() {
echo "ipv6"
}
Batch() {
}
SetIpv6() {
ipv6=$1
ipgw=`echo $ipv6|awk -F ':' '{print $1":"$2":"$3":"$4"::1"}'`
[ -f $eth0f ] && cp $eth0f{,.bak}
if [ -z "`grep ^'IPV6INIT=yes' $eth0f`" ]; then
echo "IPV6INIT=yes" >> $eth0f
echo "IPV6_DEFROUTE=yes" >> $eth0f
[ -z $2 ] && echo "IPV6ADDR=${ipv6}/64" >> $eth0f
echo "IPV6_DEFAULTGW=$ipgw" >> $eth0f
restartflag=1
else
echo "skip set ipv6"
fi
[ -f $resf ] && cp $resf{,.bak}
if [ -z "`grep ^'nameserver 240e:56:4000:8000::69' $resf`" ]; then
echo "nameserver 240e:56:4000:8000::69" >> $resf
echo "nameserver 240C::6666" >> $resf
restartflag=1
else
echo "skip set ipv6 dns"
fi
[ $restartflag -eq 1 ] && service network restart && ifconfig|grep inet6|grep global|awk '{print $2}' && echo "set ipv6 success"
}
[ -z $1 ] && ifconfig|grep inet6|grep global|awk '{print $2}'
while [ $1 ]; do
case $1 in
'-b' | '--batch' )
[ -z "$2" -o -z "$3" ] && echo "Incomplete parameters" && exit
Batch $2 $3
break
;;
'-s' | '--single' )
[ -z "$2" ] && echo "Incomplete parameters" && exit
SetIpv6 $2
break
;;
'-h' | '--help' )
Help
break
;;
* )
Help
exit
;;
esac
shift
done
详细代码:请下载附件
setipv6.txt
(2.12 KB, 下载次数: 0, 售价: 10 金币)
|