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

N ways to align the last row of lists in CSS flex layout to the left (summary)

I would like to quote an article by Zhang Xinxu a...

One question to understand multiple parameters of sort command in Linux

The sort command is very commonly used, but it al...

Two implementation solutions for vuex data persistence

Table of contents Business requirements: Solution...

Steps to use autoconf to generate Makefile and compile the project

Preface Under Linux, compilation and linking requ...

Practical method of deleting associated tables in MySQL

In the MySQL database, after tables are associate...

MySQL column to row conversion tips (share)

Preface: Because many business tables use design ...

Detailed analysis of several situations in which MySQL indexes fail

1. Leading fuzzy query cannot use index (like ...

In-depth explanation of the global status of WeChat applet

Preface In WeChat applet, you can use globalData ...

Docker online and offline installation and common command operations

1. Test environment name Version centos 7.6 docke...

How to avoid duplication of data when inserting in MySql batch

Table of contents Preface 1. insert ignore into 2...

Web design must also first have a comprehensive image positioning of the website

⑴ Content determines form. First enrich the conten...

10 very good CSS skills collection and sharing

Here, clever use of CSS techniques allows you to g...

Linux common basic commands and usage

This article uses examples to illustrate common b...

The principle and implementation of two-way binding in Vue2.x

Table of contents 1. Implementation process 2. Di...