1. Network architecture
Experimental results, through the forwarding function of machine B, the packets of machine A are forwarded to machine C. For
this experiment, three machines are prepared to configure the following network:
machine A ip: 192.168.56.104
machine C ip: 10.1.0.10
machine B two network cards, The respective IPs are 192.168.56.106 and 10.1.0.11
as shown in the picture
As shown below
2. Virtual machine network card settings
Set up two host-only LANs
The network settings of machine A are as follows:
The network settings of machine B are as follows:
two network cards, connected to two LANs respectively
The network card configuration of machine C is as follows:
3. Virtual machine network settings
A machine
B machine
When connecting to the LAN, there are actually two network cards
enp0s8 and the network card settings are as follows:
The enp0s9 network card settings are as follows:
C machine
After configuring the network of the three machines,
try A(192.168.56.104) ping B(192.168.56.106)
[root@localhost network-scripts]# ping 192.168.56.106
PING 192.168.56.106 (192.168.56.106) 56(84) bytes of data.
64 bytes from 192.168.56.106: icmp_seq=1 ttl=64 time=1.12 ms
64 bytes from 192.168.56.106: icmp_seq=2 ttl=64 time=0.861 ms
C(10.1.0.10) ping B(10.1.0.11)
[root@localhost ~]# ping 10.1.0.11
PING 10.1.0.11 (10.1.0.11) 56(84) bytes of data.
64 bytes from 10.1.0.11: icmp_seq=1 ttl=64 time=0.933 ms
64 bytes from 10.1.0.11: icmp_seq=2 ttl=64 time=0.899 ms
It can be found that A and B, C and B are all interoperable.
However, A and C cannot interoperate at this time
. Therefore, the following steps are required to enable the forwarding function of machine B.
4. Enable the forwarding function as Router B
/etc/sysctl.conf sets the following configuration
[root@localhost ~]# cat /etc/sysctl.conf
net.ipv4.ip_forward=1
restart machine B
5. Routing settings for machine A and machine C
By manually adding routing rules, the packets from A and machine C (10.1.0.10) are processed through gateway B. Note that the route setting of
machine A (192.168.56.104)
is only valid when it is currently running. There will be no such route after restarting. Rules
[root@localhost network-scripts]# route add -net 10.1.0.0/16 gw 192.168.56.106
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.56.100 0.0.0.0 UG 100 0 0 enp0s8
10.1.0.0 192.168.56.106 255.255.0.0 UG 0 0 0 enp0s8
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.56.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s8
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
Similarly, if machine C (10.1.0.10) wants to connect to machine A (192.168.56.104), it must set up a route.
[root@localhost network-scripts]# route add -net 192.168.56.0/24 gw 10.1.0.11
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.1.0.2 0.0.0.0 UG 100 0 0 enp0s8
10.1.0.0 0.0.0.0 255.255.0.0 U 100 0 0 enp0s8
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.56.0 10.1.0.11 255.255.255.0 UG 0 0 0 enp0s8
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
Machine A (192.168.56.104) pings Machine C (10.1.0.10)
[root@localhost network-scripts]# ping 10.1.0.10
PING 10.1.0.10 (10.1.0.10) 56(84) bytes of data.
64 bytes from 10.1.0.10: icmp_seq=1 ttl=63 time=1.51 ms
64 bytes from 10.1.0.10: icmp_seq=2 ttl=63 time=1.61 ms
Machine C (10.1.0.10) pings Machine A (192.168.56.104)
[root@localhost ~]# ping 192.168.56.104
PING 192.168.56.104 (192.168.56.104) 56(84) bytes of data.
64 bytes from 192.168.56.104: icmp_seq=1 ttl=63 time=1.62 ms
64 bytes from 192.168.56.104: icmp_seq=2 ttl=63 time=1.75 ms
Now, machines A and C can communicate with each other.