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

  

上一篇:npm-package.json


下一篇:Configuration in scripts