Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to ping from a specific interface, I have a wired and a wireless connection both going into my laptop.

My wired adaptor eth0 is on the IP 172.16.109.75
My wifi adaptor wlan0 is on the IP 192.168.1.69

When I ping google with my eth0 unplugged with the following command:

conneco@mcr-pc-29334:~$ ping -I wlan0 www.google.co.uk
PING www.l.google.com (74.125.230.115) from 192.168.1.69 wlan0: 56(84) bytes of data.
64 bytes from 74.125.230.115: icmp_seq=1 ttl=51 time=32.7 ms
64 bytes from 74.125.230.115: icmp_seq=2 ttl=52 time=28.7 ms
64 bytes from 74.125.230.115: icmp_seq=3 ttl=52 time=28.9 ms
64 bytes from 74.125.230.115: icmp_seq=4 ttl=52 time=28.3 ms

It works fine as expected. I plug my eth0 cable in and run the same again:

conneco@mcr-pc-29334:~$ ping -I wlan0 www.google.co.uk
PING www.l.google.com (74.125.230.112) from 172.16.109.75 wlan0: 56(84) bytes of data.
From mcr-pc-29334.local (192.168.1.69) icmp_seq=2 Destination Host Unreachable
From mcr-pc-29334.local (192.168.1.69) icmp_seq=3 Destination Host Unreachable
From mcr-pc-29334.local (192.168.1.69) icmp_seq=4 Destination Host Unreachable
From mcr-pc-29334.local (192.168.1.69) icmp_seq=5 Destination Host Unreachable
From mcr-pc-29334.local (192.168.1.69) icmp_seq=6 Destination Host Unreachable
From mcr-pc-29334.local (192.168.1.69) icmp_seq=7 Destination Host Unreachable

By the output at the top it seems to send it from the eth0 (which at work won't be able to ping because it gets blocked), but the wifi is another link to a separate network where I'm on the net directly and therefore sending the ping request from the wlan0 should work. What's happening? How should I fix it?

share|improve this question
    
In the future, if you want to move your post to a different SE site, just flag it for mod attention and tell them which site you want it moved to. I asked an SU mod to move yours; I'll merge this with that when they do (Edit: Looks like they just deleted it instead; oh well) –  Michael Mrozek Mar 28 '11 at 14:30
    
No probs, sorry still finding my feet in *.exchange world –  Shutupsquare Mar 30 '11 at 21:47

2 Answers 2

up vote 2 down vote accepted

Probably, when pluging in the ethernet cable, your default route gateway changes by dhcp. You send packets from wlan0 but your system doesn't know who is the gateway to forward them to. This way you can only ping systems within 192.168.1 network but not further. If you want to get a reply from the google server, you'll have to either change the default gateway back to the wireless router, or add a specific route for this server.

route add -host 74.125.230.112/32 gw 192.168.1.1 # assuming 192.168.1.1 is the wireless router's ip
share|improve this answer
    
makes sense to me thanks very much! ill try it out shortly –  Shutupsquare Mar 28 '11 at 10:29

To ping from some interface you should use:

$ ping -I ethx xxx.xxx.xxx.xxx
share|improve this answer
    
This is true but not his problem; he already uses -I in the question –  Michael Mrozek Mar 28 '11 at 14:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.