Configure Linux in the virtual machine as a router

Source: Internet
Author: User

There are two physical NICs on the PC. The physical network card corresponding to eth0 in the virtual machine is connected to the TP-link router (192.168.1.1), and the physical network card corresponding to eth1 is connected to a local database (192.168.2.124 ).

(1) assign an address to this eth0:
# Ifconfig eth0 192.168.1.125 netmask 255.255.255.0
(2) Add a static route:
# Route add-net 192.168.1.0 netmask 255.255.255.255.0 Dev eth0

(3) Allocate an address to eth1:
# Route add-net 192.168.2.1 netmask 255.255.255.0
(4) add another static route:
# Route add-net 192.168.2.0 netmask 255.255.255.0 Dev eth1
(5) Add a default route for the system:

# Route add default GW 192.168.1.1 (TP-link address)

(6) Add the system's IP forwarding function:

# Echo 1>/proc/sys/NET/IPv4/ip_forward

At this point, the virtual machine Linux has basic vro functions. However, the problem is that the gateway can be pinged (eth1 of the Virtual Machine Linux), but the TP-link router cannot be pinged. Later, I found that the problem lies in my TP-link router: There is no static route for packet return, and there is no route for packets to be pinged out.

Solution: configure the TP-link router and set a static route (Destination: 192.168.2.0 GW: 192.168.1.125 ).

At this point, the vro can be accessed through the Virtual Machine Linux (you also need to set the LAN port of TP-link and set the subnet mask to 255.255.0.0; otherwise, you can only ping the vroping, but does not have the permission to log on to the vro ).

 

However, you cannot access the Internet because the network segment is 192.168.2.0, And the NAT rule of TP-link is only for the network segment 192.168.1.0. Therefore, we are going to re-configure the Virtual Machine Linux to enable its NAT Function.

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.