Experimental environment: two centos 7 and two win 7 as clients to obtain IP addresses.
(Configure the yum warehouse in advance and turn off the firewall and selinux)
Meaning: Assign IP addresses to different network segments.
The first step is to set the gateway to the IP address of the soft route in the first centos 7 and install the DHCP server.
yum install dhcp -y
The second step is to overwrite the main configuration file.
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
Then edit the main configuration and write the following command. (Two network segments are added here)
subnet 192.168.80.0 netmask 255.255.255.0 {
}
subnet 192.168.37.0 netmask 255.255.255.0 {
range 192.168.37.100 192.168.37.200;
option domain-name-servers 7.7.7.7;
option domain-name "37king";
option routers 192.168.37.2;
default-lease-time 600;
}
subnet 192.168.38.0 netmask 255.255.255.0 {
range 192.168.38.100 192.168.38.200;
option domain-name-servers 8.8.8.8;
option domain-name "38king";
option routers 192.168.38.2;
default-lease-time 600;
}
Then restart the dhcp service to make it take effect.
systemctl restart dhcpd
The third step, add two network cards to another centos 7 system
The fourth step, copy the configuration information of the two network cards.
/etc/sysconfig/network-scripts/
cp ifcfg-ens33 ifcfg-ens37
cp ifcfg-ens33 ifcfg-ens38
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens37
DEVICE=ens37
ONBOOT=yes
IPADDR=192.168.37.1
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens38
DEVICE=ens38
ONBOOT=yes
IPADDR=192.168.38.1
Restart to view
systemctl restart network
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:fc:f1:83 brd ff:ff:ff:ff:ff:ff
inet 192.168.80.50/24 brd 192.168.80.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::ad8e:1bfe:8f2f:952b/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:fc:f1:8d brd ff:ff:ff:ff:ff:ff
inet 192.168.37.1/24 brd 192.168.37.255 scope global noprefixroute ens37
valid_lft forever preferred_lft forever
inet6 fe80::a1ba:2207:b347:ed3e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:fc:f1:97 brd ff:ff:ff:ff:ff:ff
inet 192.168.38.1/24 brd 192.168.38.255 scope global noprefixroute ens38
valid_lft forever preferred_lft forever
inet6 fe80::c29e:8e6f:70e:e240/64 scope link noprefixroute
valid_lft forever preferred_lft forever
The fifth step is to install the dhcp service and enable the relay service.
dhcrelay 192.168.80.150
[root@localhost network-scripts]# dhcrelay 192.168.80.150
Dropped all unnecessary capabilities.
Internet Systems Consortium DHCP Relay Agent 4.2.5
Copyright 2004-2013 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/ens38/00:0c:29:fc:f1:97
Sending on LPF/ens38/00:0c:29:fc:f1:97
Listening on LPF/ens37/00:0c:29:fc:f1:8d
Sending on LPF/ens37/00:0c:29:fc:f1:8d
Listening on LPF/ens33/00:0c:29:fc:f1:83
Sending on LPF/ens33/00:0c:29:fc:f1:83
Sending on Socket/fallback
The sixth step is to turn on the routing makeup and hair function to make it a soft routing.
vim /etc/sysctl.conf
Add tonet.ipv4.ip_forward = 1
Turn this feature on again.
sysctl -p
Step 7 Test.