building simulation network environment with multiple virtual machines

Posted by trammel at 2020-03-02

Published on September 24, 2016


Using multiple virtual machines to simulate a small network environment on a computer entity. We use virtual machine software to simulate a network environment for experiments. The main function of this kind of software is to use software to simulate a complete computer system with complete hardware system functions and running in an isolated environment. In this way, we can simulate one or more virtual computers on a physical computer (host machine). These virtual machines can work like real computers, and we can install new operating systems and application software on them. By connecting virtual machines with virtual connection devices in the virtual machine software, we can build the network environment for the experiment.

Network topology

Next, the network topology and topology configuration information table to be constructed are given:

In this experiment, we use five virtual machines, namely, ut-571 ~ ut-575. There are two routers in the network topology, which are simulated by ut-571 and ut-574 respectively. The two routers are connected through the network. Here, we use the virtual network vmnet4 to simulate. The two routers respectively have three hosts, namely PC0, PC1 and PC2. The three hosts are simulated by ut-572, ut-573 and ut-575.

It can be seen from the network topology that PC0, PC1 and route0 are in the same network segment, and the network segment is, while PC2 and route1 are in the same network segment, Then in order to realize the connection of the two network segments, we set the two routers in the same network segment, that is, we need three virtual networks to realize the connection of five machines. Our goal is to configure the network card, IP, gateway and router forwarding table of each machine, so that each machine on this virtual network can communicate with each other. The square figure in the figure represents the switch of LAN. Finally, we test whether the machines are connected by Ping each other.


Configure virtual machine

We need to configure at least one network card for each virtual machine to realize network interconnection, and we need to configure two network cards for the virtual machines ut-571 and ut-574, because they are routers and belong to two network segments. The process of configuring the virtual machine is as follows: select the editing option before the virtual machine is powered on

If there is no network card before, click Add to add the network card, and then next:

Add the configuration of the network card, select custom: specific virtual network, and configure the machine to the corresponding virtual network, such as PC0 and PC1 to vmnet2, PC2 to vmnet3. Add two network cards to the virtual machine configuration of two routers and set them to two network segments.

Set up each terminal PC

IP address is the basis of computer network communication, each networked computer has at least one IP address. In daily use, we can usually obtain IP automatically, which is due to the role of DHCP protocol. This time we need to manually assign the IP address to the configured virtual network.

Open the terminal of each machine (PC0, PC1, PC2), input

You will see the following output: the output shows that the network card of the machine has not been configured with an IPv4 address. We will manually configure a fixed IP address.

In order to prevent the interference of DHCP protocol and network manager and change the IP address we set, we input

Disable the network manager service, so that the IP we set will not be changed by the system.

Network manager is a service of network management in Linux system. Network manager is a free software project, which provides a simple way for applications to communicate with each other. It is developed as a part of freedesktoporg project Background service for reporting, and a client program that allows users to manage network connections. Advantages of network manager: simplify the work of network connection, and make the desktop itself and other applications aware of the network.

To learn about network manager, please refer to the materials.

Then set the IP address of each PC. because PC0 and PC1 are in the same network segment, we set their IP address to (ut-572) and (ut-573) respectively, leaving for router route0 (ut-571). There are the following commands to set the IP address: (take as an example)

Then you can use the ifconfig - a command to view the IP status as shown in the figure.

ifconfig -a

Then set the default gateway as the IP address of eth0 of router route0 of the network segment (

Such a terminal PC has been configured with its own IP address and default gateway.

As we all know, from one room to another, we must go through a door. Similarly, sending information from one network to another must also pass through a "gateway", which is the gateway. As the name implies, gateway is the "gateway" that connects one network to another, that is, the network gateway (– Baidu Encyclopedia). At this time, the network gateway of PC0 is the eth0 of its router route0.

Other terminal PC configurations are similar.

Set up router

IP address setting is the same as above,

Eth0 is a network card for PC0 and PC1, while eth1 is a network card for another network segment ( / 24). After all, the router is a router. It also needs a set of routing and forwarding tables to play the role of routing. So next, set the route table of route0 (ut-571):

Among them, the rule added by the command IP route add via tells that the packets of the destination IP in the ( ~ network segment are forwarded by the device with IP address (route 0), that is, the next IP hop is is a common mask representation in Linux. 24 indicates that the mask word length is 24, i.e. the mask is is the network number, and 1 ~ 254 is the host number in the network. There are also other forms of commands for adding routing rules. The second rule indicates that the next hop IP that tells the destination IP to go through in network segment is (that is, the other end of vmnet4, that is, eth1 of route1, because route1 is the router of network segment). The last rule indicates that the next hop IP that tells the destination IP to go through in network segment is, that is, eth1 of route0

Finally, we need to make the virtual route allow forwarding, and set the IP forward flag of the virtual machine u-571 to 1. Here we need to set the IP forward value of the file under the directory / proc / sys / net / IPv4 / to 1. Use the command echo, as follows:

ip_forward /proc/sys/net/ipv4/ ip_forward

In this way, our router route0 is also set up. In the same steps, we can set up route1 soon. Some steps are as follows:


Finally, we can ping the IP of other virtual machines on different virtual machines, and test whether the interconnection is realized.

PC0 ping PC1:

PC0 Ping route1 eth1 and PC2:

PC2 ping PC0, PC1:

Wait a moment, it's easy to see that under the correct setting, you can ping to connect the two LANs.

Wireshark grabs the bag

Enter in terminal

Start Wireshark, select the device to be monitored through the blue box below, such as eth0, and then start Ping in the terminal to observe the packet traffic:

The results are as follows: PC0 Ping the packet flow of PC1:

Packet flow of PC0 Ping PC2:

Click to open a package. You can see:

The protocol box displays the layer protocols of the selected packet: physical layer frame, Ethernet frame and its header, IP protocol datagram and its header, and Internet control message protocol. The original box shows each byte of the data contained in the group. You can see the original data from it. On the left is the hexadecimal data, and on the right is the ASCII code. If you select an entry in the protocol box, the corresponding original data will be marked in the original box, otherwise, the same will be true if you select it in the original box.


In this way, the virtual network construction is successful. Generally speaking, there is a great distance between knowing and being able to do the computer network. Some basic network theoretical knowledge is really strange to use, but it's still a dish after all~

------------------------------------------------------------------------------------------------------------------------------I want a small amount of sponsorship to help the author write better articles!