#!/bin/bash ########安裝dhcp伺服器######### ######配置yum源####### cat >/etc/yum.repos.d/local.repo<<end [local] name=local baseurl=file:///mnt gpgcheck=0 enable=1 end ########挂載CD光牒############### if mount | grep /dev/sr0>/dev/null then echo "it mount" else echo "not mount" mount /dev/cdrom /mnt fi ##########清空防火牆############## /etc/init.d/iptables stop ###########修改主機名############# cat >/etc/sysconfig/network <<eof networking=yes hostname=dhcp_server eof ##########安裝dhcp伺服器########### yum -y install dhcp ###########編輯配置檔案############ rm -rf /etc/dhcp/dhcpd.conf cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf cat >/etc/dhcp/dhcpd.conf<<eof option domain-name "feiyu.com"; option domain-name-servers 192.168.1.16,8.8.8.8; default-lease-time 600; max-lease-time 7200; log-facility local7; subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.17 192.168.1.20; option domain-name-servers 8.8.4.4; option domain-name "hehe.org"; option routers 192.168.1.1; option broadcast-address 192.168.1.255; } host dayinji { hardware ethernet 08:00:27:3d:2b:a7; fixed-address 192.168.1.200; #############啟動dhcp############## /etc/init.d/dhcpd restart && chkconfig --level 35 dhcpd on 注:這個腳本隻适用于centos7之前的版本!因為centos7服務啟動方式以及網卡名做了一些小改動,不過可根據此腳本适當的做修改即可!