How to write a script to install the Configure DHCP service

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.