Use iptables in centos to set port forwarding

Source: Internet
Author: User

Echo 1>/proc/sys/NET/IPv4/ip_forward

First, you should do the net. ipv4.ip _ forward = 1 in the/etc/sysctl. conf configuration file. The default value is 0, which allows iptalbes forward.

After the modification is complete, run the following command to make the parameter take effect:
/Sbin/sysctl-P

Forward port 3389 of the Local interface IP address 61.144.14.72 to port 3389 of 116.6.73.229.
(Access port 3389 of 61.144.14.72 to jump to 3389 of 116.6.73.229)

[STEP]

1. First, we should do the net. ipv4.ip _ forward = 1 in the/etc/sysctl. conf configuration file, which defaults to 0 to allow iptalbes forward.

2. Disable the firewall using service iptables stop

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
Save the current rule to/etc/sysconfig/iptables
If you are familiar with this file, directly modifying the content here is also equivalent to the command line Input rules.

5. Start the iptables service and service iptables start
You can write a script to enable the device to run automatically;
# Vi/etc/rc. Local
#! /Bin/sh
#
# This script will be executed * after * all the other init scripts.
# You can put your own initialization stuff in here if you don't
# Want to do the full sys V style init stuff.
Touch/var/lock/subsys/local
SH/root/myshipin. Log
---------------------------------------------------------------------
VI myshipin. Log

#! /Bin/sh
#
# This script will be executed * after * all the other init scripts.
# You can put your own initialization stuff in here if you don't
# Want to do 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 -- 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
~

----------------------------------------------------------------
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

Use iptables in centos to set port forwarding

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.