1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| #!/bin/bash # Author: Ropon # Blog: https://www.ropon.top
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 240e:d9:c200:101:7bb2::120" echo "Example: ./$(basename $0) -b 240e:d9:c200:101:7bb2::120 240e:d9:c200:101:7bb2::130" echo }
CheckIpv6() { echo "ipv6" }
Batch() { start="`echo $1awk -F ':' '{print $NF}'`" end="`echo $2awk -F ':' '{print $NF}'`" pre=`echo ${1%:*}` dstart=`printf %d 0X${start}` dend=`printf %d 0X${end}` total=$(($dend-$dstart+1)) ipv6string="" for ((i=1;i<=$total;i++)) do [ $i -eq $total ] && ipv6string=${ipv6string}${pre}:`printf %x $dstart`"/64" ipv6string=${ipv6string}${pre}:`printf %x $dstart`"/64 \\ " let dstart=dstart+1 done echo "Batch Binding IPV6" echo "IPV6ADDR_SECONDARIES=\"$ipv6string\"" >> $eth0f SetIpv6 $1 "-b" }
SetIpv6() { ipv6=$1 ipgw=`echo $ipv6awk -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 && ifconfiggrep inet6grep globalawk '{print $2}' && echo "set ipv6 success" }
[ -z $1 ] && ifconfiggrep inet6grep globalawk '{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
|