Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
My wifi adaptor wlan0 is on the IP

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 ( from wlan0: 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=51 time=32.7 ms
64 bytes from icmp_seq=2 ttl=52 time=28.7 ms
64 bytes from icmp_seq=3 ttl=52 time=28.9 ms
64 bytes from 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 ( from wlan0: 56(84) bytes of data.
From mcr-pc-29334.local ( icmp_seq=2 Destination Host Unreachable
From mcr-pc-29334.local ( icmp_seq=3 Destination Host Unreachable
From mcr-pc-29334.local ( icmp_seq=4 Destination Host Unreachable
From mcr-pc-29334.local ( icmp_seq=5 Destination Host Unreachable
From mcr-pc-29334.local ( icmp_seq=6 Destination Host Unreachable
From mcr-pc-29334.local ( 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 – squarebear Mar 30 '11 at 21:47
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 gw # assuming is the wireless router's ip
share|improve this answer
makes sense to me thanks very much! ill try it out shortly – squarebear Mar 28 '11 at 10:29

SystemWide, there can only be one default gateway and only one SystemWide routing table. Not exactly true, but good enough for this.

NicWide, there can be one default gateway per nic. Each nic can have its own individual routing table.

In short, become familar with ip route, ip rule and /etc/iproute2/rt_tables. Look at this "Two Default Routes" tutorial.


share|improve this answer

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
Not long ago on RedHat derived systems, ping -I LocalInterfaceName would fail altogether, but ping -I LocalInterfaceIP would succeed. The kernel did not know anything about userland interface names. – rjt Jan 13 '15 at 6:45

Your Answer


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.