我的环境:
两台RedHat6.2,其中192.168.16.11作测试,192.168.16.12做dhcp服务器
dhcp版本:dhcp-4.1.1-25.P1.el6.i686
实验步骤:
1、由于镜像已拷贝到服务器端,直接在服务器端搭建本地yum源:
[root@redhat6-2 dhcp]# vi /etc/yum.repos.d/rhel-source.repo
[my-yum]
name=Red Hat Enterprise 6.2
baseurl=file:///var/ftp/pub/Server
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
2、使用yum update更新yum源:
3、使用yum install dhcp-* 安装dhcp
Running Transaction
Installing : 12:dhcp-4.1.1-25.P1.el6.i686 1/1
Installed products updated.
Installed:
dhcp.i686 12:4.1.1-25.P1.el6
Complete!
4、手动写dhcp的配置文件:
[root@redhat6-1 ~]# vi /etc/dhcp/dhcpd.conf
也可直接copy模板,修改一下即可:
[root@redhat6-1 ~]# cp -rf /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
配置文件内容如下:关键内容已标出
ddns-update-style interim; 支持DDNS
ignore client-updates; 忽略DDNS更新
subnet 192.168.16.0 netmask 255.255.255.0 { 声明作用域
# --- default gateway
option routers 192.168.16.1; 网关
option subnet-mask 255.255.255.0; 掩码
option nis-domain "domain.org"; NIS域
option domain-name "domain.org"; DHCP名字
option domain-name-servers 10.37.16.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.0.128 192.168.0.254;
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 fantasia.fugue.com;
}
}
5、保存退出,重启一下dhcp服务:service dhcpd restart
6、修改测试端的IP设置为dhcp获取
[root@redhat6-1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
加入BOOTPROTO=dhcp即可
DEVICE="eth1"
HWADDR="00:0C:29:19:FB:ED"
NM_CONTROLLEiD="no"
ONBOOT="yes"
BOOTPROTO=dhcp
IPADDR=192.168.16.11
NETMASK=255.255.255.0
7、测试端(原本IP是192.168.16.11)输入dhclient
由于dhcp重新获取ip,ip地址已改变
8、进入虚拟机查看IP是否发生了变化,IP是否是从dhcp服务器端获得
ip地址果然发生变化,服务端查看ip资源分配情况
[root@redhat6-2 dhcp]# cat /var/lib/dhcpd/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.1.1-P1
lease 192.168.16.128 {
starts 2 2013/12/10 10:50:51;
ends 2 2013/12/10 16:50:51;
tstp 2 2013/12/10 16:50:51;
cltt 2 2013/12/10 10:50:51;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:19:fb:ed;
}
192.168.16.128分配给了00:0c:29:19:fb:ed,完全一致,dhcp配置成功!
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29320885/viewspace-1062880/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29320885/viewspace-1062880/