How can I ping via an alternate gateway?
Our network has two modems, each one hidden behind a router. The primary router is on 10.1.1.1, the backup router is on 10.1.1.2, and are both configured to the 10.1.1.0/24 subnet. Both routers have their gateway configured to 192.168.0.1. However, the 192.168.0.1 that you see if your gateway is 10.1.1.1 is a different machine from the 192.168.0.1 that you see if your gateway is 10.1.1.2.
My Nagios server is set up accordingly:
auto eth0
iface eth0 inet static
address 10.1.1.10
netmask 255.255.255.0
gateway 10.1.1.1
So to be clear: there are four gateways here. Router1 (10.1.1.1) Router2 (10.1.1.2) Modem1 (192.168.0.1) Modem2 (192.168.0.1)
Here's an illustration of what I can do manually to check the status of the two modems:
ping -c4 192.168.0.1 # Is Modem1 up?
ip route add via 10.1.1.2
ip route change default via 10.1.1.2
ping -c4 192.168.0.1 # Is Modem2 up?
wget 192.168.0.1 # yields expected control webpage for Modem2
ip route change default via 10.1.1.1
ip route del default via 10.1.1.2
wget 192.168.0.1 # Connection refused; Modem1 has no web interface
ssh [email protected] # I can log in to Modem1 and check status
I would like at a minimum to be able to ping Modem2.
*Edited to correct my abominable misuse of CIDR notation, and provide clear detail.
Solution 1:
Neither ping -N
nor arping
worked for me, I finally settled with the solution from this answer:
You can use the tool nping from the nmap package:
# nping --icmp --dest-mac [gateway mac] [target ip]
You can find your router's mac in your local ARP cache:
$ arp -v [gateway ip]
The tool also supports different ping types, like --tcp
or --udp
.
Solution 2:
man ping
ping [hop... ] destination
So you can give ping a number of IPs separated by white space as parameter. The last address will be "pinged"; the previous parameters define the route that ping should take.
So in your case:
- "ping 10.1.1.2 modem" to explicitly use the first gateway,
- "ping 10.1.1.1 modem" to explicitly use the second gateway.
If you encounter the same problem with Windows:
ping /?
-k
is the option you probably want.
BTW: The above ping does not require any root privileges. The routing information (in your case: the "whishlist") is part of the ICMP protocol.
Solution 3:
Sorry, you can only have one default gateway. You can have multiple gateways, but only one for every network.
The problem is, that both mentioned IPs are in the same network. Also you specified your CIDRs wrongly: You meant 10.1.1.0/24 as having a subnet of 255.255.255.0; or even have a bigger subnet e.g. 10.0.0.0/8 as being 255.0.0.0.
You can therefore ping any host inside your network (10.0.0.0/8) or any host reachable via a (or the) gateway. But having two gateways for the same network is not possible.