CentOS 7 Shell修改IP地址


參考地址:https://blog.csdn.net/me1171115772/article/details/82556270

 

修正的版本,創建一個ps文件,運行后,即會輸入一個具體的IP地址

#/bin/bash
echo "###input ip you want change to ### "
ipfront=172.17.130.
read ip1
ip="${ipfront}${ip1}"
echo "###change ip as====" $ip "###"
eth=`find /etc/sysconfig/network-scripts/ -name "ifcfg-e*" |sort |head -1 |awk -F/ '{print $5}'`
ethfile="/etc/sysconfig/network-scripts/$eth"
echo "${ethfile}"
sed -i 's/BOOTPROTO="dhcp"/BOOTPROTO="static"/g' "${ethfile}"
sed -i 's/^ONBOOT="no"/ONBOOT="yes"/g' "${ethfile}"
#testfile="/etc/sysconfig/network-scripts/test"
echo "IPADDR=${ip}" >>${ethfile}
echo 'PREFIX=24' >>${ethfile}
echo 'NETMASK=255.255.255.0' >>${ethfile}
echo 'NETWORK=172.17.130.0' >>${ethfile}
echo 'GATEWAY=172.168.130.254' >>${ethfile}
echo 'DNS1=8.8.8.8' >>${ethfile}
echo 'PEERDNS="yes"' >>${ethfile}
service network restart

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM