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

    #!/bin/sh
    #$1 IP
    #$2 netmask
    #$3 gw
    netWorkCard=eno1    //以太网
    configFile=/etc/rc.d/rc.local   //配置文件
    #取得那个位置的ip
    if [ -a $configFile ];  //如果文件存在
    then
            oldip=`cat $configFile| grep "ifconfig $netWorkCard" | awk '{print $3}'`   //  找出旧的ip
            oldnetmask=`cat $configFile| grep "ifconfig $netWorkCard" | awk '{print $5}'`
            oldgw=`cat $configFile| grep "dev $netWorkCard" | awk '{print $5}'`
            echo $oldip "->" $1   
            echo $oldnetmask "->"  $2
            echo $oldgw "->" $3
            #替换为新的IP
            sudo -S sed -i  "s/$oldip/$1/" $configFile        //替换oldip   用S1
            sudo -S sed -i  "s/$oldnetmask/$2/" $configFile
            sudo -S sed -i  "s/$oldgw/$3/" $configFile
            sudo -S  ifconfig $netWorkCard $1 netmask $2

            currentIp=`ifconfig $netWorkCard |grep -w inet | awk '{print $2}'`
            currentNetmask=`ifconfig $netWorkCard |grep -w inet | awk '{print $4}'`
            echo $currentIp
            oldip=`cat $configFile| grep "ifconfig $netWorkCard" | awk '{print $3}'`
            oldnetmask=`cat $configFile| grep "ifconfig $netWorkCard" | awk '{print $5}'`
      //and 
            if  [ $currentIp == $oldip -a  $currentNetmask == $oldnetmask -a $currentIp == $1 -a  $currentNetmask == $2 ];
            then
                    ifconfig $netWorkCard down
                    ifconfig $netWorkCard up
                    echo "ip setting sucess!"
                    route add default gw $3
            else
                    echo "ip setting fail!"
            fi
    else
            echo "file no exist!"
    fi
     
  • 相关阅读:
    HGOI 20191029am 题解
    『ZJOI2019 D2T2』语言
    『NOIP 2019Day2 T3』 保卫王国(defense)
    『HGOI 20190917』Lefkaritika 题解 (DP)
    『HGOI 20190917』Cruise 题解 (计算几何+DP)
    HGOI 20190830 题解
    『Codeforces 1186E 』Vus the Cossack and a Field (性质+大力讨论)
    HGOI 20190828 题解
    BZOJ 1934 善意的投票
    BZOJ 2763 飞行路线 BFS分层
  • 原文地址:https://www.cnblogs.com/countryboy666/p/11323344.html
Copyright © 2011-2022 走看看