One Network Card connects two network segments (public network and virtual network)

Source: Internet
Author: User
My personal data is stored in MySQL in the virtual machine. It is maintained using PHP.
Therefore, to control the BSD system in the virtual machine or access the PHP webpage, you must establish a network connection with the virtual machine.

This is not a problem, but it is also difficult to connect to the Internet. because the Internet is sometimes not fixed, sometimes it can be obtained through DHCP, and sometimes it can only be set statically. sometimes there is no network.
Method.
Once the Internet is changed, the network configuration of the virtual machine system needs to be changed. Once the BSD configuration is changed, the SSH connection needs to be changed. This is troublesome.

Later, we can see from the Internet that we can add a virtual Nic.
You can select Add hardware from the control panel, and then select Add new hardware from the installed hardware ", next, select "Install the hardware I manually selected from the list (advanced)". Next, click
Select "network adapter", select "Microsoft" on the left of the next step, and select "Microsoft loopback" on the right
Adapter ". After the installation is complete, an extra NIC will be displayed in the hardware list, but this Nic does not exist.

At the same time, there will be an extra connection in the network connection. You can name it "virtual link ".
I changed its IP address to "192.1.1.1". Mask "255.255.255.0" Gateway "192.1.1.1"

In this way, you can use virtual
Link to connect to the virtual machine, and the normal Nic to connect to the Internet. The IP address of the virtual machine is relatively fixed. You do not need to change it.
However, when you want to access the Internet, it is very likely that it is based on virtual
Link.

I was troubled by this problem before, But today a colleague suggested that the route command could be used to solve it.

Just run the following two commands:
Route Delete 0.0.0.0
Route add 0.0.0.0 mask 0.0.0.0 10.90.65.23

In this way, the system will understand that all the IP addresses except the specified 192.1.1.1 go from the 10 CIDR block ......
Because 192.1.1.0 has been automatically "route Add" to the system route table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.