Configure iptables to set default gateway for local network

I assume your IP subnet is 192.168.1.0/24, which means that all IP addresses starting with 192.168.1 are in the same L2 broadcast domain, that is, connected to the same switch.

Devices that are in the same IP subnet communicate directly with each other via layer 2 "connectivity", there is no layer 3 routing happening.

IPTables is a mechanism that performs firewalling on routed packets between different subnets. It does not see any traffic that same subnet hosts send to each other.

If you want to install a firewall between the two hosts, there are a couple of options:

  1. Move the hosts to different subnets (for example 192.168.1.0/24 and 192.168.2.0/24), and make the router route between the two subnets.
  2. Install two different Ethernet segments, and configure your router as a bridge between the segments. Then one can configure IPTables to filter packets between the two Ethernet segments.