標籤:redhat快速部署dhcp伺服器
伺服器位址:192.168.1.110
網段:192.168.1.0
子網路遮罩:255.255.255.0
網關:192.168.1.254
[[email protected] ~]# cat dhcp.sh
#!/bin/bash
#auto deploy dhcp server for 192.168.1.0/24 netmask
#this script need you have you yum repository
echo "____________mount-cdrom_____"
umount /dev/cdrom &> /dev/null # 卸載光碟片
mount /dev/cdrom /mnt &> /dev/null && #重新掛載系統光碟片
touch /etc/yum.repos.d/yum.repo # 建立yum的設定檔,名稱yum.repo
if [ $? -eq 0 ]
then # 判斷建立yum檔案成功就執行寫入以下參數
cat <<EOF > /etc/yum.repos.d/yum.repo
[server]
name=rehat server yum
baseurl=file:///mnt/Server # URL的訪問路徑
enabled=1 #啟動yum的倉庫
gpgcheck=0 #不啟用軟體包的簽名
EOF
else #否則列印出安裝yum錯誤!
echo "_-----install yum error___"
fi
#安裝dhcp軟體包
echo "___-install dhcp packet__ "
yum -y install dhcp &> /dev/null &&
if [ -f /etc/dhcpd.conf ] #判斷是否有/etc/dhcpd.conf這個主設定檔
then #執行
mv /etc/dhcp.conf /etc/dhcpd.conf.save #儲存原有的設定檔
fi
#變數定義,主要包括網路,子網,地址等資訊
NET=192.168.1.0
MASK=255.255.255.0
RANGE="192.168.1.50 192.168.1.100"
DOMAIN_NAME="breaklinux.com"
ROUTER=192.168.1.254
DNS=8.8.8.8
#建立新的設定檔
echo "______create Configuration file______"
cat <<EOF > /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
subnet $NET netmask $MASK {
# --- default gateway
option routers $ROUTER;
option subnet-mask $MASK;
option nis-domain "$DOMAIN_NAME";
option domain-name "$DOMAIN_NAME";
option domain-name-servers $DNS;
option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don‘t change this unless
# -- you understand Netbios very well
# option netbios-node-type 2;
range dynamic-bootp $RANGE;
default-lease-time 21600;
max-lease-time 43200;
# we want the nameserver to appear at a fixed address
host ns {
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 207.175.42.254;
}
}
EOF
echo "_____________dhcp Configuration file correctly "
service dhcpd restart #啟動dhcp服務
chkconfig dhcpd on #開機啟動
搭建dhcp伺服器完成
希望大家多多關注breaklinux.com 工作室,有錯誤的地方請指出,謝謝!
---新
本文出自 “渲染不變的昨天” 部落格,請務必保留此出處http://breaklinux.blog.51cto.com/8193722/1531320