在私有网络内通过 SSH 访问具有 VPN 连接的目标计算机

在私有网络内通过 SSH 访问具有 VPN 连接的目标计算机

我有一个相当标准的私人网络设置,其中两台电脑连接到路由器:

Router
| |
| -> PC1
|
->PC2

当我使用 192.168.. IP 地址通过 SSH 从 PC1 连接到 PC2 时,一切都运行正常。但是,我想在 PC2(并且只在 PC2)上启用 VPN 连接,并且仍然能够在我的私有网络内连接到它。但是,当我在 PC2 上启用 VPN 连接时,我无法使用 192.168.. IP 地址从 PC1 连接到它,即使 PC2 上的 ifconfig 显示本地网络仍然有标志 <UP、BROADCAST、RUNNING、MULTICAST>

在此设置中,是否有办法使用 SSH 从我的专用网络内连接到 PC2?我知道我在这里重复了一遍,但我只是想说清楚:我不需要从外部网络通过 SSH 连接到我的 PC,那样端口转发就没问题了。

两台电脑都运行基于 Debian 的发行版(PC1 是 Ubuntu,PC2 是 Raspbian)

我尝试在 SO 上和一般情况下寻找解决方案,但似乎大多数人几乎都遇到如下设置问题:

PC1 ----> (Internet) ---> Router ---> PC2

而且这个设置看起来不太像我的。另外,除非我确信这是唯一的选择,否则我真的不想弄乱端口转发。

PC2 netstat 输出:

$ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.189.1   0.0.0.0         UG        0 0          0 wlan0
192.168.189.0   0.0.0.0         255.255.255.0   U         0 0          0 wlan0

是否配置没有VPN:

$ ifconfig 
eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether -  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1042  bytes 156052 (152.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1042  bytes 156052 (152.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.189.174  netmask 255.255.255.0  broadcast 192.168.189.255
        ether -  txqueuelen 1000  (Ethernet)
        RX packets 26871875  bytes 39045623151 (36.3 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9704634  bytes 1330790356 (1.2 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

启用 VPN 的 ifconfig:

$ ifconfig 
eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1034  bytes 154982 (151.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1034  bytes 154982 (151.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

nordlynx: flags=81<UP,POINTOPOINT,RUNNING>  mtu 1420
        inet 10.5.0.2  netmask 255.255.255.255  destination 10.5.0.2
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
        RX packets bytes 
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets bytes 
        TX errors 4  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.189.174  netmask 255.255.255.0  broadcast 192.168.189.255
        ether txqueuelen 1000  (Ethernet)
        RX packets bytes 
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets bytes 
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

谢谢你!

答案1

感谢用户盲区

nordvpn whitelist add subnet 192.168.0.0/16 – 添加规则以将指定子网列入白名单 nordvpn whitelist remove subnet 192.168.0.0/16 – 删除同一规则

相关内容