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
     
  • 相关阅读:
    (转)通过Javascript得到URL中的参数(query string)
    (转)对存储过程进行加密和解密(SQL 2008/SQL 2012)
    (转)怎样玩转千万级别的数据
    (转)mongodb学习(翻译1)
    (转)Web API 强势入门指南
    (转)正则表达式—RegEx(RegularExpressio)(三)
    学习进度-16 python爬虫
    学习进度-15 变量类型的转换
    学习进度-14
    学习进度-13
  • 原文地址:https://www.cnblogs.com/countryboy666/p/11323344.html
Copyright © 2011-2022 走看看