标签:shell
实验环境:VMware12 、 redhat 6.4 、支持中文
#!/bin/bash
#shell自动搭建DHCP服务
rpm -q dhcp &>/dev/null
if [ $? -eq 0 ];then
echo "dhcp服务已经搭建"
else
echo "dhcp服务还未搭建,马上开始搭建"
yum install dhcp -y &>/dev/null
if [ $? -eq 0 ];then
echo "dhcp服务搭建成功"
else
echo "yum源错误,马上退出"
exit 10
fi
fi
if [ ! -f /etc/dhcp/dhcpd.conf ];then
echo "配置文件不存在,可能发生其他错误,马上退出"
exit 20
fi
cat << EOF >/etc/dhcp/dhcpd.conf
option domain-name "server.org";
option domain-name-servers 114.114.114.114;
default-lease-time 3200;
max-lease-time 7200;
subnet 192.168.16.0 netmask 255.255.255.0 {
range 192.168.16.100 192.168.16.200;
option routers 192.168.16.254;
}
EOF
ifconfig eth0 192.168.16.254/24 &>/dev/null
if [ $? -eq 0 ];then
service dhcpd start &> /dev/null
if [ $? -eq 0 ];then
echo "DHCP服务开启成功"
else
echo "DHCP服务开启失败"
fi
else
echo "网卡IP配置出错,马上退出"
exit 30
fi
本文出自 “天晴了要下雨” 博客,请务必保留此出处http://8776055.blog.51cto.com/8766055/1839810
标签:shell
原文地址:http://8776055.blog.51cto.com/8766055/1839810