Automating the deployment of DHCP services with Shell scripting, plus text-to-document verification

Source: Internet
Author: User

The automated DHCP service shell script is as follows:

#vim auto_dhcp.sh

#!/bin/bashread -p  "please input your ip: "  IP       #设置dhcp服务器ipread  -p  "please input your gw: "  GW       #设置dhcp服务器网关IPNET =$ (echo  $IP  |awk -F.  ' {print $1 '. " $ "." $ "$} ')    #取网段号  ip_conf="/etc/sysconfig/network-scripts/ifcfg-eth0 "   #ip配置文件sed  -i   ' s/ipaddr=.*/ipaddr= ' "$IP" '/'   $IP _conf     sed -i  ' s/gateway=.*/ Gateway= ' "$GW" '/'   $IP _confservice network restart &> /dev/nullrpm -q  dhcp &> /dev/null[ $? -eq 0 ] | |  yum -y install dhcp &> /dev/null     #安装dhcpdhcp_ version= ' rpm -qa dhcp | awk -f '-'   ' {print $2} '    #获取dhcp版本cd  /usr/share/doc/dhcp-"$dhcp _version"      #将模板配置文件进行复制一份grep -v  "#"  dhcpd.conf.sample |grep -v  "^$" |sed -e  ' s/192.168.0/' "$IPNET "'/g '  > /etc/dhcpd.conf   sed -i  '/nis\-domain/d '   /etc/ dhcpd.conf     #不配置域名sed  -i  '/domain-name/d '   /etc/dhcpd.confsed - i  ' s/' "$IPNET" '. 1\;$/' "$GW" ' \;/g '  /etc/dhcpd.confservice dhcpd start

Demonstrate:

Lab environment: Two redhat in VMware, one for DHCP server and one for verification.

Dhcp:ip 192.168.1.3 GW 192.168.1.0

A VMware configuration of two redhat VMware network configurations is as follows

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6D/75/wKiom1Vkf56Tvp_rAAKVZ4jDppo673.jpg "title=" Z63fob {M13MZ (ROC2) auycd.jpg "alt=" Wkiom1vkf56tvp_raakvz4jdppo673.jpg "/>

Two execute scripts to install the DHCP server

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6D/70/wKioL1VkfxWhSoF8AAKBSutX-94188.jpg "title=" YW "HI6 (8M ' V0hwd8gx~v%ku.png "alt=" Wkiol1vkfxwhsof8aakbsutx-94188.jpg "/>

To view the DHCP server IP address and gateway:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6D/71/wKioL1VkgK_SAPDIAAMbH1Yp7Ao815.jpg "title=" { WXTPMFXO9M7Q9A8I1) U (c1.png "alt=" Wkiol1vkgk_sapdiaambh1yp7ao815.jpg "/>

Two redhat to verify with another one

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6D/71/wKioL1Vkgnaz-tqaAAJ7iVFR5y8307.jpg "title=" Dddd.png "alt=" Wkiol1vkgnaz-tqaaaj7ivfr5y8307.jpg "/>

Three further validations, modify the address pool scope of the DHCP server, and verify that the client IP address changes.

1 Change the address pool from 192.168.1.128 to 192.168.1.254 to 192.168.1.128 to 192.168.1.140

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6D/71/wKioL1VkgxWDcoX1AAFFm2II9Jg092.jpg "title=" Iiii.png "alt=" Wkiol1vkgxwdcox1aaffm2ii9jg092.jpg "/>

2 Restarting the DHCP service

Service DHCPD Restart

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6D/71/wKioL1Vkg-nSFvTyAACA2JR08T8552.jpg "title=" yy.png "alt=" Wkiol1vkg-nsfvtyaaca2jr08t8552.jpg "/>

3 Authenticating the Client

Service Network restart

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6D/75/wKiom1VkgtmwUhKTAAJ5iQ_rdLg175.jpg "title=" 4444. PNG "alt=" wkiom1vkgtmwuhktaaj5iq_rdlg175.jpg "/>

Iv. Summary

The script only can initially build the DHCP server, for some other functions can only be manually changed through the/etc/dhcpd.conf configuration file.




This article is from the "Tiandaochouqin" blog, make sure to keep this source http://luzhi1024.blog.51cto.com/8845546/1655443

Automating the deployment of DHCP services with Shell scripting, plus text-to-document verification

Related Article

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.