Port forwarding between the same machine and different machines with iptables

Source: Internet
Author: User

Iptables forwarding a native 80 port request to port 8080
Iptables-t nat-a prerouting-p tcp--dport 80-j REDIRECT--to-ports 8080
    1. If you need this machine to be accessible, you need to configure the output chain:

Iptables-t nat-a output-p tcp-d 127.0.0.1--dport 80-j REDIRECT--to-ports 8080
Port forwarding between two machines
    1. Forward all 81 port requests from this machine to 192.168.1.1:80

    2. First, you want to enable the IPv4 forwarding feature:

Echo 1 >/proc/sys/net/ipv4/ip_forward
    1. or modify/etc/sysctl.conf (via) to enable forwarding after a reboot, then set Iptables (VIA):

Iptables-t nat-a prerouting-p tcp--dport 81-j DNAT--to 192.168.1.1:80 iptables-t nat-a postrouting-j MASQUERADE
    1. If the firewall feature is turned on, be careful to turn on both 80 and 812 ports.

10.23.3.129 the forwarding script on the 10.21.1.91 443 port is set up:
#!/bin/sh/sbin/iptables-t Nat-fecho 1 >/proc/sys/net/ipv4/ip_forward/sbin/iptables-t nat-a prerouting-p tcp--d Port 443-j DNAT--to 10.21.1.91:443/sbin/iptables-t nat-a postrouting-j masquerade/sbin/iptables-t nat-l-N

The simplest port forwarding tool under Linux:rinetd"If you think iptables is complicated, use the tools below to be simple"

Website address: http://www.boutell.com/rinetd


This article is from the "Endless Life" blog, make sure to keep this source http://holiday98.blog.51cto.com/2088075/1585817

Port forwarding between the same machine and different machines with iptables

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.