Use iptables as a NAT proxy to access the Internet, iptablesnat

Source: Internet
Author: User

Use iptables as a NAT proxy to access the Internet, iptablesnat

Background:
One server A cannot access the Internet and is connected to server B through the Intranet. Server B can access the Internet, and server A can also access the internet.

Intranet HOST: A eth1: 172.16.1.8 Internet host: B eth0: 10.0.0.61
Internet host: B eth1: 172.16.1.61

SNAT: Change the source address of the data packet. The firewall uses an external address to replace the local network address of the data packet. In this way, the host inside the network can communicate with the outside of the network.

1. Enable kernel route forwarding on server B that can access the Internet

# Temporary echo 1>/proc/sys/net/ipv4/ip_forwardsysctl-p # Permanent echo 'Net. ipv4.ip _ forward = 1'>/etc/sysctl. confsysctl-p

2. view the route table on the proxy server. And add the default gateway. Route add default gw 172.16.1.61

[root@localhost ~]# route -nKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface172.16.1.0      0.0.0.0         255.255.255.0   U     0      0        0 eth1169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth10.0.0.0         172.16.1.6      0.0.0.0         UG    0      0        0 eth1

3. You can add SNAT rules on server B.

iptables -t nat -A POSTROUTING -o eth0 -s 172.16.1.0/24 -j SNAT --to 10.0.0.61

4. Save

Service iptables save # restart iptables service/etc/init. d/iptables restart

5. Verify that the Internet can be accessed normally.

Set iptables to boot automatically [root @ lb02 ~] # Chkconfig | grep iptables 0: off1: off2: on3: on4: on5: on6: off

  

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.