Dual-Nic host routing configuration in Linux

Source: Internet
Author: User
Article title: Dual-Nic host routing configuration in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

  I. environment:

Three directly connected computer hosts

PC1 <------> PC2 <------> PC3

Two NICs eth0 and eth1 are available on PC2, which are connected to PC3 and PC1 respectively.

------ Network cable

  II. requirements:

Configure PC2 as vro mode to forward packets between PC1 and PC3

  III. method:

After connecting the three hosts to the Internet using a crossover line as required by the environment, assign network segments for the three hosts and configure IP addresses.

CIDR blocks and IP addresses are allocated as follows:

IP gateway is allocated to the CIDR block of the host name.

PC1: 192.168.2.0/24 192.168.2.2/24 192.168.2.1

PC2: 192.168.2.0/24 192.168.2.1/24 'configuration of the NIC connected to PC1' eth1

192.168.1.0/24 192.168.1.1/24 'configuration of the NIC connected to PC3' eth0

PC3: 192.168.1.0/24 192.168.1.2/24 192.168.1.1

Configure the host IP addresses as shown in the preceding table. Note that to enable PC2 to have the packet forwarding function

Check whether the value in/proc/sys/net/ipv4/ip_forward is 1

Command:

# More/proc/sys/net/ipv4/ip_forward

If the value is not 1 but 0, enter the following command:

# Echo '1'>/proc/sys/net/ipv4/ip_forward

Enable IP forwarding

Other configurations in PC2:

To add a route for PC2, run the following command:

# Route add-net 192.168.1.0 netmask 255.255.255.0 dev eth0

# Route add-net 192.168.2.0 netmask 255.255.255.0 dev eth1

  IV. verification:

PC1:

Ping Gateway

# Ping 192.168.2.1

# Ping 192.168.1.1

Ping PC3:

# Ping 192.168.1.2

PC3:

Ping Gateway

# Ping 192.168.1.1

# Ping 192.168.2.1

Pint PC1

# Ping 192.168.2.2

  V. Bug debugging:

The cause of the error mainly lies in PC2.

1. check whether PC2 allows IP packet forwarding (/proc/sys/net/ipv4/ip_forward value is 1)

2. check whether route settings are correct (# press enter to view route information)

This article is from 51CTO. COM Technical Blog

Related Article

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.