Configure server port forwarding using iptables

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.