11

i have 3 network cards , 1 Lan (wired) , 1 wireless network card & 1 is wireless usb

how do i ping from specific network card ?

& how do i use specific network card for specific application

example

i want to ping google from wlan1

example for specific application

i want to use firefox or transmission from wan1

Lan ip 192.168.0.2 > Working Properly enter image description here pin -I wlan1 google.com enter image description here

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 

@Khaled

one@onezero:~$ ping -S 192.168.0.2  hotmail.com
PING hotmail.com (65.55.72.135) 56(84) bytes of data.
64 bytes from origin.sn131w.snt131.mail.live.com (65.55.72.135): icmp_req=1 ttl=236 time=391 ms
64 bytes from origin.sn131w.snt131.mail.live.com (65.55.72.135): icmp_req=2 ttl=236 time=296 ms
64 bytes from origin.sn131w.snt131.mail.live.com (65.55.72.135): icmp_req=3 ttl=236 time=393 ms
64 bytes from origin.sn131w.snt131.mail.live.com (65.55.72.135): icmp_req=4 ttl=236 time=352 ms

 ping -S 192.168.0.3  hotmail.com
PING hotmail.com (65.55.72.183) 56(84) bytes of data.
64 bytes from origin.sn134w.snt134.mail.live.com (65.55.72.183): icmp_req=1 ttl=236 time=312 ms
64 bytes from origin.sn134w.snt134.mail.live.com (65.55.72.183): icmp_req=2 ttl=236 time=457 ms
64 bytes from origin.sn134w.snt134.mail.live.com (65.55.72.183): icmp_req=3 ttl=236 time=298 ms
64 bytes from origin.sn134w.snt134.mail.live.com (65.55.72.183): icmp_req=5 ttl=236 time=330 ms
64 bytes from origin.sn134w.snt134.mail.live.com (65.55.72.183): icmp_req=6 ttl=236 time=300 ms

Now Lastly the application issue

1
  • 1
    Do you just want to set the source address, or are you expecting to somehow select a different network path? Setting a source address is not going to auto-magically change which route is selected, and make exit any particular interface.
    – Zoredache
    Jan 30, 2012 at 18:18

3 Answers 3

11

If you look at ping manual man ping, you can read:

-I interface address
   Set source address to specified interface address. Argument may be numeric IP
   address or name of device.
4
  • 1
    check 2nd pic > ping -I wlan1 google.com
    – One Zero
    Jan 30, 2012 at 15:05
  • Maybe, you have ping blocked in your connection.
    – Khaled
    Jan 30, 2012 at 15:09
  • its working on eth0
    – One Zero
    Jan 30, 2012 at 15:16
  • I think this only will work for multicast addresses
    – slm
    May 19, 2021 at 2:54
5

Check out your routing table.

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
192.168.0.0     0.0.0.0         255.255.255.0   U     2      0        0 wlan1

Your wlan1 interface only knows how to reach the 192.168.0.0 network. You also have your wlan1 and eth0 in the same subnet which could cause problems. You need to add a route to the routing table for any destinations you want to reach on your wlan interface. For example

route add -host 65.55.72.135 gw 192.168.0.1 dev wlan1
ping -I wlan1 65.55.72.135

Note this won't let you route by application. For that you'll need to configure policy routing with something like iptables -m owner --uid-owner The ping -S src_ip dest_ip command will actually send the packet out with a source of your wlan1 IP address but then route the packet out eth0 because the next hop is eth0 in the routing table. Your best bet is to place the wlan1 and eth0 interfaces on separate subnets.

0
4

As far as ping(8) from BSD goes, you can use the -S switch of ping to simulate pinging from particular interface:

-S src_addr
             Use the following IP address as the source address in outgoing packets.  On hosts
             with more than one IP address, this option can be used to force the source address to
             be something other than the IP address of the interface the probe packet is sent on.
             If the IP address is not one of this machine's interface addresses, an error is
             returned and nothing is sent.

Application level awareness for network interface(IP addresses) is somewhat possible to some extent with if we specify different gateway for different interfaces or redirect traffic according to port or other criterion via firewall rules... eg. if you are using firefox to connect to 80 ports only , then you could specify SNAT rule in iptables to connect via yours specified IP address hence the desired interface

6
  • i didnt understand , command ? ping -S ?
    – One Zero
    Jan 30, 2012 at 15:03
  • ping -S your.first.ip.addr hotmail.com & ping -S your.another.ip.addr hotmail.com pings hotmail.com with your available different IP address. If unspecified , default protocol takes the ping probe via default gateway
    – kaji
    Jan 30, 2012 at 15:09
  • 1
    What version of ping are you suing? On my Ubuntu system -S configures the socket send buffer.
    – Zoredache
    Jan 30, 2012 at 18:20
  • ping -V > ping utility, iputils-sss20101006
    – One Zero
    Jan 30, 2012 at 18:31
  • @Zoredache that's BSD ping, not GNU ping. Different program, not simply different version.
    – lapo
    Aug 26, 2020 at 8:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .