centos6-centos7 firewall (iptables-firewalld) set up port forwarding nat

 

 

background:

8080 forwarded to the other host port of the machine, the host IP: 192.168.1.162, target host IP and port 192.168.1.163:80, as follows:

centos6 the system iptables environment:

   -A PREROUTING -p -t NAT iptables tcp -m tcp --dport 8080 -j DNAT --to Where do you want? 192.168 . 1.163 : 80 

  iptables -t NAT -A POSTROUTING -p tcp -m tcp --dport 80 -j SNAT Source---to 192.168 . 1.162 : 8080 

  echo 1 > / proc / SYS / NET / ipv4 / ip_forward ### while turning the Linux kernel forwarding.

 

centos7 the system firewalld environment:

Camouflage open the firewall: Firewall-cmd --add-Masquerade --permanent     // After opening in order to forward the port 

Add forwarding rule: Firewall -cmd --add-Forward-Port = Port = 8080 : proto = tcp: toport = 80 : toaddr = 192.168 . 1.163 - Permanent 

(PS: this rule forwards port 8080 to the machine 192. 168.1 80 .163 port, configuration complete - reload takes effect) 

If you have configured the above rules still not entered into force, to check whether the firewall open 80 port, if port 80 is open, not forward, probably due to sysctl.conf kernel parameter file is not configured ip forwarding, the specific configuration is as follows: 

vi / etc / sysctl.conf 

add text content: net.ipv4. ip_forward = 1 

after saving the file, enter the command sysctl - the p-take effect

 

Guess you like

Origin www.cnblogs.com/Crazy-Liu/p/11344505.html