网络拓扑以下:
网络
| 1.1.1.1 2.2.2.2 | +---------+ Public +---------+ | Private | ServerA +-----------+ ServerB +-----+ +---------+ Network +---------+ | Network | | 192.168.1.0/24需求以下:
ServerB 配置
ip tunnel add a2b mode ipip remote 2.2.2.2local1.1.1.1ide
ifconfig a2b 192.168.2.1 netmask 255.255.255.0spa
隧道配置完成后,请在ServerA上192.168.2.2,看是否能够ping通,ping通则继续,ping不通须要再看一下上面的命令执行是否有报错
ip tunnel add a2b mode ipip remote 1.1.1.1local2.2.2.2ip
ifconfig a2b 192.168.2.2 netmask 255.255.255.0路由
ServerB上,添加iptables nat,将ServerA过了访问192.168.1.0/24段的包进行NAT,并开启ip foward功能
/sbin/route add -net 192.168.1.0/24 gw 192.168.2.2rem
至此,完成了两端的配置,ServerA能够直接访问ServerB 所接的私网了。
iptables -t nat -A POSTROUTING -s 192.168.2.1-d 192.168.1.0/24-j MASQUERADEcmd
sysctl -w net.ipv4.ip_forward=1it
sed -i '/net.ipv4.ip_forward/ s/0/1/'/etc/sysctl.confpip