Enable centos Intranet machine to access the Internet
Environment: one machine with Internet and Intranet, and the other machine only has Intranet, which by default cannot access the Internet. Both machines are centos Systems
The Internet ip address of the machine with Internet access is 123.221.20.11, and the Intranet ip address is 192.168.15.100.
The Intranet ip address of the Intranet machine is 192.168.15.101.
The setting method is simple:
1. Set iptables rules on machines with Internet access:
Iptables-t nat-a postrouting-s 192.168.15.101-j SNAT -- to 123.221.20.11
// If You Want To Enable Internet access for all machines on the Intranet, replace-s 192.168.15.101
-S 192.168.15.0/255.255.255.0
2. Enable forwarding on a machine with Internet bandwidth
First, check whether it is enabled.
Sysctl-a | grep 'Net. ipv4.ip _ forward'
If the value is 1, it indicates that it has been enabled; otherwise, you need to modify the configuration file/etc/sysctl. conf.
Open the configuration file, find the parameter, and change it
Net. ipv4.ip _ forward = 1
Then run sysctl-p
3. on the Intranet machine, set its gateway to 192.168.15.100
Vim/etc/sysconfig/network-scripts/ifcfg-eth0
Add
GATEWAY = 192.168.15.100
Restart the network service. Service network restart
4. test whether the Intranet machine can access the Internet.