CentOS7将dhcp获取到的地址固定改为静态地址的脚本
Posted sdrbg
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7将dhcp获取到的地址固定改为静态地址的脚本相关的知识,希望对你有一定的参考价值。
[root@localhost ~]# cat network.sh #!/bin/bash #调整eth0文件 sed -i "/^IPV6/d" /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i "s/dhcp/static/g" /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i "s/ONBOOT=no/ONBOOT=yes/g" /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i "s/UUID/#UUID/g" /etc/sysconfig/network-scripts/ifcfg-eth0 #IP地址: ifconfig -a | grep broadcast | awk -F‘ ‘ ‘{print "IPADDR="$2}‘ >> /etc/sysconfig/network-scripts/ifcfg-eth0 #子网掩码: ifconfig -a | grep broadcast | awk -F‘ ‘ ‘{print "NETMASK="$4}‘ >> /etc/sysconfig/network-scripts/ifcfg-eth0 #网关: cat /etc/resolv.conf | grep nameserver | awk -F‘ ‘ ‘{print "GATEWAY="$2}‘ >> /etc/sysconfig/network-scripts/ifcfg-eth0 #DNS: cat /etc/resolv.conf | grep nameserver | awk -F‘ ‘ ‘{print "DNS1="$2}‘ >> /etc/sysconfig/network-scripts/ifcfg-eth0 #重启网络: systemctl restart network
以上是关于CentOS7将dhcp获取到的地址固定改为静态地址的脚本的主要内容,如果未能解决你的问题,请参考以下文章