Linux七大项目作业——DHCP

@toc

DHCP作业
(1)DHCP服务器的地址都是172.16.118.100+学号/24,
    有效IP地址段为172.16.118.1172.16.118.254,
    子网掩码是255.255.255.0,
    网关为172.16.118.254。
(2)172.16.118.200
172.16.118.253网段地址是服务器的固定地址。
(3)客户端可以使用的地址段为172.16.118.1~172.16.118.99,5
   但172.16.118.88为保留地址,其中172.16.118.88保留给zhangsan。
(4)DNS服务器IP为8.8.8.8和61.128.128.68。
(5)客户机租用时间为2个小时。 每个人的IP地址和地址池随系统IP进行变化。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[root@lai18 html]# ifconfig  ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.118.118 netmask 255.255.255.0 broadcast 172.16.118.255
inet6 fe80::cc92:1612:53f5:26dd prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:37:c8:db txqueuelen 1000 (Ethernet)
RX packets 7452 bytes 710992 (694.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5802 bytes 857597 (837.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
//ether 00:0c:29:37:c8:db 本机网卡的MAC地址

ping -c 1 172.16.118.118 //ping远程计算机172.16.118.118一次
[root@lai18 html]# arp -n //查询缓存
Address HWtype HWaddress Flags Mask Iface
172.16.118.254 (incomplete) ens33
172.16.118.188 ether 02:00:4c:4f:4f:50 C ens33
//02:00:4c:4f:4f:50 远程计算机MAC地址

rpm -q dhcp
yum -y install dhcp //安装DHCP服务
cp -p /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y //这里输y
vi /etc/dhcp/dhcpd.conf //编辑配置
//添加以下内容
ddns-update-style none;
log-facility local7;
subnet 172.16.118. 0 netmask 255.255.255.0 {
range 172.16.118.1 172.16.118.87;
range 172.16.118.89 172.16.118.99;
range 172.16.118.100 172.16.118.254; //这是地址池
option subnet-mask 255.255.255.0; //定义子网掩码
option routers 172.16.118.254; //定义默认网关地址
option domain-name "cqipc.eud"; //名称
option domain-name-servers 8.8.8.8,61.128.128.68; //定义DNS服务器地址
default-lease-time 600;
max-lease-time 7200; //租约时间
}
host zhangsan{ //为 zhangsan分配固定IP地址
hardware ethernet 02:00:4c:4f:4f:50;
fixed-address 172.16.118.88;
}

systemctl restart dhcpd
systemctl enable dhcpd
cat /var/lib/dhcpd/dhcpd.leases

配置内容

做这一块的时候,感觉有点小问题