Experimental environment: VMWARE12, Redhat 6.4, support Chinese
#!/bin/bash
#shell自动搭建DHCP服务
Rpm-q DHCP &>/dev/null
If [$?-eq 0];then
echo "DHCP service has been built"
Else
echo "DHCP service is not set up, start building now"
Yum Install dhcp-y &>/dev/null
If [$?-eq 0];then
echo "DHCP service builds successfully"
Else
echo "Yum source error, Exit Now"
Exit 10
Fi
Fi
if [!-f/etc/dhcp/dhcpd.conf];then
echo "configuration file does not exist, other errors may occur, exit immediately"
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 service turned on successfully"
Else
echo "DHCP service failed to open"
Fi
Else
echo "NIC IP configuration error, exit immediately"
Exit 30
Fi
This article is from the "Sunny Rain" blog, please be sure to keep this source http://8776055.blog.51cto.com/8766055/1839810
Automating the installation of DHCP services _shell