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

DHCP of Linux system

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

I. DHCP request of C è S

C: client

S: server side

The first step: C è s uses DISCOVER to initiate DHCP request, because it does not know the specific IP of DHCP, so it uses network-wide broadcast. The DHCP server responds to the DHCPOFFER when it receives the request, indicating its identity. Packets that will be dropped by other non-DHCP servers

The second step: C è s uses DHCPREQUEST to initiate DHCP request to lease IP, which is broadcast all over the network. DHCP servers can rent IP using DHCPACK echo requests, and also use webcast, because the client still does not have IP

The third step: DHCPACK contains the corresponding IP lease rules. If the C client agrees, it initiates the DHCP request again to indicate that it agrees to lease, and the S server sends the IP with the rules to the C client. Both are in the form of webcast, and the C client verifies that IP is available

Part IV: after the client verifies that the IP is available, it initiates a lease request to the server, "indicates that it agrees to use this IP", and the server establishes the lease time and starts the lease! This time, we still use the form of network-wide broadcast.

A client:

Client C uses the address of 0.0.0.0 as the source address, the UDP68 port as the source port, 255.255.255.255 as the destination address, and the UDP67 port as the destination port to broadcast request IP address information! The broadcast message contains the MAC address and computer name of the DHCP client so that the DHCP server can determine which client sent the request!

B, server side

When the DHCP server receives the information that the client requests the IP address, it picks the remaining legitimate IP addresses from the address pool. If so, the DHCP server marks the IP and encapsulates it in the DHCPOFFER message and broadcasts it across the network. DHCPOFFER contains information such as:

MAC address of the DHCP client, legal IP provided by the DHCP server, subnet mask, default gateway, lease term, IP address of the DHCP server

II. DHCP configuration

Dynamic IP address control protocol

When the number of clients in the local area network reaches a certain level, they all use static IP with heavy workload and low efficiency, and using DHCP to automatically assign and manage IP can effectively improve work efficiency and reduce network failures!

2.1.The DHCP address pool (within the same network segment)

Objective: to create a range of IP addresses so that all clients can obtain IP from this range for easy management.

Steps:

Premise: first turn off the dhcp function of the iptables Selinux VMware virtual network card itself.

1. Use two virtual machines, one S and one C, and choose the same custom network card Vmnet10.

2. Install the DHCP package on S

A. Configure local yum source, / etc/yum.repo.d/rhel6.repo

Edit the content manually:

[rehl-server]

Name=***

Baseurl= file:///mnt

Enable=1

Gpgchack=0

B, mount the CD image

Mount / dev/sr0 / mnt

C, yum-y install dhcp

3. Modify dhcp configuration file

Cat / usr/share/doc/dhcp-4.1.1/dhcp.conf.sample > / etc/dhcp/dhcpd.conf

Two lines of subnet * * and range * * in vim / etc/dhcp/dhcpd.conf configuration can be used.

Format:

Subnet segment netmask mask {

Range IP1~IP2 (address range)

}

4. Detect whether there are syntax errors in the dhcp configuration

Service dhcpd configtest

5. Restart the service

Service dhcpd restart

6. Use C for verification

Set the Nic configuration to dhcp

Restart the network card service

2.2, DHCP reservation

In practice, the IP of the server in the computer room is fixed, and the frequency of change is very low, so it is necessary to bind IP and MAC so that the IP of A server can only be IP-A,B server and the IP of IP-A,B server can only be IP-B.

Steps:

1. Use three virtual machines, one S, two C, and the same virtual network card (turn off the dhcp of the network card itself)

2. Modify dhcp configuration file

The following in vim / etc/dhcp/dhcpd.conf

Host fantasia {

Hardware Ethernet + MAC

Fixed-address + corresponds to IP

}

Note: if you bind the MAC address of one PC here, you need to use one hostfantasia collection, and two PC should use two hostfantasia sets.

3. Enable the automatic acquisition function of the two C's to obtain the IP

Check whether the binding MAC effect works!

Here, in the virtual machine test, the PC bound to IP è MAC must first preempt the IP, so that other computers will not occupy the bound IP when assigning IP

Dhcp automatic allocation ip is assigned sequentially!

2.3.The scope of DHCP

Sometimes the number of IP in the DHCP address pool is too small, so it is necessary to add another network segment to increase the number of IP in the address pool to adapt to the change of office computer IP, that is, cross-segment DHCP.

1. Step: one S, two C, the same virtual network card (turn off the dhcp of the network card itself)

Both C's are acquired automatically.

The share-network public {} content in the configuration file needs to be modified

Note: there is only one IP in the address range of one of the subnet to ensure the verification of the scope effect!

2.4, DHCP Relay

Steps:

1. Preparation of experimental environment

A DHCP server S: eth0 (192.168.15.20) connects to the intranet VMnet 15

A DHCP relay: eth0 (192.168.15.254) connects to the intranet VMnet 15

Eth2 (192.168.14.254) connects to the public network VMnet 14

An extranet client: eth0 (automatic acquisition) connects to the extranet VMnet 14

2. Configure DHCP server S

1.1.The network card IP--eth0:192.168.15.20 needs to be modified.

1.2. turn off the dhcp function of iptables SElinux and VMnet14 VMnet15

Modify the configuration file

Cat / usr/share/doc/dhcp-4.1.1/dhcp.conf.sample > / etc/dhcp/dhcpd.conf

Vim / etc/dhcp/dhcpd.conf

Save exit and restart dhcpd service service dhcpd restart

Designated gateway ip route add default gw 192.168.15.254

(you can also write the gateway in the subnet of the configuration file)

3. Configure DHCP relay

3.1Modification of the network card IP

Eth0 (192.168.15.254) connects to the private network VMnet 15

Eth2 (61.150.14.254) connects to the public network VMnet 14

3.2. Close the defense modification configuration file

Close iptables SElinux

Install the dhcp service yum-yinstall dhcp

3.3.Modification of configuration file / etc/sysconfig/dhcrelay

Fourth line INTERFACES= "eth0 eth2" (Nic that requires address forwarding)

Line 6 DHCPSERVERS= "192.168.15. 15" (dhcp server IP)

Restart the dhcrelay service service dhcrelay start

3.4. Enable address forwarding function

Vim / etc/sysctl.conf

Net.ipv4.ip_forward=1

Refresh configuration file sysctl-p

4. Open the public network client, select VMnet14, and the network card automatically acquires IP to verify the experimental function.

Considerations for this lab concept:

1. The dhcp server is configured with both private and public subnet. You can assign private network ip address pool and public network ip address pool to dhcp at the same time.

2. At this point, the relay server needs to forward the addresses of two network segments, and the concept of address forwarding needs to be enabled.

3. Use the PC of VMnet15 to obtain the ip of 15 network segments

Use PC of VMnet14 to get ip of 14 network segments

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: 0

*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