码迷,mamicode.com
首页 > 其他好文 > 详细

dhcp配置简单脚本

时间:2014-11-04 06:55:54      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:dhcp配置

dhcp_install.sh
#!/bin/bash
#安装yum源
#配置
#启动

#mount -o loop /dev/cdrom /mnt
#echo "mount -o loop /dev/cdrom /mnt">>/etc/rc.local

cat >/etc/yum.repos.d/dvd.repo <<ENDF
[autoyum]
baseurl=file:///mnt
gpgcheck=0
ENDF
yum clean all && yum list all &>/dev/null && echo "yum is ok"

yum install -y dhcp &>/dev/null && echo "dhcp is installed"

dhcp_configure.sh
#!/bin/bash
read -p "please input your IP:" IP
read -p "please input your NETMASK:" NET
read -p "please input your GATEWAY:" GW
read -p "please input your DNS1:" DNS1
read -p "please input your DNS2:" DNS2

SAM=/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample
ITR=$(ifconfig eth0 |grep -Eo ‘([0-9]{1,3}\.){2}[0-9]{1,3}‘|head -1)
MASK=$(ifconfig eth0 |grep -Eo ‘(([0-9]{1,3}\.){3}[0-9]{1,3})‘|grep ^255)
BOR_ADD=$(ifconfig eth0 |grep -Eo ‘(([0-9]{1,3}\.){3}[0-9]{1,3})‘|grep 255$)
MAC=$(ifconfig eth0 |grep -Eo ‘(([0-9 A-Z a-z]{1,2}:){5}[0-9 A-Z a-z]{1,2})‘)

export SAM ITR MASK BOR_ADD MAC

cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<ENDF
DEVICE="eth0"
BOOTPROTO="none"
HWADDR="00:0C:29:23:15:40"
ONBOOT="yes"
IPADDR=$IP
NETMASK=$NET
GATEWAY=$GW
DNS1=$DNS1
DNS2=$DNS2
ENDF

read -p "please input your HOSTNAME:" HN
cat >/etc/sysconfig/network <<ENDF
NETWORKING=yes
HOSTNAME=$HN
ENDF

echo "$IP $HN ">>/etc/hosts &>/dev/null && echo "hostname is ok"


\cp -p $SAM /etc/dhcp/dhcpd.conf &>/dev/null && echo "copy is ok"

cat >/etc/dhcp/dhcpd.conf <<ENDF
option domain-name "$HN";
option domain-name-servers $DNS1, $DNS2;  
default-lease-time 600;
max-lease-time 7200;

subnet $ITR.0 netmask $MASK {
 range $ITR.100 $ITR.200;
 option routers $GW;
 option broadcast-address $BOR_ADD;
 default-lease-time 600;
 max-lease-time 7200;
}

host fantasia {
 hardware ethernet $MAC;
 fixed-address $GW;
}
ENDF
#检测dhcpd的语法是否正确
#dhcpd -d &>/dev/null && echo "dhcpd grammer is ok"

service dhcpd restart &>/dev/null && echo "dhcpd is ok"
chkconfig dhcpd on

dhcp配置简单脚本

标签:dhcp配置

原文地址:http://jianglipan.blog.51cto.com/9541041/1571399

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!