好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

使用linux操作系统搭建dhcp服务器 - Linux操作系统:

在linux环境下搭建Dhcp服务器  

(1) 首先配置 dhcp 服务器端 --- 安装 dhcp 服务:

dhcp-3.0.5-23.el5.i386.rpm  ( dhcp 主要配置包)

  dhcpv6-1.0.10-18.el5.i386.rpm  ( dhcp 工具包)

rpm -ivh dhcp-3.0.5-23.el5.i386.rpm (可以使用rpm或者yum安装)

(2) 配置 dhcp 服务器:

rpm -qc dhcp     查看 dhcp 中可配置的脚本

rpm -ql dhcp |less   查看 dhcp 包的安装位置

Dhcp 的主要配置文件为: /etc/dhcpd.conf  进入进行编译

#

# DHCP Server Configuration file.

#   see /usr/share/doc/dhcp*/dhcpd.conf.sample  

#                                                                                                                

ddns-update-style interim;

ignore client-updates;

subnet 192.168.10.0 netmask 255.255.255.0 {       (建立作用域)

# --- default gateway

        option routers                  192.168.10.254;        网管地址:

        option subnet-mask              255.255.255.0;

        option nis-domain               "domain.org";

        option domain-name              "test.ct";                 服务器名标识

        option domain-name-servers 222.88.88.88,222.85.85.85;  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.10.10 192.168.10.30;                  地址池

        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 00:0c:29:cf:12:2a;

                fixed-address 192.168.10.2;

        }

: r  /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample  (在底行使用此方法获取该文件的配置脚本参考)

( 3 )编译完成后  执行下面命令可以检查脚本是否有错,并可根据报错找出位置

[root@luo Server]# service dhcpd configtest

Syntax: OK    (此为没错)

(4) 启动 dhcp 服务

chkconfig   dhcpd  on   或者   service dhcpd  start 

(5) 在 dhcp 客户端( linux )获取地址:

在命令行中使用  dhclient 工具获取地址, linux dhcp 服务器分配地址的顺序是由大到小

dhclient -d eth0    从 eth0 网卡获取地址 

此时便可以看到获取的地址是 192.168.10.30 ,是从 192.168.10.3 服务器上获取的

 

我们绑定的主机也获取到了相应的 ip

当然对比一下,在 windows 安装配置 dhcp 服务器那更是小菜一碟

 

(6) 如果网络内存在上千台主机,那么上叙的配置是远远不行的

这里我们需要使用超级作用域了,顾名思义,超级作用域是一个很大域,里面有若干个小的子作用域组成 windows 下配置如下:

 

 

那么 linux 下呢,我们可以这样来:

使用一个  shared-network test{  子作用域  }  例如:

ddns-update-style interim;

ignore client-updates;

shared-network test{

subnet 192.168.20.0 netmask 255.255.255.0 {

# --- default gateway

        option routers                  192.168.20.254;

        option subnet-mask              255.255.255.0;

        option nis-domain               "domain.org";

        option domain-name              "test.ct";

        option domain-name-servers      222.88.88.88,222.85.85.85;

        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.20.10 192.168.20.10;

        default-lease-time 21600;

        max-lease-time 43200;

        # we want the nameserver to appear at a fixed address

}

subnet 192.168.10.0 netmask 255.255.255.0 {

# --- default gateway

        option routers                  192.168.10.254;

        option subnet-mask              255.255.255.0;

        option nis-domain               "domain.org";

        option domain-name              "test.ct";

        option domain-name-servers      222.88.88.88,222.85.85.85;

        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.10.2 192.168.10.2;

        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 00:0c:29:cf:12:2a;

                fixed-address 192.168.10.2;

        }

}

}

然后检查是否有错: service dhcpd configtest

在重启服务:    service dhcpd restart

 

 

(7) 但是每个 dns 每次获取的都是分配的,若想自己手动配置:

 dns 指向参数文件 ------/etc/resolv.conf

nameserver 222.85.85.85

nameserver 222.88.88.88

则需要编译  /etc/sysconfig/network-scripts/ifcfg-eth0  文件

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth0

BOOTPROTO=none

BROADCAST=192.168.100.255

HWADDR=00:0c:29:5a:46:70

IPADDR=192.168.100.99

NETMASK=255.255.255.0

NETWORK=192.168.100.0

PEERDNS=no               (添加)

ONBOOT=yes

GATEWAY=192.168.100.254

TYPE=Ethernet

(8) 此时便可以通过修改 /etc/resolv.conf   手工分配 dns 了

 

9 服务器选项作用整个超级作用域,作用域选项作用个子作用域

 

作者[missingluo]

查看更多关于使用linux操作系统搭建dhcp服务器 - Linux操作系统:的详细内容...

  阅读:47次