项目名称 | 基础信息 |
---|---|
操作系统 | Centos7.8 |
IP地址 | 192.168.250.219 |
SElinux | 已关闭 |
防火墙 | 已启用,开放相关端口:UDP/67和UDP/68 |
DHCP地址池 | 192.168.250.2-192.168.250.90 |
[root@dhcp-server ~]# yum -y install dhcp已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile
默认情况下,dhcpd.conf配置文件在 /etc/dhcp/
目录下,默认的配置内容为空,如下:
[root@dhcp-server ~]# cd /etc/dhcp[root@dhcp-server dhcp]# ll总用量 8drwxr-xr-x. 2 root root 236月 102021 dhclient.ddrwxr-xr-x. 2 root root 284月 1216:09 dhclient-exit-hooks.d-rw-r--r--. 1 root root 1206月 102021 dhcpd6.conf-rw-r--r--. 1 root root 1176月 102021 dhcpd.confdrwxr-x---. 2 root dhcpd 284月 1216:09 scripts[root@dhcp-server dhcp]# cat dhcpd.conf## DHCP Server Configuration file.# see /usr/share/doc/dhcp*/dhcpd.conf.example# see dhcpd.conf(5) man page#[root@dhcp-server dhcp]#
从 /usr/share/doc/dhcp-*/dhcpd.conf.example
复制文件到 /etc/dhcp
下,文件名为 dhcpd.conf
,进行覆盖。
[root@dhcp-server dhcp]# cp -a /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.confcp:是否覆盖"/etc/dhcp/dhcpd.conf"?y[root@dhcp-server dhcp]#
[root@dhcp-server dhcp]# cat dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
subnet 10.152.187.0 netmask 255.255.255.0{
}
# This is a very basic subnet declaration.
subnet 10.254.239.0 netmask 255.255.255.224{
range 10.254.239.1010.254.239.20;
option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}
# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.
subnet 10.254.239.32 netmask 255.255.255.224{
range dynamic-bootp 10.254.239.4010.254.239.60;
option broadcast-address 10.254.239.31;
option routers rtr-239-32-1.example.org;
}
# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224{
range 10.5.5.2610.5.5.30;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option routers 10.5.5.1;
option broadcast-address 10.5.5.31;
default-lease-time 600;
max-lease-time 7200;
}
# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.
host passacaglia {
hardware ethernet 0:0:c0:5d:bd:95;
filename "vmunix.passacaglia";
server-name "toccata.fugue.com";
}
# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP. Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
host fantasia {
hardware ethernet 08:00:07:26:c0:a5;
fixed-address fantasia.fugue.com;
}
# You can declare a class of clients and then do address allocation
# based on that. The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.
class"foo"{
match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
}
shared-network 224-29{
subnet 10.17.224.0 netmask 255.255.255.0{
option routers rtr-224.example.org;
}
subnet 10.0.29.0 netmask 255.255.255.0{
option routers rtr-29.example.org;
}
pool {
allow members of "foo";
range 10.17.224.1010.17.224.250;
}
pool {
deny members of "foo";
range 10.0.29.1010.0.29.230;
}
}
[root@dhcp-server dhcp]#
这里只配一个基本的网络DHCP服务,地址范围为规划的地址:[192.168.250.2,192.168.250.90]。
配置如下:
[root@dhcp-server dhcp]# vim dhcpd.conf
[root@dhcp-server dhcp]#
# This is a very basic subnet declaration.
subnet 192.168.250.0 netmask 255.255.255.0{
range 192.168.250.2192.168.250.90; #指定IP地址范围
option routers 192.168.250.1; #指定网关地址
option broadcast-address 192.168.250.255; #指定广播地址
default-lease-time 600; #指定默认租约
max-lease-time 7200; #指定最大租约
}
[root@dhcp-server dhcp]# systemctl restart dhcpd[root@dhcp-server dhcp]# systemctl status dhcpd● dhcpd.service - DHCPv4ServerDaemonLoaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)Active: active (running) since 五 2022-04-1512:42:03 CST; 10s agoDocs: man:dhcpd(8) man:dhcpd.conf(5)Main PID: 18776(dhcpd)Status: "Dispatching packets..."Tasks: 1CGroup: /system.slice/dhcpd.service└─18776/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
启动一个客户面,查看能否获得IP。
本次在LINUX客户机下,先配置自动获取IP地址
[root@mysvn ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0TYPE=EthernetBOOTPROTO=dhcp #自动获取IP地址DEFROUTE=yesIPV4_FAILURE_FATAL=noNAME=eth0UUID=434372f7-39e5-48b7-968b-61dc7193c902DEVICE=eth0ONBOOT=yes
然后重启网络服务,查看获取的IP地址为 192.168.250.2/24
,如下:
[root@mydhcpclient ~]# ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN groupdefault qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP groupdefault qlen 1000 link/ether 52:54:00:43:f4:24 brd ff:ff:ff:ff:ff:ff inet 192.168.250.2/24 brd 192.168.250.255 scope global noprefixroute dynamic eth0 valid_lft 572sec preferred_lft 572sec inet6 fe80::652b:6da4:4354:b80a/64 scope link tentative noprefixroute dadfailed valid_lft forever preferred_lft forever inet6 fe80::c1d:8fe4:757a:da37/64 scope link tentative noprefixroute dadfailed valid_lft forever preferred_lft forever inet6 fe80::941:8a6:6c27:1098/64 scope link tentative noprefixroute dadfailed valid_lft forever preferred_lft forever3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN groupdefault qlen 1000 link/ether 52:54:00:d7:57:29 brd ff:ff:ff:ff:ff:ff inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN groupdefault qlen 1000 link/ether 52:54:00:d7:57:29 brd ff:ff:ff:ff:ff:ff[root@mydhcpclient ~]#
那么为什么要有保留地址呢?一些主机需要固定的IP,但是仍然使用DHCP来分配地址,配置完地址保留后,以后每次给这个主机分配的IP都是相同的。
还是打开配置文件 /etc/dhcp/dhcpd.conf
找到下面这部分:
# Fixed IP addresses can also be specified for hosts. These addresses# should not also be listed as being available for dynamic assignment.# Hosts for which fixed IP addresses have been specified can boot using# BOOTP or DHCP. Hosts for which no fixed address is specified can only# be booted with DHCP, unless there is an address range on the subnet# to which a BOOTP client is connected which has the dynamic-bootp flag# set.host fantasia { hardware ethernet 08:00:07:26:c0:a5;fixed-address fantasia.fugue.com;}
然后进行修改,比如,这次要保留地址 192.168.250.10
的地址为NC服务器,这台NC服务器的MAC地址为 08-3a-38-9d-9A-71
,则进行如下配置:
host fantasia { hardware ethernet 08:3a:38:9d:9A:71; #被指定的主机的MAC地址fixed-address 192.168.250.10; #指定的IP}
为什么要用到超级作用域,现在局域网用的是C类网段分配主机,但是主机数目大于254,一个C类网段不够分,所以要两个网段才行,还要这两个网段之间能够通信。这时候我们就可以把路由器和DHCP服务器结合到一起来用。
[root@dhcp-server dhcp]# cd /etc/sysconfig/network-scripts/
[root@dhcp-server network-scripts]# cp ifcfg-eth0 ifcfg-eth0:0
[root@dhcp-server network-scripts]# vim ifcfg-eth0:0
[root@dhcp-server network-scripts]#
[root@dhcp-server network-scripts]# cat ifcfg-eth0:0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
UUID=434372f7-39e5-48b7-968b-61dc7193c902
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.251.219
PREFIX=24
GATEWAY=192.168.251.1
DNS1=192.168.251.219
[root@dhcp-server network-scripts]#
配置另一个的IP为 192.168.251.219
。
/etc/dhcp/dhcpd.conf
,找到下面部分:
shared-network 224-29{ subnet 10.17.224.0 netmask 255.255.255.0{ option routers rtr-224.example.org;} subnet 10.0.29.0 netmask 255.255.255.0{ option routers rtr-29.example.org;} pool { allow members of "foo"; range 10.17.224.1010.17.224.250;} pool { deny members of "foo"; range 10.0.29.1010.0.29.230;}}[root@dhcp-server dhcp]#
进行修改:
shared-network 250-251{ subnet 192.168.250.0 netmask 255.255.255.0{ option routers 192.168.250.1; range 192.168.250.2192.168.250.254;} subnet 192.168.251.0 netmask 255.255.255.0{ option routers 192.168.251.1; range 192.168.251.2192.168.251.200;}
服务热线
1391-024-6332
Copyright 2015-2018 www.intsavi.com.cn All Rights Reserved
电话:010-62980070 010-62961051 手机:13910246332
版权所有北京赛维博信科技发展有限公司 备案号:京ICP备14043711号-1 京ICP备14043711号-3