How to Implement iptables port ing

Source: Internet
Author: User

Iptables port ingThe implementation steps are as follows:

I. Environment and functions to be implemented

The network settings of PC1 are as follows:

Eth0 192.168.0.29 Intranet

Eth1 219.239.11.22 Internet

The Network Setting of PC2 is 192.168.0.21 intranet.

The function we need to implement is to map port 8080 of PC1 to port 80 of PC2, that is, access

Http: // 219.239.11.22: 8080

You can access the WEB service on pc2.

 II. Implementation steps

1. First, the net. ipv4.ip _ forward = 1 in the/etc/sysctl. conf configuration file is 0 by default.

This allows iptalbes FORWARD.

2. There is an iptables file in the/etc/rc. d/init. d directory. The format is as follows:

Usage:./iptables {start | stop | restart | condrestart | status | panic | save}

Equivalent to service iptables {....}

Stop the iptables service, clear previous rules, and save disks.

Go to the/etc/rc. d/init. d directory and run

./Iptables stop

Iptalbes-F

Iptalbes-X

Iptalbes-Z

./Iptables save

3. reconfigure rules

Iptables-t nat-a prerouting-d 219.239.11.22-p tcp-m tcp -- dport 8080-j DNAT -- to-destination 192.168.0.21: 80

Iptables-t nat-a postrouting-d 192.168.0.21-p tcp-m tcp -- dport 80-j SNAT -- to-source 192.168.0.29

Iptables-a forward-o eth0-d 192.168.0.21-p tcp-dport 80-j ACCEPT

Iptables-a forward-I eth0-s 192.168.0.21-p tcp-sport 80-j ACCEPT

For more information about dnat snat, see help.

4. New rule Disks

./Iptables save

The rules are stored in the/etc/sysconfig/iptables file. If you are familiar with this file

Directly modifying the content here is also equivalent to entering the rule using the command line method.

5. Start the iptables service.

./Iptables start

There is a package flow in the/proc/net/ip_conntrack file, as shown below

Tcp 6 53 TIME_WAIT src =.../221.122.59.2 dst = 219.239.11.22 sport = 7958 dport = 8080 packets = 9 bytes = 1753

Src =.../172.18.10.205 dst = 172.18.10.212 sport = 80 dport = 7958 packets = 9 bytes = 5777 [ASSURED] use = 1

Through the introduction of this article, we can clearly see every step of iptables port ing implementation! Hope to help you!

  • Iptables port ing settings
  • Iptables implements port forwarding, port ing, and bidirectional access
  • Configure iptables firewall in CentOS
  • Install iptables and layer7 protocols in Centos5
  • Compile iptables in Centos 5.3 Environment
  • CentOS + iptables + squid transparent proxy + Firewall settings
  • Centos IPTables configuration method

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.