ssh 使用指定网卡 连接特定网络

有时候,当电脑有两个网卡时;一个网卡 连接免费网络,一个网卡连接收费网络。这样当你想使用免费网络与远程服务器建立连接,使用诸如scp命令或者 ssh 隧道之类传输大文件。这时候你需要指定特定的特定的网卡来建立连接了。

ssh 中 有一个选项可以绑定特定的interface 我们使用 man ssh 查看手册可以看到:

 -B bind_interface
             Bind to the address of bind_interface before attempting to connect to the destination host.  This is only useful on systems with more than one address.

可见,使用 ssh -B 选项,可以指定特定的网卡;

另外还有个选项 -b 可以指定 数据包的源地址 也相当于绑定了网卡。因为 macos 上 ssh 没有 -B 选项;总之具体情况,具体对待吧。更权威的使用方式还是查找文档。

-b bind_address
             Use bind_address on the local machine as the source address of the connection.  Only useful on systems with more than one address.

我在实验室环境测试成功。如果您有什么问题,欢迎留言讨论。

保持更新,转载请注明出处。更多关于 网络和系统的博客,请关注 cnblogs.com/xuyaowen 

原文地址:https://www.cnblogs.com/xuyaowen/p/ssh-bind-interface.html