Automatically deploy DHCP service scripts

Source: Internet
Author: User

The basic things are all there. You need to combine the things and then click OK.

#! /Bin/bash

Yum-y install DHCP

\ CP/usr/share/doc/dhcp-3.0.5/DHCPD. conf. Sample/etc/DHCPD. conf

Read-P "Enter the network segment" WD

Read-R "Enter the subnet mask" zwym

Sed-I-r "/^ subnet/S/([0-9] {0, 2} | 1 [0-9] {2} | 2 [0-4] [0-9] | 25 [0-5]) \.) {3} ([0-9] {0, 2} | 1 [0-9] {2} | 2 [0-4] [0-9] | 25 [0-5 ]) /$ WD/"/etc/DHCPD. conf

Sed-I-r "/^ subnet/S/([0-9] {0, 2} | 1 [0-9] {2} | 2 [0-4] [0-9] | 25 [0-5]) \.) {3} ([0-9] {0, 2} | 1 [0-9] {2} | 2 [0-4] [0-9] | 25 [0-5 ]) /$ zwym/2 "/etc/DHCPD. conf

Sed-I '2 a option domain-name-servers 8.8.8.8; '/etc/DHCPD. conf

Sed-I '2 a max-lease-time 7200; '/etc/DHCPD. conf

Sed-I '2 a default-lease-time 600;'/etc/DHCPD. conf

Sed-I '/Default Gateway/, + 24d'/etc/DHCPD. conf

Sed-ri'/^ subnet/A \ toption routers 192.168.1.254; '/etc/DHCPD. conf

Sed-ri '/^ subnet/A \ toption subnet-mask limit 255.0;'/etc/DHCPD. conf

Sed-ri '/^ subnet/A \ trange 192.168.1.100 192.168.1.200;'/etc/DHCPD. conf

Sed-ri '/^ subnet/A \ trange 192.168.1.50 192.168.1.60;'/etc/DHCPD. conf

Service DHCPD start




Optimization

Sed-I's/dhcpdargs = "eth0"/'/etc/sysconfig/DHCPD



Enable DHCP relay

Sed-I '/net. ipv4.ip _ forward/S/0/1/'/etc/sysctl. conf

Sysctl-P

Echo "dhcrelayargs = \" eth0 \ "">/etc/sysconfig/dhcrelay

Echo "dhcpservers = \" 192.168.1.254 \ "">/etc/sysconfig/dhcrelay

Service dhcrelay start


Or


Sed-I '/dhcrelayargs =/S/""/"eth0"/'/etc/sysconfig/dhcrelay

Sed-I '/dhcpservers =/S/""/"192.168.1.254"/'/etc/sysconfig/dhcrelay




Sed-I '/dhcrelayargs =/S/""/"eth0"/'/etc/sysconfig/dhcrelay




Client check


Dhclient-D eth0


Check DHCP allocation information on the server

/Var/lib/DHCPD. Leases


Client View

/Var/lib/dhclinet/dhclient. Leases


Automatically deploy DHCP service scripts

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.