linux Shared Network setup example details
- 2020-06-07 05:55:12
- OfStack
linux shares web surfing Settings
1. Open kernel ip forwarding
vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
Execute ES9en-p into effect
2. If firewall is not enabled on the host, 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
or
iptables -t nat -A POSTROUTING -s ip -o eth0 -j MASQUERADE
// To specify a ip or ip Segments can be forwarded
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
Description:
iptables -F # Remove the original filter Rules in place
iptables -t nat -F # Remove the original nat Rules in a table
iptables -P FORWARD ACCEPT # The default allows IP forwarding
If firewall is enabled on the host, 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
Thank you for reading, I hope to help you, thank you for your support to this site!