Skip to main content

 路由器设置 > 新闻资讯 >

搭建DHCP服务器

2014-04-20 01:33 浏览:

步骤一、为服务器配置静态的IP地址

[root@localhost ~]# vim/etc/sysconfig/network-scripts/ifcfg-eth0

# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)

DEVICE=eth0

BOOTPROTO=static

ONBOOT=yes

HWADDR=00:0c:29:c3:b1:d9

IPADDR=192.168.80.253

NETMASK=255.255.255.0

 

步骤二、配置DHCP服务器

1、安装软件包

[root@localhost ~]# rpm -q dhcp

package dhcp is not installed              (dhcp软件包没有安装)

进入光盘文件安装dncp

[root@localhost ~]# cd /misc/cd/Server/

[root@localhost Server]#

查找dncp开通的文件

[root@localhost Server]# ls dhcp*

dhcp-3.0.5-31.el5_8.1.x86_64.rpm        dhcpv6-1.0.10-20.el5.x86_64.rpm

dhcp-devel-3.0.5-31.el5_8.1.i386.rpm    dhcpv6-client-1.0.10-20.el5.x86_64.rpm

dhcp-devel-3.0.5-31.el5_8.1.x86_64.rpm

安装dhcp软件包

[root@localhost Server]# rpm -ivhdhcp-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配置文件

让linux客户端获得固定的IP:192.168.80.188,win7客户端自动获取IP地址

[root@localhost ~]# vim /etc/dhcpd.conf

 

[root@localhost ~]# cat /etc/dhcpd.conf

ddns-update-style interim;

subnet 192.168.80.0 netmask 255.255.255.0 {

       optionrouters                  192.168.80.253;

       optionsubnet-mask              255.255.255.0;

       optiondomain-name             "tarena.com";

       optiondomain-name-servers     192.168.80.1,202.106.0.20;

       rangedynamic-bootp 192.168.80.80 192.168.80.100;

       range dynamic-bootp192.168.80.120 192.168.80.200;

       default-lease-time21600;

       max-lease-time43200;

       host linux {

               hardwareethernet 00:0C:29:B4:3D:3C;

              fixed-address 192.168.80.188;

       }

       host ns {

               hardware ethernet 12:34:56:78:AB:CD;

              fixed-address 207.175.42.254;

       }

}

 

3、启动服务

[root@localhost ~]# /etc/init.d/dhcpd configtest

Syntax: OK

[root@localhost ~]# /etc/init.d/dhcpd status

dhcpd 已停

[root@localhost ~]# /etc/init.d/dhcpd start

启动 dhcpd:                                              [确定]

[root@localhost ~]# chkconfig --list dhcpd

dhcpd           0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭

[root@localhost ~]# chkconfig dhcpd on

[root@localhost ~]# chkconfig --list dhcpd

dhcpd           0:关闭  1:关闭  2:启用  3:启用4:启用 5:启用  6:关闭

 

4、验证

分别登录两台客户机查看ip地址的获取情况

Linux获取的IP地址是192.168.80.188.