DHCP

1: yum install dhcp

第一步,复制模板文件

首先我们来查看一下DHCP的配置文件,

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

#

# DHCP Server Configuration file.

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

#

~  

这个文件提示我们去在/usr/share/doc/dhcp*/dhcpd.conf.saple是个模板文件。

现在去查看一下这个文件,

 [root@localhost ~]# cd /usr/share/doc/dhcp-3.0.5/

 [root@localhost dhcp-3.0.5]# ls | grep dhcpd.conf.sample

dhcpd.conf.sample

现在把这个文件复制成dhcpd.conf文件。

[root@localhost dhcp-3.0.5]#

[root@localhost dhcp-3.0.5]# cp dhcpd.conf.sample /etc/dhcpd.conf

cp: overwrite `/etc/dhcpd.conf'? y

第二步,编辑DHCP的配置文件

ddns-update-style interim;

ignore client-updates;

 

subnet 192.168.0.0 netmask 255.255.255.0 {

 

# --- default gateway

        option routers                         192.168.0.254;

        option subnet-mask                 255.255.255.0;

 

        option nis-domain                      " domain.org";

        option domain-name                   " example.com";

        option domain-name-servers        192.168.0.254;

 

        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 192.168.0.100 192.168.0.250;

        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 207.175.42.254;

        }

}

关于语法参数的解释,

ddns-update-style interim;

定义所支持的DNS的动态更新类型(必选)

ignore client-updates;

忽略客户端更新DNS记录

subnet 192.168.0.0 netmask 255.255.255.0

定义作用域是192.168.0.0/24

option routers  192.168.0.254

为客户端定义网关地址

option subnet-mask

网关的子网掩码

option nis-domain   "domain.org";

指定Nis的域名,没有定义

option domain-name  "example.com"

指定DNS的域名

option domain-name-servers  192.168.0.254;

指定DNS Serverip地址

option time-offset    -18000; # Eastern Standard Time

这个是时区的设置

range 192.168.0.100  192.168.0.250;

定义DHCP的地址池

default-lease-time   21600;

默认最小的租约期是21600S

max-lease-time 43200;

最大的租约期是43200S

好了,DHCP的服务器基本就配置成功了,可以提供工作了。

现在我们重启下服务,

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

Shutting down dhcpd:                                       [  OK  ]

Starting dhcpd:                                                 [  OK  ]

[root@localhost ~]#

服务启动成功,

现在我们到DHCP客户端上面去测试下,

永久租期主要是通过MAC地址和IP地址进行绑定,从而实现永久租期。

/etc/dhcpd.conf文件里面就可以定义。

现在我们给192.168.0.10这个IP地址做绑定,

        host station10 {

                hardware ethernet 00:0C:29:75:91:EC;

                fixed-address 192.168.0.10;

        }

语法参数解释

hardware ethernet 00:0C:29:75:91:EC;

这个是代表需要绑定计算机的MAC地址

fixed-address 192.168.0.10;

这个是需要保留的IP地址

注意,这个保留的IP地址不可以在定义的地址池范围内,否则没有意义。

设置完成,现在重启下DHCP服务。DHCP客户端上面去测试下