ropon 发表于 2019-2-27 15:00:43

Centos批量绑定IPV6地址

#!/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 "
        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

详细代码:请下载附件


dsanlink 发表于 2019-2-27 15:02:03

ddddd

dsanlink 发表于 2019-2-27 15:02:27

支持一下原创

syl2018 发表于 2019-2-27 15:06:40

支持一下原创

syl2018 发表于 2019-2-27 15:06:52

支持一下原创

syl2018 发表于 2019-2-27 15:07:51

很棒棒

zswtest 发表于 2019-2-27 15:38:45

支持看看

cn539 发表于 2019-2-28 06:47:28

学习
页: [1]
查看完整版本: Centos批量绑定IPV6地址