码迷,mamicode.com
首页 > 其他好文 > 详细

CentOS7将dhcp获取到的地址固定改为静态地址的脚本

时间:2019-10-11 20:02:45      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:bash   static   broadcast   重启   调整   gateway   oca   ipv6   ddr   

[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获取到的地址固定改为静态地址的脚本

标签:bash   static   broadcast   重启   调整   gateway   oca   ipv6   ddr   

原文地址:https://www.cnblogs.com/sdrbg/p/11656410.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!