How to Use iptables to implement port ing in Linux (Ubuntu) first, you must enable the data forwarding function in linux. The specific steps are as follows: 1vi/etc/sysctl. conf2 sets net. ipv4.ip _ forward = 0 is changed to net. ipv4.ip _ forward = 1 and cancel the prefix & ldquo; # & rdquo; 3sysctl-p (this command takes effect for the data forwarding function ).
How to Use iptables for port ing in Linux (Ubuntu)
First, you must enable the data forwarding function in linux. The steps are as follows:
1 vi/etc/sysctl. conf
2. Change net. ipv4.ip _ forward = 0 to net. ipv4.ip _ forward = 1, and cancel the prewatch "#".
3 sysctl-p (this command takes effect for the data forwarding function)
Now you can change iptables to implement nat ing:
For example, if you want to convert port 80 of the local IP address (192.168.75.5) from the Internet to port 8000 of 192.168.75.3, you can use the following command:
(1) iptables-t nat-a prerouting-d 192.168.75.5-p tcp -- dport 80-j DNAT -- to-destination 192.168.75.3: 8000
(2) iptables-t nat-a postrouting-d 192.168.75.3-p tcp -- dport 8000-j SNAT 192.168.75.5 (an error occurred when I executed this sentence !! This part is not used)
The statement I run is only: sudo iptables-t nat-A PREROUTING-d *. *. *. *-p tcp -- dport 80-j DNAT -- to-destination *. *. *. *: 9000
Because I want to forward port 80 to port 9000, because port 80 is out of an electronic envelope and cannot be accessed from outside, port 9000 is used. In this way, you can directly access the WEB service provided by port 9000 through the domain name.
Run iptables-t nat -- list to check nat list information:
Shows the result.
Delete Nat list information:
Iptables-t nat-d prerouting 1 // The serial number starts from 1, followed by this + 1.
For more iptables tutorials, see the following content::
CentOS 7.0 disable default firewall enable iptables firewall http://www.linuxidc.com/Linux/2015-05/117473.htm
Iptables usage example detailed http://www.linuxidc.com/Linux/2014-03/99159.htm
Linux Firewall iptables detailed tutorial http://www.linuxidc.com/Linux/2013-07/87045.htm
Basic use http://www.linuxidc.com/Linux/2013-08/88535.htm for iptables backup, recovery, and firewall scripts
Linux Firewall iptables detailed explanation of usage rules http://www.linuxidc.com/Linux/2012-08/67952.htm
Linux iptables firewall settings http://www.linuxidc.com/Linux/2015-10/123843.htm
This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-12/125879.htm