Configure Ubuntu as a gateway for dual-nic

Source: Internet
Author: User
Hardware requirement: a PC with Ubuntu installed. Two NICs. The configuration is simple. Suppose there are two network segments: 0 and 1, 192.168.0.0 and 192.168.1.0, respectively. Eth0 is connected to network No. 0, and eth1 is connected to network No. 1. Now, the two NICs, eth0 and eth1, are allocated IP addresses of different network segments: # sudoifconfigeth0192.168.0.1netmask1_255.255.0up # su hardware requirements:
A pc with Ubuntu installed.
Two NICs.

The configuration is simple. Suppose there are two network segments: 0 and 1, 192.168.0.0 and 192.168.1.0, respectively. Eth0 is connected to network No. 0, and eth1 is connected to network No. 1. Now, the two NICs, eth0 and eth1, are assigned IP addresses of different network segments:

# Sudo ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up
# Sudo ifconfig eth1 192.168.1.1 netmask 255.255.255.0 up

The configuration is better from the interface management, so you do not need to execute the above command every time.

Enable iptables forwarding rules:

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

The default ip_forward value is zero. Forwarding is not allowed. You can forward the IP address to 1. If you want to allow forwarding at startup, add the preceding command to the startup script rc. local.

Configure the computers in network No. 0 and network No. 1. The gateways are 192.168.0.0 and 192.168.1.0 respectively. In this way, the computer in the network segment 0 can access the computer in the Network Segment 1, and the computer in the Network Segment 1 can also access the computer in the network segment 0.

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.