redhat 下dhcp的配制
一.Dhcp动态主机地址协议
动态主机地址协议,给自动获取的客户端分配ip地址
整个过程:
1.客户端广播 DHCP discover 数据包 寻×××器
2.服务端响应 DHCP offer
3.客户端选择服务器 DHCP request
4.服务器段发送ip地址信息 DHCP ack
二.拓扑图
环境:vmware下 redhat为服务器 xp为客户机 网络模式均为hostonly
并且不使用vmware自带的dhcp功能
三、配制过程
1.建立目录并挂载光盘
[root@dg ~]# mkdir /mnt/cdrom
[root@dg ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
2.切换目录并安装Dhcp服务
[root@dg ~]# cd /mnt/cdrom/Server/
[root@dg Server]# ll dhcp*
-r--r--r-- 108 root root 886718 2009-07-16 dhcp-3.0.5-21.el5.i386.rpm
-r--r--r-- 125 root root 134127 2009-07-16 dhcp-devel-3.0.5-21.el5.i386.rpm
-r--r--r-- 108 root root 196554 2009-07-16 dhcpv6-1.0.10-17.el5.i386.rpm
-r--r--r-- 108 root root 125916 2009-07-16 dhcpv6-client-1.0.10-17.el5.i386.rpm
[root@dg Server]# rpm -ivh dhcp-3.0.5-21.el5.i386.rpm
warning: dhcp-3.0.5-21.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
package dhcp-3.0.5-21.el5.i386 is already installed
3.修改配制文件
[root@dg Server]# vim /etc/dhcpd.conf
进去后原始没有几行数据在命令行模式下输入
:r /usr/share/doc/dhcp-3.0.5/dhcpd.conf ß中间可以用Tab键补全
进入后配置如下
#
ddns-update-style interim;
ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0 { ß作用域 、子网掩码
# --- default gateway
option routers 192.168.1.254; 网关
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "dg.com"; dns服务器域名
option domain-name-servers 192.168.1.1; 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.1.30 192.168.1.60; ßip地址池
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;
}
}
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
4.检查是否有错误并启动dhcp服务
[root@dg Server]# service dhcpd configtest
Syntax: OK
[root@dg Server]# service dhcpd start
启动 dhcpd: [确定]
四、验证dhcp 服务器
1.客户机首先释放原有ip地址本例是(xp为例)
2.再次获得ip
可以看到获得了ip为192.168.1.60 dns服务器为dg.com
3.在dhcp服务器上查看日志
[root@dg ~]# tail -f /var/log/messages
可以看到dhcp服务工作的整个过程,上面显示把192.168.1.60 分给了 dg-105dd83d02d
4.查看client主机属性
5.如果想开机启动的话可以设置
[root@dg Server]# chkconfig dhcpd on
好了,简单的配置就此完成了。
dhcp 超级作用域的配置
redhat5.4 配置dhcp超级作用域
服务器联网方式是host-only,ip地址为192.168.1.25
服务器的配置:1.安装dhcp服务器,在原有的配置基础上修改配置文件,
[root@dg ~]# vi /etc/dhcpd.conf
#
ddns-update-style interim;
ignore client-updates;
shared-network dgzz{ ß定义了一个超级作用域,名为dgzz
subnet 192.168.1.0 netmask 255.255.255.0 { ß定义一个子网 192.168.1.0
option routers 192.168.1.1; #默认路由
option subnet-mask 255.255.255.0;
option domain-name "dg.com"; #dns服务器名
option domain-name-servers 222.88.88.88;
option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
range dynamic-bootp 192.168.1.20 192.168.1.20;
# 分配的ip地址范围,即地址池,这里就配置了一个ip地址
default-lease-time 21600;
max-lease-time 43200;
host ns {
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 207.175.42.254;
}
}
subnet 192.168.2.0 netmask 255.255.255.0 {
option routers 192.168.2.1;
option subnet-mask 255.255.255.0;
option domain-name "dg1.com";
option domain-name-servers 222.88.88.88;
option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
range dynamic-bootp 192.168.2.30 192.168.2.30;
# 分配的ip地址范围,即地址池,这里就配置了一个ip地址
default-lease-time 21600;
max-lease-time 43200;
host ns1 {
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 207.175.42.254;
}
}
} 注:别忘了添加大括号。
注:为了验证,在每个地址池里面只配置了一个ip,为的是让客户端获得两个地址池了的ip地址,如果ip地址足够多的话,客户机就会把一个地址池了的ip用完后,在用另一地址池里的ip地址。
2.重启dhcp服务
[root@dg ~]# service dhcpd restart
关闭 dhcpd: [确定]
启动 dhcpd: [确定]
客户端的配置:
1. 两台xp的虚拟机,联网方式为host-only,ip地址改为自动获取
2. 对于xp1
3.对于xp2
在实际的应用中,两个地址池ip范围可以根据需求进行配置。