#!/bin/bash #自动配IP # Author: tianzhaogao (E-mail: [email protected]) 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
时间: 2024-10-28 14:29:43