Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

14.4 Assign a fixed IP address


May 24, 2021 That's what Linux should learn



There is a term in the DHCP protocol that is "appointment" and is used to ensure that specific devices in the local area network always get a fixed IP address. In other words, the dhcpd service will hide an IP address and use it only for a specific device that matches it.

To bind an IP address to a host, you need to use the MAC address of that host. Mac addresses are a string of independent identifiers on the network card and are unique, so there will be no conflicts, as shown in Figure 14-6.

14.4 Assign a fixed IP address

Figure 14-6 shows the MAC address of the host running the Linux system

In between Linux and Windows systems, you can find the MAC address of the host by looking at the status of the network card. In the profile of the dhcpd service provider, the IP address is bound to the MAC address in the following format.

Host host name . . .
hardware ethernet MAC address of the host;
fixed-address ip address to be specified;
}
What if it's not easy to see the MAC address of the host? F or example, to give the boss to use the host binding IP address, you can not casually go to view the boss's host information. I n response to this situation, Miss Liu Wei told everyone a good way. W e start by starting the dhcpd service program and assigning an IP address to the boss's host so that the IP address assignment record is saved in the log file of the DHCP server. Then look at the log files and you'll know the MAC address of the host (that is, the bold content below).

[root@linuxprobe ~]# tail -f /var/log/messages Mar 30 05:33:17 localhost dhcpd: Copyright 2004-2013 Internet Systems Consortium. Mar 30 05:33:17 localhost dhcpd: All rights reserved. Mar 30 05:33:17 localhost dhcpd: For info, please visit https://www.isc.org/software/dhcp/ Mar 30 05:33:17 localhost dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file Mar 30 05:33:17 localhost dhcpd: Wrote 0 leases to leases file. Mar 30 05:33:17 localhost dhcpd: Listening on LPF/eno16777728/00:0c:29:c4:a4:09/192.168.10.0/24 Mar 30 05:33:17 localhost dhcpd: Sending on LPF/eno16777728/00:0c:29:c4:a4:09/192.168.10.0/24 Mar 30 05:33:17 localhost dhcpd: Sending on Socket/fallback/fallback-net Mar 30 05:33:26 localhost dhcpd: DHCPDISCOVER from 00:0c:29:27:c6:12 via eno16777728 Mar 30 05:33:27 localhost dhcpd: DHCPOFFER on 192.168.10.50 to 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPDISCOVER from 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPOFFER on 192.168.10.50 to 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPREQUEST for 1 92.168.10.50 (192.168.10.10) from 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) via eno16777728 Mar 30 05:33:29 localhost dhcpd: DHCPACK on 192.168.10.50 to 00:0c:29:27:c6:12 (WIN-APSS1EANKLR) V ia eno16777728 Before I started speaking online, I always saw some students scratching their heads after the DHCP service. A t first I didn't understand, after all, the dhcpd service program is a very simple experiment in Linux system, a total of more than a dozen lines of configuration parameters can be written wrong? T he reason was later discovered - some of the participants experimented with the binding of IP and MAC addresses for Windows systems. M ac addresses seen in Windows systems are similar in format to 00-0c-29-27-c6-12, with an minus sign (-). In Linux systems, however, the spacer of the MAC address becomes a colon (:)).

[root@linuxprobe ~]# vim /etc/dhcp/dhcpd.conf ddns-update-style none; i gnore client-updates; s ubnet 192.168.10.0 netmask 255.255.255.0 { range 192.168.10.50 192.168.10.150; o ption subnet-mask 255.255.255.0; o ption routers 192.168.10.1; o ption domain-name "linuxprobe.com"; o ption domain-name-servers 192.168.10.1; d efault-lease-time 21600; m ax-lease-time 43200; h ost linuxprobe { hardware ethernet 00:0c:29:27:c6:12; f ixed-address 192.168.10.88; After you confirm that the parameters are filled in correctly, you can save the exit profile, and then you can restart the dhcpd service program.

It root@linuxprobe is important to note that if you have just assigned this host an IP address, its IP address lease has not expired and therefore will not be immediately replaced with a newly bound IP address. To see the binding effect immediately, you need to restart the client's network service, as shown in Figure 14-7.

14.4 Assign a fixed IP address

Figure 14-7 restarts the client's network service to see the binding effect