我有两个带有公共IP地址的VPS centos 6.6 x64示例:1.1.1.1和2.2.2.2
1.1.1.1的VPN是VPN服务器
我需要通过ssh连接1.1.1.1到2.2.2.2
因此,1.1.1.1上的VPN客户端可以有2.2.2.2公共IP地址。
我该怎么做?
发布于 2015-06-23 11:11:57
请看一下ssh的手册页,它给您提供了一个很好的例子:
man ssh
SSH-BASED VIRTUAL PRIVATE NETWORKS
ssh contains support for Virtual Private Network (VPN) tunnelling using the tun(4) network pseudo-device, allowing two networks to be joined securely. The sshd_config(5) configuration option PermitTunnel controls whether the server sup-
ports this, and at what level (layer 2 or 3 traffic).
The following example would connect client network 10.0.50.0/24 with remote network 10.0.99.0/24 using a point-to-point connection from 10.1.1.1 to 10.1.1.2, provided that the SSH server running on the gateway to the remote network, at
192.168.1.15, allows it.
On the client:
# ssh -f -w 0:1 192.168.1.15 true
# ifconfig tun0 10.1.1.1 10.1.1.2 netmask 255.255.255.252
# route add 10.0.99.0/24 10.1.1.2
On the server:
# ifconfig tun1 10.1.1.2 10.1.1.1 netmask 255.255.255.252
# route add 10.0.50.0/24 10.1.1.1
Client access may be more finely tuned via the /root/.ssh/authorized_keys file (see below) and the PermitRootLogin server option. The following entry would permit connections on tun(4) device 1 from user ``jane'' and on tun device 2 from
user ``john'', if PermitRootLogin is set to ``forced-commands-only'':
tunnel="1",command="sh /etc/netstart tun1" ssh-rsa ... jane
tunnel="2",command="sh /etc/netstart tun2" ssh-rsa ... john
Since an SSH-based setup entails a fair amount of overhead, it may be more suited to temporary setups, such as for wireless VPNs. More permanent VPNs are better provided by tools such as ipsecctl(8) and isakmpd(8).
您还必须设置路由,以确保流量流到正确的“接口”。
如果您正在寻找一个更永久的设置,您可能会考虑基于OpenVPN或IPSec的VPN,因为它们更适合这项工作,而且适应性更强。
不要使用公共IP作为ifconfig中唯一的IP来创建VPN,例如,您需要为每个服务器指定一个专用网络
服务器@ 1.1.1.1 -私有tun0 IP -10.0.100.0/28-10.0.100.1
服务器@ 2.2.2.2 -私有tun0 IP -10.0.200.0/28-10.0.200.1
然后分别从10.0.100.1 -> 10.0.200.1或相反的方向行驶。
https://serverfault.com/questions/700942
复制相似问题