Basic Idea: Enable IP Forwarding and set iptables rules.
2. 1. Enable IP Forwarding
Two methods,
Temporary: echo "1">/proc/sys/net/ipv4/ip_forward
Fixed: Modify/etc/sysctl. conf to cancel the comments of this line:
Net. ipv4.ip _ forward = 1
Then make it take effect immediately
Sysctl-p
2. Set iptables rules
Temporary: iptables-t nat-a postrouting-j MASQUERADE
Fixed:
Or write the preceding code to a STARTUP script (such as/etc/rc. local ). There is another version:
Iptables-F
Iptables-P INPUT ACCEPT
Iptables-P FORWARD ACCEPT
Iptables-t nat-a postrouting-s 192.168.0.0/24-o eth1-jMASQUERADE
It is said that "the first sentence is to clear all previous iptables rules, the second sentence is to allow receiving and sending data packets, and the fourth sentence is to NAT on the eth1 network port", just a few more nonsense words than above, and finally specify what Nic parameters, have not tried. The usage of iptables is still easy to learn.
3. Client settings
Set the default gateway to 192.168.0.1. For the IP address, set it to 192.168.0.
From patriot's blog