Requirements:
1, automatic installation, basic configuration
2, through the prompt input network segment, subnet mask, gateway, DNS, IP end address and other information to complete the scope of the add
"Method One":
#!/bin/bash
conf= "/etc/dhcpd.conf"
Rpm-q DHCP &>/dev/null
If [$?-ne 0];then
Yum-y Install DHCP
Fi
grep "Subnet" $conf &>/dev/null
If [$?-ne 0]; Then
echo "
Ddns-update-style Interim;
Ignore client-updates;
Default-lease-time 21600;
Max-lease-time 43200;
"> $conf
Fi
Read-p "Please input network:" Network
Read-p "Please input netmask:" Netmask
Read-p "Please input gateway:" Gateway
Read-p "Please input DNS:" DNS
Read-p "Please input start_ip:" Start_ip
Read-p "Please input end_ip:" End_ip
echo "
Subnet $network netmask $netmask {
option routers $gateway;
Option Subnet-mask $netmask;
URL Address: http://www.bianceng.cn/Servers/zs/201602/49614.htm
Option Domain-name-servers $dns;
Range DYNAMIC-BOOTP $start _ip $end _ip;
}
">> $conf
Service DHCPD Restart
"Method Two":
#!/bin/bash
Dhcpconf=/etc/dhcpd.conf
Rpm-q DHCP &>/dev/null
If [$?-ne 0];then
Yum-y Install DHCP
Fi
grep "Subnet" $dhcpconf &>/dev/null
If [$?-ne 0];then
echo "Ddns-update-style interim;
Ignore client-updates;
Default-lease-time 21600;
Max-lease-time 43200; "> $dhcpconf
Fi
While True
Todo
Read-p "Please input network:" Network
Read-p "Please input Netmask:" Netmask
Read-p "Please input gateway:" Gateway
Read-p "Please input DNS:" DNS
Read-p "Please input start_ip:" Start_ip
Read-p "Please input end_ip:" End_ip
grep $network $dhcpconf &>/dev/null
If [$?-ne 0];then
echo "Subnet $network netmask $netmask {
option routers $gateway;
Option Subnet-mask $netmask;
Option Domain-name-servers $dns;
Range DYNAMIC-BOOTP $start _ip $end _ip;
} ">> $dhcpconf
Read-p "continue to Do" (yes/no) yn
if [$yn = "no"]; Then
Service DHCPD Status &>/dev/null
If [$?-ne 0]; Then
Service DHCPD start &>/dev/null
Else
Service DHCPD Reload &>/dev/null
Fi
Exit 0
Fi
Fi
Done
This article is from the "Soldier" blog, please be sure to keep this source http://ganbing.blog.51cto.com/7002794/1241895