#!/bin/bash
########安装dhcp服务器#########
######配置yum源#######
cat >/etc/yum.repos.d/local.repo<<end
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
enable=1
end
########挂载光盘###############
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;
}
EOF
#############启动dhcp##############
/etc/init.d/dhcpd restart && chkconfig --level 35 dhcpd on
注:这个脚本只适用于centos7之前的版本!因为centos7服务启动方式以及网卡名做了一些小改动,不过可根据此脚本适当的做修改即可!
原文:http://blog.51cto.com/13043516/2110732