Rocky8.6-2 A
[root@wing ~]# vim /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto resume=UUID=f8444bff-4b00-4c57-8cc7-556695548c55 rhgb quiet net.ifnames=0"
[root@wing ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
[root@wing ~]# reboot
[root@wing ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=172.20.0.34
PREFIX=16
GATEWAY=172.20.0.254
ONBOOT=yes
[root@wing ~]# nmcli connection reload eth0
[root@wing ~]# reboot
[root@wing ~]# systemctl disable --now firewalld.service
[root@wing ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.20.0.34 netmask 255.255.0.0 broadcast 172.20.255.255
inet6 fe80::20c:29ff:fe1b:b65b prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:1b:b6:5b txqueuelen 1000 (Ethernet)
RX packets 98779 bytes 8926143 (8.5 MiB)
RX errors 0 dropped 7782 overruns 0 frame 0
TX packets 32135 bytes 1983825 (1.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Rocky8.6-3 R1
[root@wing ~]# vim /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto resume=UUID=f8444bff-4b00-4c57-8cc7-556695548c55 rhgb quiet net.ifnames=0"
[root@wing ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
[root@wing ~]# reboot
[root@wing ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.7
PREFIX=24
ONBOOT=yes
[root@wing ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
NAME=eth0
BOOTPROTO=static
IPADDR=172.20.0.254
PREFIX=16
ONBOOT=yes
[root@wing ~]# nmcli connection reload eth0
[root@wing ~]# nmcli connection reload eth1
[root@wing ~]# reboot
[root@wing ~]# systemctl disable --now firewalld.service
[root@wing ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.7 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fea1:9c26 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:a1:9c:26 txqueuelen 1000 (Ethernet)
RX packets 5505 bytes 445833 (435.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2141 bytes 158343 (154.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@wing ~]# ifconfig eth1
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.20.0.254 netmask 255.255.0.0 broadcast 172.20.255.255
inet6 fe80::20c:29ff:fea1:9c30 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:a1:9c:30 txqueuelen 1000 (Ethernet)
RX packets 72666 bytes 7304356 (6.9 MiB)
RX errors 0 dropped 7847 overruns 0 frame 0
TX packets 6656 bytes 409799 (400.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@wing ~]# echo net.ipv4.ip_forward =1 >> /etc/sysctl.conf
[root@wing ~]# sysctl -p
[root@wing ~]# route add -net 192.168.10.0/24 gw 10.0.0.8
[root@wing ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
172.20.0.0 0.0.0.0 255.255.0.0 U 101 0 0 eth1
192.168.10.0 10.0.0.8 255.255.255.0 UG 0 0 0 eth0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
Rocky8.6-4 R2
[root@wing ~]# vim /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto resume=UUID=f8444bff-4b00-4c57-8cc7-556695548c55 rhgb quiet net.ifnames=0"
[root@wing ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
[root@wing ~]# reboot
[root@wing ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.8
PREFIX=24
ONBOOT=yes
[root@wing ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
NAME=eth0
BOOTPROTO=static
IPADDR=192.168.10.254
PREFIX=24
ONBOOT=yes
[root@wing ~]# nmcli connection reload eth0
[root@wing ~]# nmcli connection reload eth1
[root@wing ~]# reboot
[root@wing ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.8 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fec4:8fa6 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:c4:8f:a6 txqueuelen 1000 (Ethernet)
RX packets 5304 bytes 429455 (419.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2325 bytes 168213 (164.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@wing ~]# ifconfig eth1
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.254 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fec4:8fb0 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:c4:8f:b0 txqueuelen 1000 (Ethernet)
RX packets 2840 bytes 256019 (250.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 89 bytes 8333 (8.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@wing ~]# echo net.ipv4.ip_forward =1 >> /etc/sysctl.conf
[root@wing ~]# sysctl -p
[root@wing ~]# route add -net 172.20.0.0/16 gw 10.0.0.7
[root@wing ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
172.20.0.0 10.0.0.7 255.255.0.0 UG 0 0 0 eth0
192.168.10.0 0.0.0.0 255.255.255.0 U 101 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@wing ~]# systemctl disable --now firewalld.service
Rocky8.6-5 B
[root@wing ~]# vim /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto resume=UUID=f8444bff-4b00-4c57-8cc7-556695548c55 rhgb quiet net.ifnames=0"
[root@wing ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
[root@wing ~]# reboot
[root@wing ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=192.168.10.200
PREFIX=24
GATEWAY=192.168.10.254
ONBOOT=yes
[root@wing ~]# nmcli connection reload eth0
[root@wing ~]# reboot
[root@wing ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.200 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fe3c:529c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:3c:52:9c txqueuelen 1000 (Ethernet)
RX packets 353 bytes 30292 (29.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 493 bytes 49132 (47.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@wing ~]# systemctl disable --now firewalld.service
运行结果
A--->B
[root@wing ~]# ping 192.168.10.200 -c1
PING 192.168.10.200 (192.168.10.200) 56(84) bytes of data.
64 bytes from 192.168.10.200: icmp_seq=1 ttl=62 time=1.71 ms
--- 192.168.10.200 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.708/1.708/1.708/0.000 ms
B--->A
[root@wing ~]# ping 172.20.0.34 -c1
PING 172.20.0.34 (172.20.0.34) 56(84) bytes of data.
64 bytes from 172.20.0.34: icmp_seq=1 ttl=62 time=1.54 ms
--- 172.20.0.34 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.536/1.536/1.536/0.000 ms