This article mainly introduces the related information of linux Shared Internet Settings Examples. Friends in need can refer to
Linux Shared Internet Settings
1. Turn on kernel ip forwarding
vi /etc/sysctl.conf net.ipv4.ip_forward = 1
Execute sysctrl -p to take effect
2. If the firewall is not enabled on the host, then set iptables as follows
[root@Web-Lnmp02 ~]# iptables -F [root@Web-Lnmp02 ~]# iptables -P INPUT ACCEPT [root@Web-Lnmp02 ~]# iptables -P FORWARD ACCEPT [root@Web-Lnmp02 ~]# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 或者 iptables -t nat -A POSTROUTING -s ip -o eth0 -j MASQUERADE //指定某ip或ip段可以转发 iptables -t nat -A POSTROUTING -s 192.168.0.170 -o enp1s0 -j MASQUERADE iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o enp1s0 -j MASQUERADE [root@Web-Lnmp02 ~]# /etc/init.d/iptables save [root@Web-Lnmp02 ~]# /etc/init.d/iptables restart 说明: iptables -F #清除原有的filter有中的规则 iptables -t nat -F #清除原有的nat表中的规则 iptables -P FORWARD ACCEPT #缺省允许IP转发
If the firewall is enabled on the host, you need to add the following two sentences:
Code:
iptables -A FORWARD -s 192.168.122.0/24 -o eth0 -j ACCEPT iptables -A FORWARD -d 192.168.122.0/24 -m state --state ESTABLISHED,RELATED -i eth0 -j ACCEPT
The above is the detailed content of Example analysis of Linux shared Internet settings. For more information, please follow other related articles on the PHP Chinese website!