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
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