在linux环境下搭建Dhcp服务器
使用linux操作系统搭建dhcp服务器
原创missingluo 博主文章分类:linux服务的搭建 ©著作权
©著作权归作者所有:来自51CTO博客作者missingluo的原创作品,请联系作者获取转载授权,否则将追究法律责任
(1)首先配置dhcp服务器端---安装dhcp服务:
dhcp-3.0.5-23.el5.i386.rpm (dhcp主要配置包)
dhcpv6-1.0.10-18.el5.i386.rpm (dhcp工具包)
rpm -ivh dhcp-3.0.5-23.el5.i386.rpm (可以使用rpm或者yum安装)
(2)配置dhcp服务器:
rpm -qc dhcp 查看dhcp中可配置的脚本
rpm -ql dhcp |less 查看dhcp包的安装位置
Dhcp的主要配置文件为:/etc/dhcpd.conf 进入进行编译
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
#
ddns-update-style interim;
ignore client-updates;
subnet 192.168.10.0 netmask 255.255.255.0 { (建立作用域)
# --- default gateway
option routers 192.168.10.254; 网管地址:
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "test.ct"; 服务器名标识
option domain-name-servers 222.88.88.88,222.85.85.85; 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 192.168.10.10 192.168.10.30; 地址池
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 00:0c:29:cf:12:2a;
fixed-address 192.168.10.2;
}
}
:r /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample (在底行使用此方法获取该文件的配置脚本参考)
(3)编译完成后 执行下面命令可以检查脚本是否有错,并可根据报错找出位置
[root@luo Server]# service dhcpd configtest
Syntax: OK (此为没错)
(4)启动dhcp服务
chkconfig dhcpd on 或者 service dhcpd start
(5)在dhcp客户端(linux)获取地址:
在命令行中使用 dhclient工具获取地址,linux dhcp服务器分配地址的顺序是由大到小
dhclient -d eth0 从eth0网卡获取地址
此时便可以看到获取的地址是192.168.10.30,是从192.168.10.3服务器上获取的
我们绑定的主机也获取到了相应的ip
当然对比一下,在windows安装配置dhcp服务器那更是小菜一碟
(6)如果网络内存在上千台主机,那么上叙的配置是远远不行的
这里我们需要使用超级作用域了,顾名思义,超级作用域是一个很大域,里面有若干个小的子作用域组成windows下配置如下:
那么linux下呢,我们可以这样来:
使用一个 shared-network test{ 子作用域 } 例如:
ddns-update-style interim;
ignore client-updates;
shared-network test{
subnet 192.168.20.0 netmask 255.255.255.0 {
# --- default gateway
option routers 192.168.20.254;
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "test.ct";
option domain-name-servers 222.88.88.88,222.85.85.85;
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 192.168.20.10 192.168.20.10;
default-lease-time 21600;
max-lease-time 43200;
# we want the nameserver to appear at a fixed address
}
subnet 192.168.10.0 netmask 255.255.255.0 {
# --- default gateway
option routers 192.168.10.254;
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "test.ct";
option domain-name-servers 222.88.88.88,222.85.85.85;
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 192.168.10.2 192.168.10.2;
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 00:0c:29:cf:12:2a;
fixed-address 192.168.10.2;
}
}
}
然后检查是否有错:service dhcpd configtest
在重启服务: service dhcpd restart
(7)但是每个dns每次获取的都是分配的,若想自己手动配置:
dns指向参数文件------/etc/resolv.conf
nameserver 222.85.85.85
nameserver 222.88.88.88
则需要编译 /etc/sysconfig/network-scripts/ifcfg-eth0 文件
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=none
BROADCAST=192.168.100.255
HWADDR=00:0c:29:5a:46:70
IPADDR=192.168.100.99
NETMASK=255.255.255.0
NETWORK=192.168.100.0
PEERDNS=no (添加)
ONBOOT=yes
GATEWAY=192.168.100.254
TYPE=Ethernet
(8)此时便可以通过修改/etc/resolv.conf 手工分配dns了
(9)服务器选项作用整个超级作用域,作用域选项作用个子作用域
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Linux系统搭建DHCP服务器
实验要求:在Linux系统搭建DHCP服务器实验步
Linux 服务器 配置文件 编辑器 -
搭建linux DHCP 服务器
其实linux搭建服务和windwos差不多在做的实验写了文档给大家一起分享咯
linux 职场 DHCP 服务器 休闲