版权声明:多多交流。 https://blog.csdn.net/qq_42776455/article/details/84791763
Linux,DHCP服务器配置
配置环境,redhat5.8(适用于linux新手练手)
安装
如果用rpm安装无法自动安装依赖包。
有yum源的情况下直接安装,没有yum源先配置/etc/yum.repos.d/local.repo
:
yum install dhcp
查看安装文件:
[root@localhost ~]# rpm -q dhcp
dhcp-3.0.5-31.el5
[root@localhost ~]# rpm -ql dhcp
/etc/dhcpd.conf
/etc/rc.d/init.d/dhcpd
/etc/rc.d/init.d/dhcrelay
/etc/sysconfig/dhcpd
/etc/sysconfig/dhcrelay
/usr/bin/omshell
/usr/sbin/dhcpd
/usr/sbin/dhcrelay
/usr/share/doc/dhcp-3.0.5
/usr/share/doc/dhcp-3.0.5/IANA-arp-parameters
/usr/share/doc/dhcp-3.0.5/README
/usr/share/doc/dhcp-3.0.5/RELNOTES
/usr/share/doc/dhcp-3.0.5/api+protocol
/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample
/usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-authentication-14.txt
/usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-dhcp-dns-12.txt
/usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-failover-07.txt
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient-script.8
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.8
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.conf.5
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.leases.5
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhcp-eval.5
/usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhcp-options.5
/usr/share/doc/dhcp-3.0.5/rfc1542.txt
/usr/share/doc/dhcp-3.0.5/rfc2131.txt
/usr/share/doc/dhcp-3.0.5/rfc2132.txt
/usr/share/doc/dhcp-3.0.5/rfc2485.txt
/usr/share/doc/dhcp-3.0.5/rfc2489.txt
/usr/share/doc/dhcp-3.0.5/rfc951.txt
/usr/share/man/man1/omshell.1.gz
/usr/share/man/man5/dhcp-eval.5.gz
/usr/share/man/man5/dhcp-options.5.gz
/usr/share/man/man5/dhcpd-eval.5.gz
/usr/share/man/man5/dhcpd-options.5.gz
/usr/share/man/man5/dhcpd.conf.5.gz
/usr/share/man/man5/dhcpd.leases.5.gz
/usr/share/man/man8/dhcpd.8.gz
/usr/share/man/man8/dhcrelay.8.gz
/var/lib/dhcpd
/var/lib/dhcpd/dhcpd.leases
配置
打开dhcp服务器的主配置文件/etc/dhcpd.conf
:
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
#
初次安装根据他的提示参考/usr/share/doc/dhcp*/dhcpd.conf.sample
:
[root@localhost ~]# cat /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample
ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
# --- default gateway
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "domain.org";
option domain-name-servers 192.168.1.1;
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.0.128 192.168.0.254;
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;
}
}
直接将该文件copy并重命名为/etc/dhcpd.conf
覆盖原有文件:
# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
cp:是否覆盖“/etc/dhcpd.conf”? y
You have new mail in /var/spool/mail/root
/etc/dhcpd.conf
主要更改以下参数:
-
有几个不同的dhcp需求的区域就写几个,花括号里是关于此dhcp服务器的配置
-
默认网关地址和掩码配置
-
指定NIS(网络信息服务)域名
-
时区设置
-
DHCP的地址池
-
ip地址租约设置
-
用来绑定固定ip
启动服务器测试
前情提要:设置的ip为192.168.19.0/24
service dhcpd restart
启动DHCP服务
在另外一台主机上修改IP地址设置模式为DHCP(动态),命令操作如下:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
再打开的配置文件中,修改为BOOTPROTO=dhcp
service network restart
客户端通过查看/var/lib/dhclient/dhclient-eth0.leases
,可以知道是从哪台dhcp服务器分配的地址。
server可以通过/var/lib/dhcpd/dhcpd.leases
查看ip分配情况。