1

I have a Linux box acting as a router for my home network. it has 3 routing tables:

# ip route show default
default via 192.168.5.1 dev wlp2s0
172.18.231.140/30 dev wwx0c5b8f279a64  proto kernel  scope link  src 172.18.231.141
192.168.0.0/24 dev enp1s0  proto kernel  scope link  src 192.168.0.110
192.168.1.0/24 dev enp3s0  proto kernel  scope link  src 192.168.1.10
192.168.5.0/24 dev wlp2s0  proto kernel  scope link  src 192.168.5.100

#ip route show table ISP1
default via 192.168.0.1 dev enp1s0
192.168.0.0/24 dev enp1s0  proto kernel  scope link  src 192.168.0.110
192.168.1.0/24 dev enp3s0  proto kernel  scope link  src 192.168.1.10

# ip route show table ISP2
default via 172.18.231.142 dev wwx0c5b8f279a64
172.18.231.140/30 dev wwx0c5b8f279a64  proto kernel  scope link  src 172.18.231.141
192.168.0.0/24 dev enp1s0  proto kernel  scope link  src 192.168.0.110
192.168.1.0/24 dev enp3s0  proto kernel  scope link  src 192.168.1.10

What normally happens is all the client who connect to network goes through default gateway and if I wanted, I'm adding ip rule to match ip and change clients to use ISP1 table or ISP2 table

now I want to do a ping check to see my mobile network "wwx0c5b8f279a64" which is attached to ISP2 table is connected or disconnected, but from the linux box I can't do a ping check because ping check goes through default route which is through "wlp2s0" interface.

Is there a way to solve this issue? I think if I can route Linux box's local traffic to ISP2 table it will work but I can't figure how to traffic box's local traffic to ISP2 table.

4
  • The obvious way is to temporarily add a rule that will activate the table for the address or address range you want to ping. Second thing to try is to bind (ping -I ...) to the device you want to ping from, but you may also need a rule to make this work (you didn't show us your rules).
    – dirkt
    Commented Jul 13, 2018 at 5:48
  • @dirkt i just add "ip rule add from ${ip} table ISP2" when i want some client ip's to change the gateway. i want to ping 8.8.8.8 (google dns) from local box via ISP2 table to figure out that gateway is up or down. Commented Jul 13, 2018 at 6:28
  • 1
    Then ip rule add to 8.8.8.8 table ISP2, ping 8.8.8.8, ip rule del to 8.8.8.8 table ISP2. Note that as long as the rule is active, all traffic to 8.8.8.8 will go via this interface, so if you are actually using 8.8.8.8 as a nameserver somewhere, it might not work during that time.
    – dirkt
    Commented Jul 13, 2018 at 7:16
  • @dirkt Thank you very very much. that did the trick. :) i'm using 8.8.8.8 as nameserver so i will find another host to ping Commented Jul 13, 2018 at 7:23

2 Answers 2

3

Perhaps nping (normally part of the nmap) can help here? From the manpage:

--dest-mac mac (Ethernet Destination MAC Address) This option sets the destination MAC address that should be set in outgoing Ethernet frames. This is useful in case Nping can't determine the next hop's MAC address or when you want to route probes through a router other than the configured default gateway. The MAC address should have the usual format of six colon-separated bytes, e.g. 0:50:56:d4:01:98. Alternatively, hyphens may be used instead of colons. Use the word random or rand to generate a random address, and broadcast or bcast to use ff:ff:ff:ff:ff:ff. If you set up a bogus destination MAC address your probes may not reach the intended targets.

1
  • Thanks for the comment but doesn't seems to be working on my case :( Commented Jul 13, 2018 at 6:56
1

The obvious way is to temporarily add a rule that will activate the table for the address or address range you want to ping:

ip rule add to 8.8.8.8 table ISP2
ping 8.8.8.8
ip rule del to 8.8.8.8 table ISP2

Note that as long as the rule is active, all traffic to 8.8.8.8 will go via this interface, so if you are actually using 8.8.8.8 as a nameserver somewhere, it might not work during that time.

You must log in to answer this question.

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