Linux firewall implements port forwarding, port mapping and bidirectional access ____linux

Source: Internet
Author: User
Tags iptables

Iptables implementation of Port forwarding, port mapping and two-way access is not difficult to configure, see below:

Allow packet forwarding:

#echo 1 >/proc/sys/net/ipv4/ip_forward

Forwarding TCP 8081 to xx.xx.xx.xx:

#iptables-T nat-i prerouting-p tcp–dport 80-j dnat–to xx.xx.xx.xx

Enable the forwarding packet to implement a "two-way path" and set a correct return channel for the packet:

#iptables-T nat-i postrouting-p tcp–dport 8080-j Masquerade

Represents saving a rule to a/etc/sysconfig/iptables file

#service iptables Save

Restart Iptables to take effect of the rule that you just added

#service iptables Restart

If you execute the above command and still cannot forward it, you may not be able to write the iptables file because the Iptables service is not stopped, and you should perform the service iptables stop before you perform the above command, and the last service iptables Start Restart Service

Because the Linux firewall defaults to shutting down Port 3306. Therefore, to be able to access Port 3306, there are two ways to turn off the firewall, and the other is to have the firewall open 3306 ports.

The troubleshooting steps for opening port 3306 are as follows:

1, modify the/etc/sysconfig/iptables file, add the following line:

-A rh-firewall-1-input-m state–state new-m tcp-p tcp–dport 3306-j ACCEPT

2, restart the firewall, here are two ways to restart the firewall

A) effective after reboot

Open: Chkconfig iptables on

Close: Chkconfig iptables off

(b) Immediate effect, failure after reboot

Open: Service iptables start

OFF: Service iptables stop

The

Database mapping succeeded.

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.