Use Iptables to set port forwarding in CentOS system

Source: Internet
Author: User
Tags centos iptables

Forward 3389 ports of the local interface IP 61.144.14.72 to 116.6.73.229 3389

(The main access to the 61.144.14.72 3389 port, you will jump to 116.6.73.229 3389)

Steps

1, the first thing to do is/etc/sysctl.conf configuration file Net.ipv4.ip_forward = 1 default is 0 This allows iptalbes forward.

2, service iptables stop shutdown firewall

3. Reconfigure rules

Iptables-t nat-a prerouting--dst 61.144.14.72-p tcp--dport 3389-j dnat--to-destination 116.6.73.229:3389

Iptables-t nat-a postrouting--dst 116.6.73.229-p tcp--dport 3389-j SNAT--to-source 61.144.14.72

Service Iptables Save

Saves the current rule to the/etc/sysconfig/iptables

If you're familiar with this file, modifying the contents directly is equivalent to command-line input rules.

5, Start iptables Services, service iptables start

Can be written into the script, the device starts to run automatically;

# vi/etc/rc.local

#!/bin/sh

#

# This script would be executed *after* all the other init scripts.

# You can put your own initialization stuff with If you don ' t

# want to does the full Sys V style init stuff.

Touch/var/lock/subsys/local

Sh/root/myshipin.log

---------------------------------------------------------------------

VI Myshipin.log

#!/bin/sh

#

# This script would be executed *after* all the other init scripts.

# You can put your own initialization stuff with If you don ' t

# want to does the full Sys V style init stuff.

Iptables-f-T Nat iptables-t nat-a prerouting--dst 61.144.14.72-p tcp--dport 3389-j dnat. 229:3,389

Iptables-t nat-a postrouting--dst 116.6.73.229-p tcp--dport 3389-j SNAT--to-source 61.144.14.72

~

----------------------------------------------------------------

Tcp

Iptables-t nat-a prerouting--dst 61.144.14.87-p tcp--dport 9304-j dnat--to-destination 10.94.143.204:9304

Iptables-t nat-a postrouting--dst 10.94.143.204-p tcp--dport 9304-j SNAT--to-source 61.144.14.87

Udp

Iptables-t nat-a prerouting--dst 61.144.14.87-p UDP--dport 9305-j dnat--to-destination 10.94.143.204:9305

Iptables-t nat-a postrouting--dst 10.94.143.204-p UDP--dport 9305-j SNAT--to-source 61.144.14.87

Related Article

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.