Configure Linux as a gateway

Source: Internet
Author: User
Reprinted:

Http://blog.csdn.net/zhangyang0402/archive/2010/06/25/5695050.aspx

 I. Network Topology

 

 

2. Configure the network

 

1.Network Configuration of A, gw1, gw2, and B

 

A:

Eth0:

Ipaddr: 192.168.1.2

Netmask: 255.255.255.0

Gateway: 192.168.1.1

 

Gw1:

Eth0:

Ipaddr: 172.16.113.173

Netmask: 255.255.255.0

Gateway: 172.16.113.9

 

Eth1:

Ipaddr: 192.168.1.1

Netmask: 255.255.255.0

 

B:

Eth0:

Ipaddr: 192.168.0.2

Netmask: 255.255.255.0

Gateway: 192.168.0.1

Gw2:

Eth0:

Ipaddr: 172.16.113.163

Netmask: 255.255.255.0

Gateway: 172.16.113.9

 

Eth1:

Ipaddr: 192.168.0.1

Netmask: 255.255.255.0

 

 

2.Gw1 settings

(1)Enable route forwarding

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

Or

# Vim/etc/sysctl. conf

Net. ipv4.ip _ forward = 0 --> net. ipv4.ip _ forward = 1

 

(2)Route entry added to CIDR Block 192.168.0.0/24

# Route add-net 192.168.0.0 netmask 255.255.255.0 GW 172.16.113.163

 

 

3.Gw2 settings

(1)Enable route forwarding

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

Or

# Vim/etc/sysctl. conf

Net. ipv4.ip _ forward = 0 --> net. ipv4.ip _ forward = 1

 

(2)Route entry added to 192.168.1.0/24 CIDR Block

# Route add-net 192.168.1.0 netmask 255.255.255.0 GW 172.16.113.173

 

Iii. Test Gateway

If a and B can ping each other, the two gateways are configured successfully.

 I. Network Topology

 

 

2. Configure the network

 

1.Network Configuration of A, gw1, gw2, and B

 

A:

Eth0:

Ipaddr: 192.168.1.2

Netmask: 255.255.255.0

Gateway: 192.168.1.1

 

Gw1:

Eth0:

Ipaddr: 172.16.113.173

Netmask: 255.255.255.0

Gateway: 172.16.113.9

 

Eth1:

Ipaddr: 192.168.1.1

Netmask: 255.255.255.0

 

B:

Eth0:

Ipaddr: 192.168.0.2

Netmask: 255.255.255.0

Gateway: 192.168.0.1

Gw2:

Eth0:

Ipaddr: 172.16.113.163

Netmask: 255.255.255.0

Gateway: 172.16.113.9

 

Eth1:

Ipaddr: 192.168.0.1

Netmask: 255.255.255.0

 

 

2.Gw1 settings

(1)Enable route forwarding

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

Or

# Vim/etc/sysctl. conf

Net. ipv4.ip _ forward = 0 --> net. ipv4.ip _ forward = 1

 

(2)Route entry added to CIDR Block 192.168.0.0/24

# Route add-net 192.168.0.0 netmask 255.255.255.0 GW 172.16.113.163

 

 

3.Gw2 settings

(1)Enable route forwarding

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

Or

# Vim/etc/sysctl. conf

Net. ipv4.ip _ forward = 0 --> net. ipv4.ip _ forward = 1

 

(2)Route entry added to 192.168.1.0/24 CIDR Block

# Route add-net 192.168.1.0 netmask 255.255.255.0 GW 172.16.113.173

 

Iii. Test Gateway

If a and B can ping each other, the two gateways are configured successfully.

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.