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.