CentOS7将dhcp获取到的地址固定改为静态地址的脚本
#!/bin/bash #调整eth0文件 /usr/bin/sed -i "/^IPV6/d" /etc/sysconfig/network-scripts/ifcfg-eth0 /usr/bin/sed -i "s/dhcp/static/g" /etc/sysconfig/network-scripts/ifcfg-eth0 /usr/bin/sed -i "s/ONBOOT=no/ONBOOT=yes/g" /etc/sysconfig/network-scripts/ifcfg-eth0 /usr/bin/sed -i "s/UUID/#UUID/g" /etc/sysconfig/network-scripts/ifcfg-eth0 #IP地址: /usr/sbin/ip add | grep "scope global dynamic eth0" | awk -F' ' '{print $2}' | awk -F'/' '{print "IPADDR="$1}' >> /etc/sysconfig/network-scripts/ifcfg-eth0 #子网掩码: /usr/bin/echo "NETMASK=255.255.255.0" >> /etc/sysconfig/network-scripts/ifcfg-eth0 #网关: /usr/bin/cat /etc/resolv.conf | grep nameserver | awk -F' ' '{print "GATEWAY="$2}' >> /etc/sysconfig/network-scripts/ifcfg-eth0 #DNS: /usr/bin/cat /etc/resolv.conf | grep nameserver | awk -F' ' '{print "DNS1="$2}' >> /etc/sysconfig/network-scripts/ifcfg-eth0 #重启网络: /usr/bin/systemctl restart network #安装net-tools软件 /usr/bin/yum install net-tools