zoukankan      html  css  js  c++  java
  • 设置IP地址

    #!/bin/bash
    
    
    #Absolute path to this script
    SCRIPT=$(readlink -f $0)
    #Absolute path this script is in
    SCRIPTPATH=$(dirname $SCRIPT)
    echo $SCRIPT
    echo $SCRIPTPATH
    
    #Initial defaults
    _NAME=ens33
    _LOC_IP=192.168.31.91
    _GW_IP=192.168.31.1
    _PREFIX=24
    
    
    clear
    echo
    echo
    echo "This script will help you easily set up IP ADDRESS"
    echo
    
    #check for root user
    if [ "$(id -u)" -ne 0 ] ; then
            echo "You must run this script as root. Sorry!"
            exit 1
    fi
    
    
    #判断IP ADDRESS是否合规
    if ! echo $LOC_IP | egrep -q '(^([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).)(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){2}([0-9]|[1-9]{2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' ; then
            #Read the IP
            read  -p "Please select the IP for this instance: [$_LOC_IP] " LOC_IP
            if ! echo $LOC_IP | egrep -q '(^([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).)(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){2}([0-9]|[1-9]{2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' ; 
            then
                    echo " Selecting default: $_LOC_IP"
                    echo
                    LOC_IP=$_LOC_IP
            else
                    echo " Selecting IP: $LOC_IP"
                    echo
            fi
    fi
    
    
    #判断IP GATEWAY是否合规
    if ! echo $GW_IP | egrep -q '(^([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).)(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){2}([0-9]|[1-9]{2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' ; then
            #Read the IP
            read  -p "Please select the IP GW for this instance: [$_GW_IP] " GW_IP
            if ! echo $GW_IP | egrep -q '(^([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).)(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){2}([0-9]|[1-9]{2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' ; 
            then
                    echo " Selecting default: $_GW_IP"
                    echo
                    GW_IP=$_GW_IP
            else
                    echo " Selecting GW: $GW_IP"
                    echo
            fi
    fi
    
    cat>/etc/sysconfig/network-scripts/ifcfg-$_NAME<<EOF
    TYPE="Ethernet"
    BOOTPROTO="static"
    ONBOOT="yes"
    DEVICE="$_NAME"
    NETMASK=$_PREFIX
    GATEWAY=$GW_IP
    IPADDR=$LOC_IP
    DNS1=114.114.114.114
    EOF
    systemctl restart network
    ifconfig
  • 相关阅读:
    'Undefined symbols for architecture i386,clang: error: linker command failed with exit code 1
    The codesign tool requires there only be one 解决办法
    XCode iOS project only shows “My Mac 64bit” but not simulator or device
    Provisioning profile XXXX can't be found 的解决办法
    UIView 中的控件事件穿透 Passthrough 的实现
    Xcode4.5出现时的OC新语法
    xcode 快捷键(持续更新)
    打越狱包
    php缓存与加速分析与汇总
    浏览器的判断
  • 原文地址:https://www.cnblogs.com/vmsysjack/p/15113520.html
Copyright © 2011-2022 走看看