单独DHCP服务器的搭建方法和步骤
1:配置DHCP的前提条件:
A.实验环境准备
1.计算机:两台LINUX虚拟机,一台windows虚拟机。
2.网 络:设置三台虚拟机的可以全部连接通。
B.DHCP服务器需要固定的IP //服务器自己得有静态的IP地址。
- vim /etc/sysconfig/network-scripts/ifG-eth0
- # Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
- DEVICE=eth0
- BOOTPROTO=static //这里要改为静态配置
- HWADDR=00:0C:29:6B:CE:CA
- ONBOOT=yes //可以自动读取此配置文件
- IPADDR=192.168.50.253
- NETMASK=255.255.255.0
- [root@gyf ~]# service network restart
- [root@gyf ~]# chkconfig network on
- [root@gyf ~]# ifconfig | grep "inet addr"
- Inet addr:192.168.50.253 Bcast:192.168.50.255 Mask:255.255.255.0
- inet addr:127.0.0.1 Mask:255.0.0.0
C.查看dhcp软件包是否安装,安装此软件包。
[root@gyf# rpm -q dhcp
package dhcp is not installed
注:没有安装,加入安装光盘,在这里加入5.9iso镜像。
- [root@gyf ~]# cd /misc/cd/Server/
- [root@gyf Server]# ls dhcp*
- dhcp-3.0.5-31.el5_8.1.x86_64.rpm
- dhcp-devel-3.0.5-31.el5_8.1.i386.rpm
- dhcp-devel-3.0.5-31.el5_8.1.x86_64.rpm
- dhcpv6-1.0.10-20.el5.x86_64.rpm
- dhcpv6-client-1.0.10-20.el5.x86_64.rpm
注:然后在这个目录下,用rpm来安装 dhcp软件包,看是否有依赖关系,如果没有就立即安装,若有依赖关系,就配置YUM,来解决安装软件包的依赖关系。
[root@gyf Server]# rpm -ivh dhcp-3.0.5-31.el5_8.1.x86_64.rpm
warning: dhcp-3.0.5-31.el5_8.1.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:dhcp ########################################### [100%]
注:没有依赖关系,就直接安装成功。
2:DHCP服务器的配置
- [root@gyf ~]# vim /etc/dhcpd.conf
- ddns-update-style interim;
- subnet 192.168.50.0 netmask 255.255.255.0 {
- option routers 192.168.50.254;
- option subnet-mask 255.255.255.0;
- option domain-name "gyf.org";
- option domain-name-servers 202.106.0.20;
- range dynamic-bootp 192.168.50.80 192.168.50.100;
- default-lease-time 21600;
- max-lease-time 43200;
- host ns {
- hardware ethernet 12:34:56:78:AB:CD;
- fixed-address 207.175.42.254;
- }
- }
3:启动服务
- [root@gyf ~]# rpm -ql dhcp | grep init.d
- /etc/rc.d/init.d/dhcpd
- /etc/rc.d/init.d/dhcrelay
- [root@gyf ~]# /etc/init.d/dhcpd status
- dhcpd 已停
- [root@gyf ~]# /etc/init.d/dhcpd start
- 启动 dhcpd: [确定]
- [root@gyf ~]# chkconfig --list dhcpd
- dhcpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭6:关闭
- [root@gyf ~]# chkconfig dhcpd on
- [root@gyf ~]# chkconfig --list dhcpd
- dhcpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
4:Linux客户机的测试:
[root@localhost ~]# ifconfig eth0
eth0 Link e ncEthernet HWaddr 00:0C:29:BD:81:6A
inet addr:192.168.50.100 Bcast:192.168.50.255 Mask:255.255.255.0
windows客户机的测试:
DHCP搭建成功,分配地址成功。
二、实验名称(固定给一个客户机分配一个IP地址)
在实验一的基础上,修改/etc/dhcpd.conf配置文件。
进入配置文件vim /etc/dhcpd.conf
- host ns {
- next-server marvin.redhat.com;
- hardware ethernet 00:0C:29:BD:81:6A;
- //这是一台linux服务器的MAC地址。
- fixed-address 192.168.50.80;
- //这是固定分配给这一台linux服务器的IP地址。
- [root@gyf ~]# service dhcpd restart
关闭 dhcpd: [确定]
启动 dhcpd: [确定]
/重新启动服务
测试:
[root@localhost ~]# service network restart
正在关闭接口 eth0:[确定]
关闭环回接口:[确定]
弹出环回接口:[确定]
弹出界面 eth0:
正在决定 eth0 的 IP 信息...完成。[确定]
[root@localhost ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:BD:81:6A
inet addr:192.168.50.80 Bcast:192.168.50.255 Mask:255.255.255.0
注:这是单独DHCP服务器的配置,其实现在三级交换机就可以做了。