4

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?

2
  • 1
    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) Commented Mar 28, 2011 at 14:30
  • No probs, sorry still finding my feet in *.exchange world Commented Mar 30, 2011 at 21:47

3 Answers 3

4

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 
1
  • makes sense to me thanks very much! ill try it out shortly Commented Mar 28, 2011 at 10:29
1

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.

http://www.rjsystems.nl/en/2100-adv-routing.php

0
-3

My example

# echo "203 T3" >> /etc/iproute2/rt_tables # apt install -y sipcalc WNET=$(sipcalc -I wlp2s0 | grep "Network address" | awk '{print $4}') WBIT=$(sipcalc -I wlp2s0 | grep "Network mask (bits)" | awk '{print $5}') WLAN_NET="$WNET/$WBIT" ip route add default via $GW_WLAN table T3 ip route add $WLAN_NET via $GW_WLAN table T3 ip rule add from $WLAN_NET table T3 # Tests ip rule list ping -I enp3s0 8.8.8.8 ping -I wlp2s0 8.8.8.8 
2
  • 2
    This is rather poor answer, because you don't explain what it does. Not all people are capable of reading scripts, and to be able to use your solution, one needs to know to edit some parts (or define the missing env variable GW_WLAN). Commented Aug 14, 2017 at 8:57
  • Please edit your answer and explain in details what you are doing and why it would solve the original issue. We should not accustom readers to copy and execute scripts blindly. Commented Aug 14, 2017 at 9:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.