Using IP tunnel to get through a private network

Source: Internet
Author: User
Tags iptables

Address: Use IP tunnel to open up private network requirements

There are 2 isolated networks, and the topology is shown in the diagram below. ServerA want direct access to the private network of the ServerB connection

                                                  |
            1.1.1.1               2.2.2.2         |
            +---------+  public   +---------+     | Private
            | ServerA +-----------+ ServerB +-----+
            +---------+  Network  +---------+     | Network
                                                  |
                                                  
Implement

The Ipip tunnel is established via IP tunnel, and then NAT can be achieved by iptables.
Step 1. Establishing an IP tunnel
ServerA Configure Iptunnel, and configure IP on tunnel interface

IP tunnel Add a2b mode ipip remote 2.2.2.2 local 1.1.1.1
ifconfig a2b 192.168.2.1 netmask 255.255.255.0

ServerB Configure Iptunnel, and configure IP on tunnel interface

IP tunnel Add a2b mode ipip Remote 1.1.1.1 local 2.2.2.2
ifconfig a2b 192.168.2.2 netmask 255.255.255.0

After the tunnel configuration is complete, on the ServerA 192.168.2.2, see if you can ping, ping general continue, Ping does not need to look at the above command to execute whether there is an error
Step 2. Adding routes and NAT
ServerA, add a route to the 192.168.1.0/24

/sbin/route add-net 192.168.1.0/24 GW 192.168.2.2

ServerB, add iptables nat, Nat ServerA the package that accesses the 192.168.1.0/24 segment, and turn on the IP foward feature

Iptables-t nat-a postrouting-s 192.168.2.1-d 192.168.1.0/24-j Masquerade
sysctl-w net.ipv4.ip_forward=1
sed -I '/net.ipv4.ip_forward/s/0/1/'  /etc/sysctl.conf

At this point, the two ends of the configuration, ServerA can directly access the ServerB connected to the private network.

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.