(三)跟我一起玩Linux网络服务:DHCP服务配置之主服务器配置

我们今天来做DHCP服务器的配置,我们的前提示要实现用一台虚拟机做DHCP服务器

 

1.首先,我们要有DHCP软件,我们用到下面两个软件(可以使用其他方法从网上直接安装,具体方法网络搜索)

dhcp-3.0pl1-23.i386.rpm

dhcp-devel-3.0pl1-23.i386.rpm

下载后,安装

# rpm -ivh /home/yanji/dhcp*.rpm

2.我们更新一下搜索的数据内容,查找我们的主配置文件

# updatedb
# locate dhcpd.conf
/etc/log.d/conf/services/dhcpd.conf
/usr/share/doc/dhcp-3.0pl1/dhcpd.conf.sample
/usr/share/man/man5/dhcpd.conf.5.gz

我们不难发现有一个文件是dhcpd.conf.sample,这个文件是我们最重要的切入点。

接下来使用下面的命令在目的目录下新建/etc/dhcpd.conf文件,是DHCP的配置文件

# cp /usr/share/doc/dhcp-3.0pl1/dhcpd.conf.sample /etc/dhcpd.conf

3.下面我们就修改这个DHCP配置文件

说明:

名称 解释
subnet 指定子网作用域
option routers 网关
option subnet-mask 网关子网掩码

option domain-name

option domain-name-servers

DNS,设置的域名和域名服务器的IP
option time-offset

时区时间

range dynamic-BOOTP 设置DHCP的地址池
default-lease-time

默认租约时间

max-lease-time 最大租约时间
host 设置保留主机名,即相当于静态分配一个

 

 

 

 

 

 

 

 

 

 

 

 

 

下面是文字版的配置信息

 1 ddns-update-style interim;
 2 ignore client-updates;
 3 
 4 subnet 10.10.10.0 netmask 255.255.255.0 {
 5 
 6 # --- default gateway
 7         option routers                  10.10.10.10;
 8         option subnet-mask              255.255.255.0;
 9 
10         option domain-name              "ns.gr.org";
11         option domain-name-servers      10.10.10.10;
12 
13         option time-offset              28800;
14 #       option ntp-servers              192.168.1.1;
15 #       option netbios-name-servers     192.168.1.1;
16 # --- Selects point-to-point node (default is hybrid). Don't change this unless
17 # -- you understand Netbios very well
18 #       option netbios-node-type 2;
19 
20         range dynamic-bootp 10.10.10.100 10.10.10.200;
21         default-lease-time 21600;
22         max-lease-time 43200;
23 
24         # we want the nameserver to appear at a fixed address
25         host boss {
26                 next-server marvin.redhat.com;
27                 hardware ethernet 12:34:56:78:AB:CD;
28                 fixed-address 207.175.42.188;
29         }
30 }

4.配置完上面的内容后,我们重启一下DHCP服务
# service dhcpd start

查看守护进程(/usr/sbin/dhcpd)
# ps -ax | grep dhcpd
9782 ?        S      0:00 /usr/sbin/dhcpd
9789 pts/0    S      0:00 grep dhcpd
有显示表示我们已经启动了DHCP服务,那么激动的时刻来临了
注:
5.这里我已经做了前面的几个,所以我的当前虚拟机是使用vmNet 1,ip是10.10.10.10(前面的文章有说明)

 我们把虚拟机的DHCP获取去掉

 再把Windows下面的网络适配器的VMNet1设置为自动获取

设置好之后,我们的最关键的都做了,看结果的时候到了,我们运行cmd,输入 ipconfig,下面显示的就证明我们配置成功了(我们配置的地址池最后一个是200),可以用我们的虚拟机做DHCP服务器了

 6.查看Linux下的租约文件

# cat  /var/lib/dhcp/dhcpd.leases

 1 # All times in this file are in UTC (GMT), not your local timezone.   This is
 2 # not a bug, so please don't ask about it.   There is no portable way to
 3 # store leases in the local timezone, so please don't request this as a
 4 # feature.   If this is inconvenient or confusing to you, we sincerely
 5 # apologize.   Seriously, though - don't ask.
 6 # The format of this file is documented in the dhcpd.leases(5) manual page.
 7 # This lease file was written by isc-dhcp-V3.0pl1
 8 
 9 lease 10.10.10.200 {
10   starts 1 2015/04/06 18:25:34;
11   ends 2 2015/04/07 00:25:34;
12   binding state active;
13   next binding state free;
14   hardware ethernet 00:50:56:c0:00:01;
15   uid "0100PV3000001";
16   client-hostname "PC-20140925ISEN";
17 }

租约文件存在,我们有空的时候可以看看这个租约文件是什么内容。

 

 

 

 

 

 

 

 

原文地址:https://www.cnblogs.com/miao-zp/p/4444637.html