Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Linux CentOS 7 install and configure the DHCP service?

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

First, configure DHCP server 1, install DHCP server software [root@centos01 ~]# mount /dev/cdrom /mnt/ mount: /dev/sr0 write protection, will mount [root@centos01 ~]#rm-rf/etc/yum.repos.d/CentOS-* [root@centos01 ~]# yum -y install dhcp The requested URL/etc/dhcp/dhcpd/was not found on this server. :r /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example ddns-update-style none; option domain-name "benet.com"; option domain-name-servers 202.106.0.10, 202.106.0.20; default-lease-time 600; max-lease-time 7200; 1) Configuration composition of/etc/dhcp/dhcpd.conf file

In the main configuration file dhcpd.conf, three types of configurations can be used: declarations, parameters, and options. Their respective roles and manifestations are as follows:

Declaration: used to describe the division of network layout in dhcpd server. It is the logical scope of network settings. Common declarations are subnet, host, where the subnet declaration is used to constrain a network segment. The host declaration is used to bind a particular host.

Parameters: Consists of configuration keywords and corresponding values, always ending with ";"(semicolon), generally within the specified declaration range, used to set the operating characteristics of the range (such as default lease time, maximum lease time, etc.).

Options: Guided by "option," followed by specific configuration keywords and corresponding values, also ending with ";," used to specify various address parameters assigned to clients (such as default gateway address, subnet mask, DNS server address, etc.). 2) Determine the global configuration of dhcpd services

To make the configuration file structure clearer, global configuration is usually placed at the beginning of the configuration file dhcod.conf, which can be configuration parameters or configuration options. Common global configuration parameters and options are described below:

ddns-update-style: Dynamic DNS update mode. Used to set the DNS data dynamic update mode associated with DHCP services. This parameter is rarely used in actual DHCP applications. Set the value to "none."

default-lease-time: Default lease time. The default time, in seconds, that a client can lease an IP address from a DHCP server.

max-lease-time: Maximum lease time. In seconds, indicates the maximum lease time allowed for DHCP client requests, and the default lease time is assumed by the server when the client does not request an explicit lease time.

option domain-name: Default search area. The default search domain when resolving host names is not specified by the client, and this configuration option is reflected in the client's/etc/resolv.conf configuration file, such as "search benet.com".

option domain-name-servers: DNS server address. Specify the DNS server address for the client to use when resolving domain names. This configuration option is also reflected in the client's/etc/resolv.conf configuration file, such as "nameserver 202.106.0.20". When multiple DNS server addresses need to be set, they are separated by commas. 3) Determine subnet segment declaration

A DHCP server can serve multiple segments, so subnet segment claims must and can have multiple segments. For example, if you want a DHCP server to serve the 192.168.100.0/24 segment, the IP address range for automatic assignment is 192.168.100. 100~192.168.100.200, specify the default gateway address for the client as 192.168.100.254, then ke can modify the dhcpd.conf configuration file, refer to the following to adjust the subnet segment declaration:

[root@centos01 ~]# vim /etc/dhcp/dhcpd.conf subnet 192.168.100.0 netmask 255.255.255.0 { range 192.168.100.100 192.168.100.200; option routers 192.168.100.254; }4) Determine host host declaration

The host declaration is used to set the network properties of a single host, usually used to assign a fixed IP address (reserved address) to a network printer or individual server. The common feature of these hosts is that they require the same IP address to be obtained each time to ensure the stability of the service.

The host declaration specifies the name of the client that requires a reserved address using the host keyword, the MAC address of the host using the hardware ethernet parameter, and the IP address reserved for the host using the fixed-address parameter. For example, to assign the printer prtsvr (MAC address 00:0C:29:0D:BA: 6B) a fixed IP address of 192.168.100.101, you can modify the dhcpd.conf configuration file to add the host host declaration to the segment declaration as follows.

C:\Users\Administrator>getmac Physical Address Transfer Name ========================================================================== \Device\Tcpip_{92E3F48B-40F0-4A0D-9604-6386AAAE3233} [root@centos01 ~]# vim /etc/dhcp/dhcpd.confhost win7 { hardware ethernet 00:0C:29:0D:BA:6B; fixed-address 192.168.100.101; Start dhcpd service

Before starting the dhcpd service, make sure that the network interfaces providing DHCP servers have static IP addresses, and that at least one of the IP addresses of the network interfaces corresponds to a subnet segment in the DHCP server, otherwise the dhcpd service will not start properly. For example, the DHCP server IP address is 192.168.100.10 for segment 192. Other clients within 168.100.0/24 provide automatic address assignment services.

After installing the dhcp package, the corresponding system service script is located in/usr/lib/systemd/system/dhcpd.service, which can be controlled using the systemd service. For example, do the following to start the dhcpd service and check if UDP port 67 is listening to confirm that the DHCP server is OK.

[root@centos01 ~]# systemctl start dhcpd [root@centos01 ~]# systemctl enable dhcpd [root@centos01 ~]# netstat -anptu | grep 67 udp 0 0 0.0.0.0:67 0.0.0.0:* 2102/dhcpd udp 0 0 0.0.0.0:67 0.0.0.0:* 1064/dnsmasq

Note: To shut down or restart dhcpd service, simply change "start" to "stop" or "restart" in the above operation command.

2. Use DHCP client 1. Windows client

ipconfig /renew ipconfig /release tracert IP address route print 2. Linux client

In Linux clients, you can configure DHCP to obtain addresses. Just edit the configuration file of the corresponding NIC, modify or add the "BOOTPROTO=dhcp" configuration line, and reload the configuration file or restart the network service. For example, do the following to modify the network card configuration file and reload the configuration to automatically acquire addresses via DHCP:

[root@centos02 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO=dhcpDEFROUTE=yesNAME=ens32DEVICE=ens32ONBOOT=yes[root@centos02 ~]# ifdown ens32 ; ifup ens32[root@centos02 ~]# systemctl restart network

In Linux clients, you can also use the dhclient tool to test DHCP servers. If the command "dhclient" is executed directly, dhclient will try to request new addresses via DHCP for all network interfaces except loopback interface lo, and then automatically go to the background to continue running. Of course, you can specify a specific network interface when testing, and combine the "-d" option to make it run in the foreground. After testing, press Ctrl+C to terminate. For example, after executing the command "dhclient -d ens32", you can automatically obtain a new IP address for the network card ens32 and display the acquisition process.

[root@centos02 ~]# dhclient -d ens32Internet Systems Consortium DHCP Client 4.2.5Copyright 2004-2013 Internet Systems Consortium.All rights reserved.For info, please visit https://www.isc.org/software/dhcp/Listening on LPF/ens32/00:0c:29:97:5c:9fSending on LPF/ens32/00:0c:29:97:5c:9fSending on Socket/fallbackDHCPDISCOVER on ens32 to 255.255.255.255 port 67 interval 4 (xid=0x5364e17f)DHCPDISCOVER on ens32 to 255.255.255.255 port 67 interval 6 (xid=0x5364e17f)DHCPDISCOVER on ens32 to 255.255.255.255 port 67 interval 14 (xid=0x5364e17f) DHCPREQUEST on ens32 to 255.255.255.255 port 67 (xid=0x5364e17f) DHCPOFFER from 192.168.100.10 DHCPACK from 192.168.100.10 (xid=0x5364e17f) bound to 192.168.100.102 -- renewal in 229 seconds.............

When the client needs to release the acquired IP lease through the dhclient command, it can be combined with the "-r" option. For example, executing the following "dhclient -r ens32" will release the IP lease previously acquired for NIC ens32. At this point, by executing the command "ifconfig ens32", the assigned IP address is no longer visible.

[root@centos02 ~]# dhclient -r ens32

--------This article ends here, thanks for reading-------

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 211

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report