Configure server port forwarding using iptables
Environment:
CentOS6.5, 192.168.1.10, two-way Internet communication, binding domain name zlzkj.org;
WinServer2008, 192.168.1.11, cannot be accessed directly from the Internet, but ftp, remote desktop, and MySQL should be accessed on zlzkj.org;
Objectives:
Ftp: 21 of 192.168.1.10 is forwarded to 21 of 192.168.1.11;
Remote Desktop: 3389 of 192.168.1.10 is forwarded to 3389 of 192.168.1.11;
MySQL: 3361 of 192.168.1.10 is forwarded to 3361 of 192.168.1.11;
1. You must first enable the data forwarding function for linux.
Vim/etc/sysctl. conf
Change net. ipv4.ip _ forward = 0 to 1.
Sysctl-p
2. Change iptables and run the following command:
# Forward data from port 21 of 192.168.1.10 to 192.168.1.11: 21.
Iptables-t nat-a prerouting-d 192.168.1.10-p tcp-dport 21-j DNAT-to-destination 192.168.1.11: 21
# Change the source IP address to 192.168.1.10 when port 21 of 192.168.1.11 is returned
Iptables-t nat-a postrouting-d 192.168.1.11-p tcp-dport 21-j SNAT-to-source 192.168.1.10
# Remote Desktop
Iptables-t nat-a prerouting-d 192.168.1.10-p tcp-dport 3389-j DNAT-to-destination 192.168.1.11: 3389
Iptables-t nat-a postrouting-d 192.168.1.11-p tcp-dport 3389-j SNAT-to-source 192.168.1.10
# MySQL
Iptables-t nat-a prerouting-d 192.168.1.10-p tcp-dport 3361-j DNAT-to-destination 192.168.1.11: 3361
Iptables-t nat-a postrouting-d 192.168.1.11-p tcp-dport 3361-j SNAT-to-source 192.168.1.10
3. Save iptables
Service iptables save
-------------------------------------- Split line --------------------------------------
Disable the default firewall in CentOS 7.0 and enable the iptables firewall.
Iptables examples
Linux Firewall iptables
Basic use of iptables backup, recovery, and firewall scripts
Detailed description of firewall iptables usage rules in Linux
-------------------------------------- Split line --------------------------------------
This article permanently updates the link address: