dhcp + dhcp脚本

脚本

an1="dhcp"
an2=""
an3=""
an4=""

function benyum(){
umount /dev/sr0 &> /dev/null
[ ! -d /media/cdrom ] && mkdir -p /media/cdrom 
mount /dev/sr0 /media/cdrom &> /dev/null
[ $? -ne 0 ] && echo "没插入光盘" && exit 1
[ ! -d /etc/yum.repos.d ] && mkdir -p /etc/yum.repos.d 
cd /etc/yum.repos.d
mv -f /etc/yum.repos.d/* /tmp/
cat > /etc/yum.repos.d/yum.repo << KOF
[local]
name=local
baseurl=file:///media/cdrom
gpgcheck=0
enabled=1
KOF
yum -y clean all &> /dev/null
yum makecache &> /dev/null
}

which $an1 $an2 $an3 $an4 &> /dev/null
[ $? -ne 0 ] && umount /dev/sr0 &> /dev/null && mount /dev/sr0 /media/cdrom &> /dev/null
if [ $? -eq 0 ];then
	yum -y install $an1 $an2 $an3 $an4 &> /dev/null 
else
	benyum
	yum -y install $an1 $an2 $an3 $an4 &> /dev/null
fi
> vim  /etc/dhcp/dhcpd.conf
function dhcp(){
name="why"
ip1="192.168.200.2"
ip2="192.168.200.100"
ip3="192.168.200.200"
ip4="192.168.200.0"
option domain-name "$name";
option domain-name-servers $ip1; default-lease-time 20000;
max-lease-time 48000;
log-facility local7;

subnet $ip4 netmask 255.255.255.0 {
   range $ip2 $ip3;
   option routers $ip1;
}
 
# host wanghaiyang {
#   hardware ethernet 00:0C:29:7B:A0:7B;
#   fixed-address 192.168.200.111;
#}
/etc/init.d/dhcp start
chkconfig dhcp --add
}

##配置DHCP服务

  • 主配置文件: /etc/dhcp/dhcpd.conf
  • 执行程序 /usr/sbin/dhcpd;/user/sbin/dhcrelay
  • 脚本:/etc/init.d/dhcpd;/etc/init.d/dhcrelay
  • 执行参数配置:/etc/sysconfig/dhcpd
  • DHCP中继配置:/etc/sysconfig/dhcrelay

yum -y install dhcp
vim /etc/dhcp/dhcpd.conf

option domain-name "why";
option domain-name-servers 192.168.200.2; default-lease-time 20000;
max-lease-time 48000;
log-facility local7;

subnet 192.168.200.0 netmask 255.255.255.0 {
   range 192.168.200.100 192.168.200.200;
   option routers 192.168.200.2;
 }
 
 host wanghaiyang {
   hardware ethernet 00:0C:29:7B:A0:7B;
   fixed-address 192.168.200.111;
 }

[root@wanghaiyang ~]# cat /etc/dhcp/dhcpd.conf 
# DHCP Server Configuration file.
        #下面路径为模板文件
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'

[root@wanghaiyang ~]# cd /etc/dhcp    #切换路径
[root@wanghaiyang dhcp]# cp  /usr/share/doc/dhcp*/dhcpd.conf.sample ./dhcpd.conf            #覆盖源
cp: overwrite `./dhcpd.conf'? y

[root@wanghaiyang dhcp]# egrep -v "#" /etc/dhcp/dhcpd.conf  > /etc/dhcp/dhcpd.conf.bak
[root@wanghaiyang dhcp]# cat /etc/dhcp/dhcpd.conf.bak >/etc/dhcp/dhcpd.conf



[root@wanghaiyang dhcp]# vim /etc/dhcp/dhcpd.conf
  #全局配置
  #opin:选项 domain-name 区域-名字 "你给他起的名字"
   option domain-name "example.org"; #域名解析名字
  #ns1.example.org, ns2.example.org;    #DNS服务器IP地址
   option domain-name-servers ns1.example.org, ns2.example.org;
   default-lease-time 600; #最小租约时间
   max-lease-time 7200;    #最大租约时间
   log-facility local7;    #日志路径
  
  #分发范围 subnet:声明;range:范围; option routers:路由,网关ip
  subnet 192.168.200.0 netmask 255.255.255.0 {
     range 192.168.200.100 192.168.200.200;
     option routers 192.168.200.2 ;
  } 
  #指定固定电脑获取固定地址
       #具体服务器名字(主机名)
  host fantasia {
    #网卡地址(mack地址)
    hardware ethernet 08:00:07:26:c0:a5;
    #强制插什么ip  #192.168.200.111
    fixed-address fantasia.fugue.com;
  } 
[root@wanghaiyang ~]# /etc/init.d/dhcpd restart
[root@wanghaiyang ~]# ifconfig | egrep -o "[0-9.]{15}" |head -1
192.168.200.111

猜你喜欢

转载自blog.csdn.net/weixin_44439515/article/details/89351778
今日推荐