Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have two network devices aboard my macbook pro:

  1. WIFI (en1): Used for general traffic. Connects to an ip of 192.168.19.* via DHCP
  2. 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:

  1. 192.168.2.1
  2. 192.168.2.21
  3. 192.168.2.20
  4. 192.168.2.30

The rest of the traffic needs to go to WIFI. 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
share|improve this question

migrated from superuser.com Jun 22 '12 at 1:30

This question came from our site for computer enthusiasts and power users.

    
The OS handles routing, not the hardware. –  Ignacio Vazquez-Abrams Jun 15 '12 at 20:23
    
Is everything 192.168.2.X on the LAN? If it is, that makes the solution much simpler. –  ultrasawblade Jun 15 '12 at 20:36
    
@ultrasawblade Yes, everything on that network is 192.168.2.* –  jakebird451 Jun 15 '12 at 20:56

3 Answers 3

up vote 1 down vote accepted
+50

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.

share|improve this answer
    
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

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.

share|improve this answer
    
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. –  ultrasawblade Jun 16 '12 at 3: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.? –  ultrasawblade Jun 17 '12 at 1:10
    
Yes, WiFi is for general traffic such as google.com (primarily for the google maps api) –  jakebird451 Jun 17 '12 at 4:40

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!

share|improve this answer
    
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
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.