更新

更新

我有 3 張網路卡,1 個 LAN(有線),1 個無線網路卡和 1 個無線 USB

我如何從特定網路卡執行 ping 操作?

&我如何將特定網卡用於特定應用程式

例子

i want to ping google from wlan0 

具體應用範例

i want to use firefox or transmission from wan1

更新

LAN ip 192.168.0.2 > 運作正常 在此輸入影像描述

WLAN1 ip 192.168.0.3

在此輸入影像描述

pin -I wlan1 google.com

更新

嘗試貼上 Route -n 和/或 ip Route 的輸出。在我看來,wlan1 介面沒有配置有效的網關。 –@MrShunz

one@onezero:~$ route -n 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth0
172.16.221.0    0.0.0.0         255.255.255.0   U     0      0        0 vmnet8
192.168.0.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     2      0        0 wlan1
192.168.48.0    0.0.0.0         255.255.255.0   U     0      0        0 vmnet1
one@onezero:~$ ip route
default via 192.168.0.1 dev eth0  proto static 
169.254.0.0/16 dev eth0  scope link  metric 1000 
172.16.221.0/24 dev vmnet8  proto kernel  scope link  src 172.16.221.1 
192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.2  metric 1 
192.168.0.0/24 dev wlan1  proto kernel  scope link  src 192.168.0.3  metric 2 
192.168.48.0/24 dev vmnet1  proto kernel  scope link  src 192.168.48.1 

答案1

ping有一個特定的開關來設定來源介面:-I。正如在線上說明頁中找到的:

 -I interface address
          Set source address to specified interface address. Argument may be  numeric  
          IP  address  or  name  of device.
          When pinging IPv6 link-local address this option is required.

舉個例子

$ ping -I wlan0 8.8.8.8

透過 wlan0 介面 ping 8.8.8.8。

為特定應用程式強制使用介面還需要做更多的工作。你可以找到解決方案在這個 superuser.com 問題中並在本文連結在答案中。

更新

我在這個答案中公開的方法展示瞭如何強制 ping 使用特定介面。並連結到一些有關如何強制通用程式使用特定介面的文章。

現在,為了使這一切發揮作用,您必須配置一些「進階」路由。正如您從輸出中看到的,route -n您有多個網絡,但只有一個通往互聯網的網關。那是好的,因為多個網關路由非常重要高級主題而且有些難以處理好。

這超出了您在原始問題中提出的問題。我建議您在這裡或上發布新問題伺服器故障詢問如何在多個網路介面上設定和管理多個網際網路網關。

或者,更好的是,嘗試用谷歌搜尋它;)同時檢查拉特克網站用於進階 Linux 路由配置。

相關內容