Linux Source address translation (i)

Source: Internet
Author: User

Linux iptables Source Address conversion experiment


1. Environmental preparedness

Before the experiment I first prepared three Linux hosts, using the operating system is: CentOS, three hosts network planning as follows:


The first host: Intranet, analog intranet host, network connection mode using bridge connection, ip:192.168.10.2

Second host: Internet, simulated external network host, network connection mode using only host mode, ip:172.16.100.2

Third host: Iptables, analog route forwarding, which has two network cards, the first network card (EHT1) ip:192.168.10.1, the second network card (eth2) ip:172.16.100.1


2. Start the experiment

hosts on the same network can communicate with each other at this time, and can be verified with a ping command. If you want your intranet to access Iptables 172.16.10.1, you need to specify a gateway for your intranet and the Internet:

To specify a gateway for the intranet: route add default 192.168.10.1

To specify the gateway for the Internet: route add default 172.16.100.1


After you specify the gateway, you need to turn on the iptables forwarding feature:

Echo 1 >/proc/sys/net/ipv4/ip_forward is temporarily active, restarting the network service or failing the host.

vim/etc/sysctl.conf Net.ipv4.ip_forward = 1 can be modified, permanently valid.


The intranet can access the Internet host at this point, but the source address is intranet:192.168.10.2. For source address translation, firewall rules need to be added to the iptables host:

Iptables-t nat-a postrouting-s 192.168.10.0/24-o eth2-j SNAT--to-source 172.16.100.1

After the rule is added, the address of the packet from the intranet is converted to 172.16.100.1

This article is from the Shell Implementation Calculator blog, so be sure to keep this source http://codekong.blog.51cto.com/10704076/1739968

Linux Source address translation (i)

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.