設置IP地址shell腳本
阿新 • • 發佈:2018-08-19
network ces start put p地址 onf bootproto boot pts
#!/bin/bash
A="IPADDR.*"
B="NETMASK.*"
C="GATEWAY.*"
D="DNS1.*"
E="/etc/sysconfig/network-scripts/ifcfg-eth1"
F="cat $E | sed -n ‘/BOOTP/p‘"
if [ ! "$F" = "BOOTPROTO=dhcp" ]
then
read -t 30 -p "Please enter the IP address:" IP
read -t 30 -p "Please enter mask:" MASK
read -t 30 -p "Please enter gateway:" GW
read -t 30 -p "Please enter DNS address:" DNS
if [ ! -z "$IP" -a ! -z "$MASK" -a ! -z "$GW" -a ! -z "$DNS" ]
then
sed -i "s/$A/IPADDR=$IP/" $E
sed -i "s/$B/NETMASK=$MASK/" $E
sed -i "s/$C/GATEWAY=$GW/" $E
sed -i "s/$D/DNS1=$DNS/" $E
sed -i ‘s/ONBOOT.*/ONBOOT=yes/‘ $E
else
echo "Error:The input is invalid!!!!"
exit 1
fi
echo "Please later....."
/etc/init.d/network restart &>/dev/null
echo "Network card has been configured successfully"
else
echo "You are already enabled for DHCP"
exit 2
fi
這是一個簡單的設置靜態IP的shell腳本,和大家分享
設置IP地址shell腳本