We all know that in a LAN, dynamic IP allocation requires DHCP. However, all information from DHCP is transmitted via broadcast, which means it cannot pass through routers. This determines that a single DHCP server can only assign IP addresses to clients within its own subnet. If you want to use one DHCP server to allocate IPs to different subnets, you need to set up a DHCP relay agent in that subnet. A machine with a Linux system can be configured as a DHCP relay agent. Let's conduct an experiment to see the configuration method.
**Experiment Platform:** Two servers with Linux systems installed, one as the DHCP server (Server1), and the other as the DHCP relay agent server (Server2). Additionally, two PCs (PC1 and PC2) are used for testing.
**Experiment Environment:** Allocate three subnets:
- 192.168.10.0/24
- 192.168.20.0/24
The server acting as the DHCP relay agent needs to have two network cards: eth0 and eth1.
IP assignments are as follows:
- eth0: 192.168.10.1
- eth1: 192.168.20.1
The DHCP server (Server1) only needs one network card: eth0.
- eth0: 192.168.10.2, with gateway pointing to 192.168.10.1
The requirement is that the test PCs (PC1 and PC2) should be connected to two different subnets, and the final result of the experiment should show that both PCs obtain IP addresses from their respective subnets.
**Configuration of the DHCP Server:**
```bash
# vi /etc/dhcpd.conf
```
Reference configuration:
```plaintext
ddns-update-style interim;
ignore client-updates;
option subnet-mask 255.255.255.0;
option domain-name "domain.org";
default-lease-time 259200;
max-lease-time 777600;
option domain-name-servers 202.96.134.133, 202.96.128.68;
# Below is the configuration for the super scope
shared-network mynet {
subnet 192.168.10.0 netmask 255.255.255.0 {
option routers 192.168.10.1;
range dynamic-bootp 192.168.10.1 192.168.10.254;
}
subnet 192.168.20.0 netmask 255.255.255.0 {
option routers 192.168.20.1;
range dynamic-bootp 192.168.20.1 192.168.20.254;
}
}
```
Finally, start the DHCP server using the following command:
```bash
# service dhcpd restart
```
The DHCP server configuration is now successful.
**Configuration of the Relay Agent Server (Server2):**
First, configure the file `/etc/sysconfig/dhcrelay`:
```bash
# vi /etc/sysconfig/dhcrelay
```
Input the following inside the file:
```plaintext
INTERFACES="eth1 eth0"
DHCPSERVERS="192.168.10.2" # Pointing to the DHCP server
```
Next, start the `dhcrelay` service:
```bash
# service dhcrelay restart
#echo "1" > /proc/sys/net/ipv4/ip_forward
```
Test using PC1 and PC2, and check the results.
**Note:**
When conducting the experiment in a virtual environment, the network card settings for the virtual networks are as follows:
- Server1's eth0 points to VMnet2
- Server2's eth0 points to VMnet2, and eth1 points to VMnet5
- PC1's network card points to VMnet2
- PC2's network card points to VMnet5
**Article Address:** [Eden Network](http://www.edenw.com/tech/os/unix/2010-07-17/4775.html)