您好,登錄后才能下訂單哦!
本篇內容介紹了“Shell怎么自動修改CentOS6網卡配置文件”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
#!/bin/bash # MY_ONBOOT="ONBOOT=yes" MY_BOOTPROTO="BOOTPROTO=static" MY_DEVICE="DEVICE="`ifconfig -a|grep HWaddr|awk {'print $1'}` MY_HWADDR="HWADDR="`ifconfig -a|grep HWaddr|awk {'print $5'}` MY_IPADDR="IPADDR="$1 MY_NETMASK="NETMASK="$2 MY_GATEWAY="GATEWAY="$3 MY_DNS="DNS1="$4 Flag1=0 Flag2=0 Flag3=0 Flag4=0 if [ $# -lt 4 ];then echo "Usage:./modif_ip.sh arg1[IPADDR] arg2[NETMASK] arg3[GATEWAY] arg4[DNS]." exit 5 fi if [ $# -gt 4 ];then echo "Usage:./modif_ip.sh arg1[IPADDR] arg2[NETMASK] arg3[GATEWAY] arg4[DNS]." exit 6 fi cat /etc/sysconfig/network-scripts/ifcfg-eth0 | while read myline do if [[ "$myline" =~ "ONBOOT" ]];then echo $MY_ONBOOT >> ifcfg-eth0 elif [[ "$myline" =~ "BOOTPROTO" ]];then echo $MY_BOOTPROTO >> ifcfg-eth0 elif [[ "$myline" =~ "DEVICE" ]];then echo $MY_DEVICE >> ifcfg-eth0 elif [[ "$myline" =~ "HWADDR" ]];then echo $MY_HWADDR >> ifcfg-eth0 elif [[ "$myline" =~ "IPADDR" ]];then Flag1=1 elif [[ "$myline" =~ "NETMASK" ]];then Flag2=1 elif [[ "$myline" =~ "GATEWAY" ]];then Flag3=1 elif [[ "$myline" =~ "DNS" ]];then Flag4=1 else echo $myline >> ifcfg-eth0 fi done if [ $Flag1 == 0 ];then echo $MY_IPADDR >> ifcfg-eth0 fi if [ $Flag2 == 0 ];then echo $MY_NETMASK >> ifcfg-eth0 fi if [ $Flag3 == 0 ];then echo $MY_GATEWAY >> ifcfg-eth0 fi if [ $Flag4 == 0 ];then echo $MY_DNS >> ifcfg-eth0 fi cp /root/ifcfg-eth0 /etc/sysconfig/network-scripts/ rm -rf /root/ifcfg-eth0
“Shell怎么自動修改CentOS6網卡配置文件”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。