Configure linux port forwarding

Source: Internet
Author: User

For linux port forwarding, assume there are two servers, A and B. I need to forward the data that accesses port 8081 of server A to port 8081 of server B and receive the response data of server B. Www.2cto.com

Command: # echo 1>/proc/sys/net/ipv4/ip_forward # iptables-t nat-I PREROUTING-p tcp -- dport 8081-j DNAT -- to xx. xx. xx. xx # iptables-t nat-I POSTROUTING-p tcp -- dport 8081-j MASQUERADE # service iptables save # service iptables restart ============ ========================================================== ===== the first command allows packet forwarding; the second command indicates forwarding TCP 8081 to xx. xx. xx. xx; the third command indicates that a "two-way path" is implemented for the forwarded data packets, and a correct return channel is set for the data packets. The fourth command means to save the rule to the/etc/sysconfig/iptables file. The Fifth command means to restart iptables to make the rule just added take effect. Many people use the method on the Internet for port ing, the reason for the failure is that the fourth and fifth commands are not executed. Note: If you still cannot forward the above commands, the iptables service may not be stopped and the command cannot be written to the iptables file. You should first execute service iptables stop and then execute the preceding command, finally, the service iptables start restarts the service.

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.