Use Iptables to do NAT agent Internet (intranet inside a machine can not be connected to the Internet through the computer to do the internet agent)

Source: Internet
Author: User
Tags iptables

Original:http://blog.sina.com.cn/s/blog_6ca646a0010126wl.html

Background:
There is a server can not access the Internet, and B server through the intranet to connect, B server to the Internet, to achieve a server can also be online.
A ip:192.168.0.35
B ip:192.168.0.146

SNAT: Change the source address of the packet. The firewall uses an external address to replace the local network address of the packet. This enables the network internal host to communicate with the network external.

1. On the Internet that Server B, to open the kernel routing forwarding function
Echo 1 >/proc/sys/net/ipv4/ip_forward

2. View the routing table on the Internet server A via proxy. and add a default gateway. Route add default GW 192.168.0.146
[Root@localhost ~]# Route-n
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.0.146 0.0.0.0 UG 0 0 0 eth0

3. Add Snat rule on Server B where you can access the Internet
Iptables-t nat-a postrouting-o eth0-s 192.168.0.0/24-j snat–-to

4. Save
Service Iptables Save

5. Verify that you can access the Internet normally.

Related Article

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.