标签:linux ip
#!/bin/bash #自动配IP # Author: tianzhaogao (E-mail: 296862380@qq.coom) line_num=$(cat /etc/sysconfig/network-scripts/ifcfg-eth0 | wc -l) while [ "$line_num" -gt 7 ] do sed -i ‘8c \‘ /etc/sysconfig/network-scripts/ifcfg-eth0 line_num=$(cat /etc/sysconfig/network-scripts/ifcfg-eth0 | wc -l) done read -t 30 -p "Please input IP:" ipnum n1=$(echo "$ipnum" | cut -d "." -f 1) n2=$(echo "$ipnum" | cut -d "." -f 2) n3=$(echo "$ipnum" | cut -d "." -f 3) n4=$(echo "$ipnum" | cut -d "." -f 4) if [ "$n1" -le 255 -a "$n2" -le 255 -a "$n3" -le 255 -a "$n4" -le 255 ];then echo -e IPADDR="$ipnum""\n"NETMASK=255.255.255.0"\n"GETWAY="$n1"\."$n2"\."$n3"\.1"\n"IPV6INIT=no"\n"USERCTL=no >> /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i ‘s/ONBOOT="no"/ONBOOT="yes"/g‘ /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i ‘s/BOOTPROTO=dhcp/BOOTPROTO=none/g‘ /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i ‘s/ONBOOT=no/ONBOOT=yes/g‘ /etc/sysconfig/network-scripts/ifcfg-eth0 service network restart fi
本文出自 “碧血青天” 博客,请务必保留此出处http://tianzhaogao.blog.51cto.com/4716906/1693194
标签:linux ip
原文地址:http://tianzhaogao.blog.51cto.com/4716906/1693194