一.准备实验用的两台虚拟机
1. 安装一台RHEL6.5虚拟机
关闭防火墙
[root@ser5 桌面]# service iptables stop
[root@ser5 桌面]# chkconfig iptables off
关闭SElinux
修改配置文件
[root@ser5 桌面]# vim /etc/selinux/config
改为
SELINUX=permissive
保存退出
安装好vmware-tools,方便复制粘贴。
关闭NetworkManager服务
[root@ser5 桌面]# /etc/init.d/NetworkManager stop
[root@ser5 桌面]# chkconfig NetworkManager off
修改ip 改为192.168.4.5/24
设置ONBOOT=yes NM_CONTROLED=no
配置YUM仓库,确保可用
[new]
name=myyum
baseurl=file:///misc/cd
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
克隆出另一台RHEL6.5虚拟机
二. 搭建简单的DHCP服务器
1.服务器端
安装dhcp
[root@ser5 桌面]# yum -y install dhcp
修改主配置文件
[root@ser5 桌面]# vim /etc/dhcp/dhcpd.conf
default-lease-time 7200;
max-lease-time 14400;
subnet 192.168.4.0 netmask 255.255.255.0 {
option routers 192.168.4.1;
option domain-name "tarena.com";
option domain-name-servers 202.106.0.20,8.8.8.8;
range 192.168.4.28 192.168.4.54;
range 192.168.4.128 192.168.4.200;
}
重启服务
[root@ser5 桌面]# service dhcpd restart
正在启动 dhcpd: [确定]
[root@ser5 桌面]# chkconfig dhcpd on
2.客户机端
修改网卡设置
[root@pc205 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
.. ..
BOOTPROTO=dhcp
[root@pc205 ~]# service network restart
[root@pc205 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:D3:F3:87
inet addr:192.168.4.28 Bcast:192.168.4.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fed3:f387/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5 errors:0 dropped:0 overruns:0 frame:0
TX packets:29 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:864 (864.0 b) TX bytes:3366 (3.2 KiB)
//客户机分配地址为192.168.4.28
三. 保留地址,根据网卡MAC地址,分配给客户机指定的地址
1.服务器调整
[root@svr5 ~]# vim /etc/dhcp/dhcpd.conf
host pc205 {
hardware ethernet 00:0C:29:4A:8C:27;
fixed-address 192.168.4.110;
}
[root@svr5 ~]# service dhcpd restart
2.客户机验证
更改获取模式 为dhcp
[root@pc205 桌面]# dhclient -d eth0
Internet Systems Consortium DHCP Client 4.1.1-P1
Copyright 2004-2010 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/00:0c:29:d3:f3:87
Sending on LPF/eth0/00:0c:29:d3:f3:87
Sending on Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 6 (xid=0x4d3a16de)
DHCPOFFER from 192.168.4.5
DHCPREQUEST on eth0 to 255.255.255.255 port 67 (xid=0x4d3a16de)
DHCPACK from 192.168.4.5 (xid=0x4d3a16de)
bound to 192.168.4.110 -- renewal in 3139 seconds.
本文出自 “没有标题可写” 博客,谢绝转载!
原文地址:http://xiao1.blog.51cto.com/9090424/1541252