可以指定ssh命令的接口吗?

时间:2013-03-05 06:01:05

标签: ubuntu openssh

我尝试通过ssh连接到我的远程服务器。但是由于代理限制,这是不可能的,因为eth0被用作默认值。

但我有自己的互联网网关wlan0接口。

我如何指定使用wlan0而不是eth0到我的openssh客户端?

我尝试了以下操作,但它不起作用:

:~$ ssh -v 176.111.109.0
OpenSSH_5.3p1 Debian-3ubuntu7, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /home/unmanner/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 176.111.109.0 [176.111.109.0] port 22.
debug1: connect to address 176.111.109.0 port 22: Connection refused
ssh: connect to host 176.111.109.0 port 22: Connection refused

我也试过这样的“绑定”选项:

:~$ ssh -v -b 172.20.10.6 176.111.109.0
OpenSSH_5.3p1 Debian-3ubuntu7, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /home/unmanner/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 176.111.109.0 [176.111.109.0] port 22.
debug1: connect to address 176.111.109.0 port 22: Connection timed out
ssh: connect to host 176.111.109.0 port 22: Connection timed out

其中“172.20.10.6” - 在wlan0上连接的IP地址。

如果我拔下以太网线 - 一切正常!但我希望有可能使用这两种接口。

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以通过网关176.111.109.0

向主持人添加路线w.x.y.z
route add -host 176.111.109.0 gw w.x.y.z wlan0

这样,176.111.109.0的所有流量都会通过指定gateway IP address上的指定network interface,即wlan0

当您断开有线网络并且只连接无线网络时,您可以从/sbin/route的输出中找出wl0的网关IP地址。

注意:如果重新启动此框,则会手动添加手动添加的路由。要使路线在重新启动后保持不变,您需要将以下行添加到/etc/sysconfig/network-scripts/route-wlan0

# Host route for 176.111.109.0 through w.x.y.z on wlan0
176.111.109.0 via w.x.y.z dev wlan0