我们今天来做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 | 设置保留主机名,即相当于静态分配一个 |
下面是文字版的配置信息
ddns-update-style interim;
ignore client-updates; subnet 10.10.10.0 netmask 255.255.255.0 { # --- default gateway
option routers 10.10.10.10;
option subnet-mask 255.255.255.0; option domain-name "ns.gr.org";
option domain-name-servers 10.10.10.10; option time-offset ;
# 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 ; range dynamic-bootp 10.10.10.100 10.10.10.200;
default-lease-time ;
max-lease-time ; # we want the nameserver to appear at a fixed address
host boss {
next-server marvin.redhat.com;
hardware ethernet ::::AB:CD;
fixed-address 207.175.42.188;
}
}
4.配置完上面的内容后,我们重启一下DHCP服务
# service dhcpd start
查看守护进程(/usr/sbin/dhcpd)# ps -ax | grep dhcpd9782 ? 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
# All times in this file are in UTC (GMT), not your local timezone. This is
# not a bug, so please don't ask about it. There is no portable way to
# store leases in the local timezone, so please don't request this as a
# feature. If this is inconvenient or confusing to you, we sincerely
# apologize. Seriously, though - don't ask.
# The format of this file is documented in the dhcpd.leases() manual page.
# This lease file was written by isc-dhcp-V3.0pl1 lease 10.10.10.200 {
starts // ::;
ends // ::;
binding state active;
next binding state free;
hardware ethernet :::c0::;
uid "\001\000PV\300\000\001";
client-hostname "PC-20140925ISEN";
}
租约文件存在,我们有空的时候可以看看这个租约文件是什么内容。