Detailed graphic explanation of setting up routing and virtual machine networking in Linux

Detailed graphic explanation of setting up routing and virtual machine networking in Linux

What is routing?

Routing refers to the activity of transmitting data packets from the source station to the destination station through interconnected networks. During the routing process, data packets usually pass through one or more transit nodes (i.e. routers). These routers along the way will forward the data packets along the best path to the destination.

What is a Router?

A router is used to connect different networks and is the hub that connects networks to each other. The main job of a router is to find an optimal transmission path for each data packet passing through the router and transmit the data to the destination efficiently.

What is a Gateway?

Gateway (GATEWAY) realizes network interconnection above the network layer.

Experiment 1: Simulate a router to allow two hosts that are not in the same network segment to ping each other

First, determine which virtual machine will be set up as a router and add two network cards to this virtual machine. I set the server as a router.
In the real machine, switch to the super user root and enter the command: virt-manager

Double-click server and click the "light bulb"

Select Add Hardware ——>network——>Device model: Select virtio——>Finish

Then set two IP addresses in different network segments. I set them to 172.25.254.224 and 1.1.1.224.


Set the IP address of another virtual machine to 1.1.1.124


Ping the virtual machine set as a router and the host in the same network segment to see if they can ping through.


On the router side:

sysctl -a | grep ip_forward ##Check whether kernel routing is enabled, 1 is enabled, 0 is disabled. If communication is not possible, it means it is disabled. 


If it is not enabled, write in the /etc/sysctl.conf file:


The purpose of sysctl -p is to make it take effect:


With the firewall turned on, enable permanent firewall camouflage:


The gateway is not set on the client at this time. We set the gateway (1.1.1.224) in /etc/sysconfig/network and restart the network.



Finally, I tried to ping the 172.25.254 network segment on the client and found that it was successful.


Can also log in to the real machine


over!

Experiment 2: Virtual Machine Networking

The main idea is to simulate the real machine as a router. At this time, the real machine is connected to the Internet, and you can ping Baidu to view the IP address of the real machine.

sysctl -a | grep ip_forward ##Check whether the kernel routing function is enabled systemctl start firewalld ##Open the firewall firewalld-cmd --add-masquerade ##Open the firewall masquerade 

On the client, set the IP address to the same network segment as the real machine. I set it to 172.25.254.124


Set the gateway to the real machine ip172.25.254.1 and restart


Ping Baidu's IP address 183.232.231.172


You can access Baidu by entering the IP address!


over!
Note: There are two ways to modify the gateway:

vim /etc/sysconfig/network-scripts/ifcfg-eth0 ##Set the gateway of a separate network card vim /etc/sysconfig/network ##Set the global gateway

Setting the global gateway will take effect on all network cards, and all data packets will be sent to this gateway when accessing the external network. After completing both settings, you need to restart the network.

The above is a detailed introduction to setting up routing and virtual machine networking in Linux. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Solution to the problem that the virtual machine cannot access the Internet when installing Linux system
  • [Linux] Detailed explanation on how to configure static IP in VMware virtual machine
  • Steps to configure and install KVM virtual machine under Linux
  • MySQL 5.7 installation and configuration tutorial under Linux virtual machine
  • Linux Learning CentOS (I) ---- Install CentOS 7 in VMware Virtual Machine (Graphic Tutorial)
  • VMware installs Linux system on virtual machine
  • Teach you how to configure a Linux virtual machine step by step
  • Folder sharing and two-way copying between Virtualbox host and virtual machine (Windows<->Windows, Windows<->Linux)
  • How to modify the root or other user password when you forget the password in the virtual machine Linux system
  • How to install Linux in Windows 10 using a virtual machine

<<:  Vue implements picture verification code when logging in

>>:  mysql5.7.14 decompression version installation and configuration method graphic tutorial (win10)

Recommend

A brief discussion on Mysql specified order sorting query

Recently, I have been working on a large-screen d...

Instance method for mysql string concatenation and setting null value

#String concatenation concat(s1,s2); concatenate ...

Detailed explanation of the principle and function of JavaScript closure

Table of contents Introduction Uses of closures C...

Introduction to Jenkins and how to deploy Jenkins with Docker

1. Related concepts 1.1 Jenkins Concepts: Jenkins...

How to build sonarqube using docker

Table of contents 1. Install Docker 2. Install so...

React Diff Principle In-depth Analysis

Table of contents Diffing Algorithm Layer-by-laye...

Three ways to communicate between Docker containers

We all know that Docker containers are isolated f...

Steps to package and deploy the Vue project to the Apache server

In the development environment, the vue project i...

Detailed tutorial for installing influxdb in docker (performance test)

1. Prerequisites 1. The project has been deployed...

javascript implements web version of pinball game

The web pinball game implemented using javeScript...

Detailed explanation of CSS elastic box flex-grow, flex-shrink, flex-basis

The functions of the three attributes flex-grow, ...

Detailed installation and configuration of MySql on Mac

1. Download and install Download the community ed...