Routing - allow hosts on different subnets to communicate

Hosts on different subnets must have entries in their routing tables that tells them where to send the traffic and that the traffic is valid to respond to.

Outgoing traffic that does not match anything in the routing table but has a gateway will go through that, and it will be dropped if there is no gateway. Incoming traffic will be dropped.

The subnet mask tells how a valid IP address is formatted. 255 tells that the value is fixed, a 0 that it can be anything.

So, if a host on 192.168.1.1 wants to communicate with a host on 192.168.2.1, then do this on 192.168.1.1, where ethX is replaced with the interface name from ip a or ifconfig:

route add -net 192.168.2.0 netmask 255.255.255.0 ethX

Now it is possible to ping the host from 192.168.1.1 to 192.168.2.1. But no answer will be sent, because 192.168.2.1 will not respond as a security measure because the sender IP address is not in the receiver routing table. So on 192.168.2.1 add the first senders subnet:

route add -net 192.168.1.0 netmask 255.255.255.0 ethX

Reference:
https://superuser.com/questions/860949/communicating-with-devices-on-a-different-subnet
https://www.cyberciti.biz/faq/linux-route-add/

This is a personal note. Last updated: 2025-11-13 21:55:30.



GitHub

My

GitLab

My

LinkedIn

My

Klebe.se

Don't forget to pay my friend a visit too. Joakim