day17 - DHCP

谁说我不能喝 提交于 2020-03-24 03:46:58

 DCHP Servers

Dynamic Host Configuration Protocol (DHCP) is a network protocol that automatically assigns TCP/IP information to client machines. Each DHCP client connects to the centrally located DHCP server, which returns the network configuration (including the IP address, gateway, and DNS servers) of that client.

Why Use DHCP?

DHCP is useful for automatic configuration of client network interfaces. When configuring the client system, you can choose DHCP instead of specifying an IP address, netmask, gateway, or DNS servers. The client retrieves this information from the DHCP server. DHCP is also useful if you want to change the IP addresses of a large number of systems. Instead of reconfiguring all the systems, you can just edit one configuration file on the server for the new set of IP addresses. If the DNS servers for an organization changes, the changes happen on the DHCP server, not on the DHCP clients. When you restart the network or reboot the clients, the changes go into effect.
If an organization has a functional DHCP server correctly connected to a network, laptops and other mobile computer users can move these devices from office to office.

Configuring A DHCP Server

[root@xlnx-lab05 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.0 (Maipo)

 

[root@xlnx-lab05 ~]# yum -y install dhcp

 Configuration File

[root@xlnx-lab05 ~]# cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
ddns-update-style none;
ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0{
range 192.168.1.100 192.168.1.120;
option subnet-mask 255.255.255.0;
option routers 192.168.1.254;
option domain-name-servers 8.8.8.8;
default-lease-time 21600;
max-lease-time 43200;
}

 

[root@xlnx-lab05 ~]# systemctl restart dhcpd
[root@xlnx-lab05 ~]# systemctl enable dhcpd
[root@xlnx-lab05 ~]# systemctl status dhcpd
dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled)
   Active: active (running) since Tue 2020-03-24 01:17:01 CST; 8s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 35428 (dhcpd)
   CGroup: /system.slice/dhcpd.service
           └─35428 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid

Mar 24 01:17:01 xlnx-lab05 systemd[1]: Started DHCPv4 Server Daemon.
Mar 24 01:17:01 xlnx-lab05 dhcpd[35428]: Internet Systems Consortium DHCP Server 4.2.5
Mar 24 01:17:01 xlnx-lab05 dhcpd[35428]: Copyright 2004-2013 Internet Systems Consortium.
Mar 24 01:17:01 xlnx-lab05 dhcpd[35428]: All rights reserved.
Mar 24 01:17:01 xlnx-lab05 dhcpd[35428]: For info, please visit https://www.isc.org/software/dhcp/
Mar 24 01:17:01 xlnx-lab05 dhcpd[35428]: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Mar 24 01:17:01 xlnx-lab05 dhcpd[35428]: Wrote 1 leases to leases file.
Mar 24 01:17:01 xlnx-lab05 dhcpd[35428]: Listening on LPF/eth0/00:0c:29:ad:b8:84/192.168.1.0/24
Mar 24 01:17:01 xlnx-lab05 dhcpd[35428]: Sending on   LPF/eth0/00:0c:29:ad:b8:84/192.168.1.0/24
Mar 24 01:17:01 xlnx-lab05 dhcpd[35428]: Sending on   Socket/fallback/fallback-net

 

[root@xlnx-lab05 ~]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    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 forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ad:b8:84 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.5/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fead:b884/64 scope link
       valid_lft forever preferred_lft forever
[root@xlnx-lab05 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.254   0.0.0.0         UG    1024   0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

 Windows Host

C:\Users\Xilong Jin>ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : PC01
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Ethernet0:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) 82574L Gigabit Network Connection
   Physical Address. . . . . . . . . : 00-0C-29-1F-43-7C
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 192.168.1.100(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Tuesday, March 24, 2020 1:03:01 AM
   Lease Expires . . . . . . . . . . : Tuesday, March 24, 2020 7:03:01 AM
   Default Gateway . . . . . . . . . : 192.168.1.254
   DHCP Server . . . . . . . . . . . : 192.168.1.5
   DNS Servers . . . . . . . . . . . : 8.8.8.8
   NetBIOS over Tcpip. . . . . . . . : Enabled

MAC Address Binding

Reterive Mac Addr

[root@xlnx-lab05 ~]# tail -F /var/log/messages
Mar 24 01:20:50 xlnx-lab05 dhcpd: DHCPREQUEST for 192.168.1.100 from 00:0c:29:1f:43:7c (PC01) via eth0
Mar 24 01:20:50 xlnx-lab05 dhcpd: DHCPACK on 192.168.1.100 to 00:0c:29:1f:43:7c (PC01) via eth0

 

[root@xlnx-lab05 ~]# cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
ddns-update-style none;
ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0{
range 192.168.1.100 192.168.1.120;
option subnet-mask 255.255.255.0;
option routers 192.168.1.254;
option domain-name-servers 8.8.8.8;
default-lease-time 21600;
max-lease-time 43200;
host yufengc{
hardware ethernet 00:0c:29:1f:43:7c;
fixed-address 192.168.1.118;
}
}
[root@xlnx-lab05 ~]# systemctl restart dhcpd
[root@xlnx-lab05 ~]# systemctl enable dhcpd

Windows Host

Microsoft Windows [Version 10.0.18362.30]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Xilong Jin>ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : PC01
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Ethernet0:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) 82574L Gigabit Network Connection
   Physical Address. . . . . . . . . : 00-0C-29-1F-43-7C
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 192.168.1.118(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Tuesday, March 24, 2020 1:29:55 AM
   Lease Expires . . . . . . . . . . : Tuesday, March 24, 2020 7:29:55 AM
   Default Gateway . . . . . . . . . : 192.168.1.254
   DHCP Server . . . . . . . . . . . : 192.168.1.5
   DNS Servers . . . . . . . . . . . : 8.8.8.8
   NetBIOS over Tcpip. . . . . . . . : Enabled

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!