Accessing 192.168.1.x device from 192.168.0.x device

I have one device with an IP address of 192.168.1.110 while the rest of the network is 192.168.0.x. The router is 192.168.0.1. 192.168.1.110 is cabled to this router. Other devices connect via WiFi to 192.168.0.5 (Raspberry Pi access point) which is cabled to the same router on 192.168.0.1.

I'm trying to access 192.168.1.110 from a device on 192.168.0.x. I've tried adding a route which I can see in the routing table but no dice.
Using sudo route -n -v add 192.168.1.110 192.168.0.1 pings and SSH timeout.
Using sudo route -n -v add 192.168.1.110 192.168.0.5 SSH times out and pings show the below

PING 192.168.1.110 (192.168.1.110): 56 data bytes
Request timeout for icmp_seq 0
92 bytes from pi.hole (192.168.0.5): Redirect Host(New addr: 192.168.0.1)
Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst
 4  5  00 0054 1369   0 0000  3f  01 e4b7 192.168.0.202  192.168.1.110 

I've also tried changing the router mask to .254.0, taking the raspberry pi access point out of the loop but I'm still not able to access the .1.110 device.

If I change the router IP to .1.x and one of the .0.x devices then I can access the .1.110 device but none of the .0.x devices. I'm sure this should be simple but I can't work it out - what am I missing?


Solution 1:

Packets must go in both directions, so many kinds of configuration changes need to be done on both sides.

For example, if you change the netmask to /23 (255.255.254.0), it's not enough to do so on device A – yes, it will be able to reach the device B directly, but where will device B send a reply? If B still thinks it's on a /24, then it will keep trying to send a reply through a gateway.

Similarly: even if you add a correct route towards device B, that doesn't tell device B where to send a reply for device A. It will still use what it knows already.

Assuming you cannot reconfigure device B at all, but can at least read its configuration, there's 1½ ways of making this work.

  • If you know what "default gateway" IP address is configured in the offending device, add that address on your router's LAN interface – alongside the existing address. (This might be called an "alias" in some routers, or a "virtual IP" in others.)

    For example, if the the device wants to use 192.168.1.254 as its gateway:

    ifconfig en0 192.168.1.254 netmask 255.255.255.0 alias         # for FreeBSD
    
    ip addr add 192.168.1.254/24 dev eth0                          # for Linux
    

    The other common address is 192.168.1.1. One way to discover the correct address is to look what ARP requests the device is making.

  • If the device has no gateway configured at all, but you know at least its subnet size, you can 1) do the above with some arbitrary address in the same subnet, and 2) configure the router so that it'll masquerade (SNAT) all communications.

    This way the device will think it's communicating only with its own subnet.

    I don't know how to do that, but it'll involve pf or iptables NAT rules.