网络拓扑如下:
|
1.1.1.1 2.2.2.2 |
+---------+ Public +---------+ | Private
| ServerA +-----------+ ServerB +-----+
+---------+ Network +---------+ | Network
|
| 192.168.1.0/24
需求如下:ServerA想直接访问到ServerB连接的私有网络
实现方法:
通过ip tunnel建立ipip隧道,再通过iptables进行nat,便可以实现。
Step 1. 建立ip隧道
ServerA配置
ip tunnel add a2b mode ipip remote 2.2.2.2local1.1.1.1
ifconfig a2b 192.168.2.1 netmask 255.255.255.0
ip tunnel add a2b mode ipip remote 1.1.1.1local2.2.2.2
ifconfig a2b 192.168.2.2 netmask 255.255.255.0
Step 2. 添加路由和nat
ServerA上,添加到192.168.1.0/24的路由
/sbin/route add -net 192.168.1.0/24 gw 192.168.2.2
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
转载于:https://blog.51cto.com/kexl908/1288296

4901

被折叠的 条评论
为什么被折叠?



