Easily build a NAT server under Linux

Source: Internet
Author: User


What is NAT?


NAT (Network address translation) is a transition solution that can be used to reduce the need for a global legal IP address. In a nutshell, Nat is the use of internal addresses in an internal private network, and when internal nodes are connected to an external network, the internal address is converted to a global address at the edge router or firewall, making it possible to transfer data on an external public network (the Internet) using an array of legitimate IP addresses.

Where the extranet and intranet are relatively speaking, the following is assumed to be able to access the Internet network for the outside.




First, the basic environment


1) Experimental environment

    • One Linux server (with two net cards configured)

    • One PC (one card, IP 10.0.0.10)


2) network environment

    • Linux server as a NAT server, responsible for the network traffic to the external network, so need two network cards, configure two networks, hereinafter referred to as the extranet and intranet .

    • The network in the intranet can be set as a static address or a DHCP server can be configured.

    • Linux in ens160 for the external network card, IP is 172.18.72.183

    • Linux in ens192 for intranet network card, IP is 10.0.0.1





Second, firewall configuration


1) Let the data sent to the intranet network card pass all

Iptables-a forward-i ens192-j ACCEPT

^ Note: ' ens192 ' for intranet network card



2) Modify Data header information

Iptables-t nat-a postrouting-s 10.0.0.0/24-o ens160-j Masquerade

^ Note: ' 10.0.0.0/24 ' for the intranet segment, ' ens160 ' for the External network network card

Or

Iptables-t nat-a postrouting-j SNAT--to-source 172.18.72.183

^ Note: ' 172.18.72.183 ' for the external network card address





Third, turn on the Linux routing function


echo 1 >/proc/sys/net/ipv4/ip_forward # Open the routing feature Cat/proc/sys/net/ipv4/ip_forward # to see if routing is enabled, result is 1, on behalf of enabled, 0 Representative not enabled





Iv. Checking Connectivity

Set the static IP (10.0.0.10/24) on Windows, and the gateway is set to 10.0.0.1.

Ping www.baidu.com

Detection passed.








Easily build a NAT server under Linux

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.