Keeping traffic on a local segment

Opinion
Oct 25, 20042 mins

We have a physical subnet that contains a group of Linux systems with IP addresses from multiple IP subnets, which all share the same default router gateway setting. When any two of these machines talk to each other, the traffic goes past the local switch to the router and back, even though both machines are connected to the same switch. Can we keep this traffic on the local segment without making changes to the IP addresses or the network mask settings?

IP network nodes determine the scope of the local subnet by consulting the network mask setting. So even though your machines are connected to the same physical segment, the configuration settings are telling the IP stacks that they are on different subnets and the packets are forwarded to the default router for delivery.

If you adjust the default route setting to point to the local machine itself, the traffic will not leave the physical subnet when both machines are connected to the same switch as you describe.

To try this, log on at the console and delete the default route with the command ‘route del default’. Then add the new default route with the command

route add default gw myhostname metric 0