Routing WIFI and LAN for specific traffic
Solution 1:
You shouldn't need to create any routing rules by hand for that configuration, provided that all the 192.168.2.x addresses you want to communicate with are down the interface with the 192.168.2.x address.
- Go to System Preferences -> Network
- Select your Ethernet device, make sure "Configure IPv4" is set to "Manually", that your subnet mask is set to 255.255.255.0, and that the router box is empty.
Once this is done, netstat -rn
should still show the routes for both of the subnets, but only a "link#4" route in place of the default route through 192.168.2.1.
If you don't want a default route, leave the router box blank. The value in the router box is only used to set up a default route through this network interface, and it isn't used for anything else.
Solution 2:
The problem is that your en0
interface is adding a default route which is taking precedence over the default route established by the 802.11 interface. I'm not exactly sure why, but it's either the fact that BSD is preferring a wired interface over a wireless one, or it's preferring a statically configured interface over a dynamically configured one. You can tell that the en0
default route is being used by the Refs
column; Refs
is a metric indicating the current number of active uses of the route, so we can see that it's getting all of the traffic.
The solution is to remove that route, preferable permanently from the routing table so that traffic that is destined for hosts other than those on your local networks traverses the default gateway established by DHCP on en1
. The first thing I would check is in the configuration panel for en0
make sure that you have not entered anything in the router
field. The information in that field is added as a default gateway. If that does not work we need to manually delete the route, the reason that route flush
does not work is that I believe it tells OS X to reload it's routing information from the interface configuration files, hence reverting your change after a short time. The following command should remove the default route for the en0
interface until either networking is restarted or the system is IPLed:
sudo route delete -net 0.0.0.0 192.168.2.1
If you want to make this change permanent you can either a) create a service in /Library/StartupItems
which seems like too much work to me or b) add that line to /etc/rc.local
with a command such as:
echo 'route delete -net 0.0.0.0 192.168.2.1' >> /etc/rc.local
You may need to add a sleep <number_of_seconds>
command before that line in /etc/rc.local
to avoid running the command before the interfaces are fully up and the routing table established.
Hope this helps and good luck!