How to set up shared internet access for dual NICs in Linux

Source: Internet
Author: User
I. network extension structure: Server: two network card settings: eth1: 192.168.99.26 mask: 255.255.255.0 Gateway: 192.168.99.133 # connect with Inte. Net to connect the vro to the Internet. Eth0: 192.168.0.1 mask: 255.255.255.0 # Subnet segment of the client associated with the LAN switch: 192.16

I. network extension structure:

Server: set two Nics:

Eth1: 192.168.99.26 mask: 255.255.255.0 Gateway: 192.168.99.htm # connect with Inte. Net to connect the vro to the Internet.

Eth0: 192.168.0.1 mask: 255.255.255.0 # associated with a LAN switch

Client Subnet: 192.168.0.0/24

II. server settings: (you can choose either of the two methods)

2.1 use NAT

Run the following commands on the server:

Echo "1">/proc/sys. Net/ipv4/ip_forward # enable IP forwarding. 1 indicates forwarding. 0 indicates no forwarding.

The above command can also be implemented by modifying/etc/sysctl. conf and adding a line above and below in the file:

Net. ipv4.ip _ forward = 1

Other commands are:

  Iptables-F

Iptables-P INPUT ACCEPT

Iptables-P FORWARD ACCEPT

Iptables-t nat-a postrouting-o eth1-j MASQUERADE # enable NAT

2.2 Net Bridge:

Echo "1">/proc/sys. Net/ipv4/ip_forward

Ifconfig eth0 0.0.0.0 up

Ifconfig eth1 0.0.0.0 up

Brctl addbr br0 # Add a bridge

Brctl addif br0 eth0

Brctl addif br0 eth1 # Add eth0 eth1 to the bridge

Ifconfig br0 192.168.0.1.Netmask 255.255.255.0 broadcast192.168.0.255 up # assign an IP address to the bridge. if you do not use NAT and do not need to remotely access the bridge, you can set an IP address but must enable the bridge (ifconfig br0up)

Route add default gw 192.168.99.htm # if the bridge does not need to access other machines, you can not add a gateway.

III. client settings:

Eth1: 192.168.0.10 mask: 255.255.255.0 Gateway: 192.168.0.1

IV. iptables command reference:

Iptables command format

Iptables [-t nat] CMD [chain] [rule-matcher] [-j target]

-T nat: indicates the operation of the nat table.

CMD: Operation Command

Chain: The chain name.

Rule-matcher: rule matcher

Target: The target action.

Iptables-t nat-F # clear the rules in the original nat table

Iptables-F # clear the rules in the original filter

Iptables-p forward accept # IP forwarding permitted by default

5. feelings about configuration

According to the NAT method, the configuration is completed quickly and the network can be accessed smoothly. For users who have no special requirements on network configuration, you can use the NAT method, which is simple and practical.

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.