13

I have two network devices aboard my macbook pro:

  • WIFI (en1): Used for general traffic. Connects to an ip of 192.168.19.* via DHCP
  • LAN (en0): Used for specific traffic. Connects to an ip of 192.168.2.10 as a static IP. Does not connect to a router, only a switch for direct routing connection.

I have 4 IP addresses I need to access on the LAN:

  • 192.168.2.1
  • 192.168.2.21
  • 192.168.2.20
  • 192.168.2.30

The rest of the traffic needs to go to Wi-Fi. I have tried setting up a routing table for the specific ip addresses, but I only managed to mess up my network. I do not venture out into the world of networking too often, but this was the latest command I have been trying:

sudo route add -host 192.168.2.30 -interface en0

This command killed my ability to use ping. It told me that ping could not allocate memory (is that even possible)? It also killed my wifi access. Logging out and back in fixed the issue. I really do not mind to make this solution permanent, so I am fine with a temporary routing.

EDIT:

If I currently have been trying:

sudo route flush
sudo route add default 192.168.19.1

This gets everything to work for about a minute. But after such minute it "forgets" the routing to WiFi while retaining LAN's (en0) routing. If I unplug and replug my LAN (en0) cable, the process works for another minute.

EDIT 2:

These were some of commands entered as a request by d34dh0r53.

$ netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.2.1        UGSc            4        0     en0
default            192.168.19.1       UGScI           0        0     en1
127                127.0.0.1          UCS             0        1     lo0
127.0.0.1          127.0.0.1          UH              5  1429023     lo0
169.254            link#4             UCS             0        0     en0
192.168.2          link#4             UCS             4        0     en0
192.168.2.1        0:27:22:2e:5f:1a   UHLWIi          2        0     en0   1199
192.168.2.10       127.0.0.1          UHS             0        0     lo0
192.168.2.30       90:a2:da:0:f5:63   UHLWIi          1     1433     en0   1191
192.168.2.255      ff:ff:ff:ff:ff:ff  UHLWbI          0        7     en0
192.168.19         link#5             UCS             2        0     en1
192.168.19.1       3e:d0:f8:aa:28:56  UHLWIi          0        2     en1   1192
192.168.19.3       127.0.0.1          UHS             1        0     lo0
192.168.19.255     ff:ff:ff:ff:ff:ff  UHLWbI          0        5     en1

Internet6:
Destination                             Gateway                         Flags         Netif Expire
::1                                     link#1                          UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en0/64                           link#4                          UCI             en0
fe80::226:4aff:fe00:b68a%en0            0:26:4a:0:b6:8a                 UHLI            lo0
fe80::%en1/64                           link#5                          UCI             en1
fe80::226:bbff:fe03:cbd%en1             0:26:bb:3:c:bd                  UHLI            lo0
ff01::%lo0/32                           fe80::1%lo0                     UmCI            lo0
ff01::%en0/32                           link#4                          UmCI            en0
ff01::%en1/32                           link#5                          UmCI            en1
ff02::%lo0/32                           fe80::1%lo0                     UmCI            lo0
ff02::%en0/32                           link#4                          UmCI            en0
ff02::%en1/32                           link#5                          UmCI            en1
$ traceroute -n 192.168.2.1
traceroute to 192.168.2.1 (192.168.2.1), 64 hops max, 52 byte packets
 1  192.168.2.1  2.499 ms  3.392 ms  3.829 ms
$ traceroute -n google.com
traceroute: unknown host google.com
Giacomo1968
  • 3,542
  • 27
  • 38
jakebird451
  • 183
  • 1
  • 1
  • 9

3 Answers3

13

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.

  1. Go to System Preferences -> Network
  2. 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.

Giacomo1968
  • 3,542
  • 27
  • 38
rakslice
  • 473
  • 3
  • 11
  • Thank you! That was it! I had everything set up properly except for the in the router field. I put in the ip address `192.168.2.1` in the router field to match a "router" on the lan side. I thought it was required, but I see now that it took over the default route for general traffic. – jakebird451 Jun 26 '12 at 17:37
  • Thanks for this! Had the same problem and worked for me perfectly. – BaronVonKaneHoffen Aug 11 '15 at 12:34
5

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!

d34dh0r53
  • 1,781
  • 11
  • 11
  • Thank you for your lengthly response. The default route to `192.168.2.1` was the problem, but @rakslice found that I made a mistake while entering my routing information for the en0 connection. I put the ip address `192.168.2.1` in the router field in the believe that it was required. After removing the default router ip, I also removed the bad default route to `192.168.2.1`. Again, thanks for your help. – jakebird451 Jun 26 '12 at 17:48
  • 1
    Kind of bummed I didn't get the bounty: "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." But it's all good in the end, glad you got it working. – d34dh0r53 Jun 26 '12 at 19:13
0

You want to set your Wifi IP as your default gateway, and remove any default gateway (or route to 0.0.0.0) connected to the LAN or 192.168.2.0/24.

This is of course easier if you can set your en1 to a fixed IP that will work with the wifi.

You might have to add 192.168.2.10 as a route to the 192.168.2.0/24 network. However, this should be automatic since it can tell that 192.168.2.0/24 is directly connected by virtual of what you assigned to the interface.

So traffic going to any 192.168.2.X will go out of 192.168.2.10, and traffic going anywhere else will go out of your en1's IP address.

LawrenceC
  • 1,202
  • 7
  • 14
  • I set my wifi order to the top via the network sys preferences. But I am not sure how to `remove any default gateway connected to the LAN`. – jakebird451 Jun 15 '12 at 21:22
  • maybe `sudo route del default 192.168.2.10`?, not exactly sure how to do it on freebsd/mac osx but it should be similar. – LawrenceC Jun 16 '12 at 03:31
  • The command on mac is `sudo route delete default 192.168.2.10`. Ping is still active. However, it shutdown access to the wifi traffic excluding the router ip. – jakebird451 Jun 16 '12 at 20:25
  • You get internet through your wifi, correct, i.e. if you don't connect via LAN and only Wifi, you can reach external sites like Google, etc.? – LawrenceC Jun 17 '12 at 01:10
  • Yes, WiFi is for general traffic such as google.com (primarily for the google maps api) – jakebird451 Jun 17 '12 at 04:40
  • Can you please add the contents of `netstat -rn`, `traceroute -n 192.168.2.1` and `traceroute -n google.com` to your original question? – d34dh0r53 Jun 25 '12 at 02:57
  • @d34dh0r53 Thank you for your help. I posted an edit to my question with the commands you requested. – jakebird451 Jun 26 '12 at 01:05