#### Stack Exchange Network Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. Loading… - Tour Start here for a quick overview of the site - Help Center Detailed answers to any questions you might have - Meta Discuss the workings and policies of this site - About Us Learn more about Stack Overflow the company, and our products 2. current community your communities Sign up or log in to customize your list. more stack exchange communities company blog ### current community - Super User help chat - Meta Super User ### your communities or to customize your list. ### more stack exchange communities Log in Sign up 1. Home 2. Questions 3. Unanswered 4. Tags 5. Chat 6. Users 7. Companies 2. Teams Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Try Teams for free Explore Teams 3. Teams 4. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams Teams Q&A for work Connect and share knowledge within a single location that is structured and easy to search. # How to direct IP route through specific interface in OS X? 239k times 65 I'm on a mac and trying to route a particular address though a specific gateway on my wifi connection. I'm using: ``` route add -host 54.81.143.201 192.168.15.1 ``` Sometimes this will work, other times it wont. What I found is that the interface it chooses is different every time. It needs ot be en0 to work netstat -nr output when it doesn't work: ``` 54.81.143.201 192.168.15.1 UGHS 1 89 en5 ``` This is when it does work: (note en0) ``` 54.81.143.201 192.168.15.1 UGHS 0 1 en ``` Why am I doing this? Because our company has a proxy that HipChat doesn't work on. So I'm routing hipchat traffic through an open wifi network while still being on my works ethernet. EDIT: I also tried adding the entry using just the interface ``` route add -host 54.81.143.201 -interface en0 54.81.143.201 78:31:c1:c7:52:74 UHS 0 2 en0 ``` HipChat fails to connect. EDIT 2: Someone asked for my whole routing table, here it is today. Note that 54.81.143.201 is now bound to en3 and not en0 ``` Internet: Destination Gateway Flags Refs Use Netif Expire default 10.7.90.1 UGSc 31 6 en3 10.7.90/24 link#4 UCS 4 0 en3 10.7.90.1 0:23:ac:3d:db:c2 UHLWIir 16 0 en3 1200 10.7.90.44 40:6c:8f:19:4a:bb UHLWI 0 3 en3 946 10.7.90.63 127.0.0.1 UHS 0 0 lo0 54.81.143.201 192.168.15.1 UGHS 0 0 en3 127 127.0.0.1 UCS 0 0 lo0 127.0.0.1 127.0.0.1 UH 3 209 lo0 169.254 link#4 UCS 1 0 en3 169.254.255.255 0:23:ac:3d:db:c2 UHLSW 0 0 en3 ``` - macos - routing asked - Post the full routing table for the case where it doesn't work. Is 192.168.15.1 reachable through en5? If so, why doesn't it work? If not, it's hard to see how that route got added. – David Schwartz Commented May 19, 2014 at 19:56 - @DavidSchwartz, that's what is interesting to me. 192.168.15.1 is not reachable through en5. The thing works when it correctly gets assigned to en0. – Sean256 Commented May 19, 2014 at 21:48 - Show us the routing table or the configuration of en5. There must be some reason the route is getting installed that way, and that's probably the real problem. – David Schwartz Commented May 19, 2014 at 22:39 - @DavidSchwartz It's not always en5, sometimes it's en3. I'm posting my whole routing table now. – Sean256 Commented May 20, 2014 at 16:05 - In the routing table you showed, en3 is clearly correct. 192.168.15.1 isn't reachable through any other interface. The only way to reach 192.168.15.1 in that routing table is through the default route, right? (Bluntly, it sounds like you have no idea what you are doing. You seem to be surprised that the system is not doing the impossible.) – David Schwartz Commented May 20, 2014 at 16:58 ## 10 Answers 10 67 Try: ``` route add -host 54.81.143.201 -interface en0 ``` answered - 4 This is what I get when I try that: route: bad address: en0 – Sean256 Commented May 19, 2014 at 17:42 - Sorry I don't have a Mac to test this. It looks like the syntax was wrong. I modified the answer. Please try again. – drkblog Commented May 19, 2014 at 17:47 - 2 same thing sadly -> route: bad address: en0 – Sean256 Commented May 19, 2014 at 19:18 - Try again. This time I removed the gateway. Also, could you add the ifconfig output to your question to see IP configuration involved? – drkblog Commented May 19, 2014 at 19:36 - I just tried that (Actually I have before too) and it does add an entry to my table, it doesn't solve the issue. HipChat fails to connect. Here is the entry in the routing table when doing it that way ->54.81.143.201 78:31:c1:c7:52:74 UHS 0 2 en0 – Sean256 Commented May 19, 2014 at 21:53 6 As others indicated, this is actually 3 problems. 1. Your wireless interface seems to be changing between en0, en3, and en5. On my MacBook Air, en0 is always wireless; Thunderbolt-to-Ethernet is always en3, and USB-to-Ethernet is always en5. But if you plug in an adapter to a different port on your Mac, then its NIC name changes. You need to solve this first. Make sure your wireless always has the same name. Otherwise when you enter the static route command, if there is no NIC plugged in to the en0 location, the command will (obviously) fail with an "address error" (physical address has no link). Likewise, make sure the adapter is always connecting to the same SSID. The gateway address obviously has to be valid for the subnet, and different WiFi networks will have different subnets. This can cause another type of error. You didn't specify if wireless is your only network connection. Given the above, I guess not...? This and virtual networking due to VMware or Parallels can cause additional complexities. (For example, if both connected networks use the same IP space... Virtual machines often are bridged and have their own IPs/routes/links...) Posting network topology would help. 2. Once that's done, try either sudo route add -host 54.81.143.201 -iface en0 or sudo ipfw . If you're not sure of the adapter's name, you can specify its MAC address instead, like this: sudo route add -host 54.81.143.201 -link 14:10:9f:e7:fd:0a Related: https://discussions.apple.com/thread/5049994?searchText=policy%20route 3. If you reboot, this may not persist. You'll need to handle that separately. answered 5 ``` sudo route -n add -net 54.81.143.201/32 192.168.15.1 ``` answered 3 I was able to add a route across an interface by using the -link option to specify a MAC address. route add -host 54.81.143.201 -link [mac addr of 192.168.15.1 on en0] That will send traffic for 54.81.143.201 out the appropriate interface. You do have two separate 192.168.15.* host addresses assigned, one to each interface, right? Else, you may send traffic out of either interface, but traffic will return on whichever source IP the packets have. answered - So I tried what you suggested by using the mac addr, and oddly my routing table shows an entry for en3 and not en0 ->54.81.143.201 00:1d.88.4a.21.da UGHS 0 0 en3 – Sean256 Commented May 20, 2014 at 16:00 - When you do an 'arp -an', what entries do you have...? – Nevin Williams Commented May 20, 2014 at 19:04 2 This solution works on latest MacOS 10.12 (Sierra). Here's the Gist. ``` #!/bin/bash # NOTE: wifi network interface is: en1 wifi_router=192.168.200.1 wifi_address=en1:ec.35.86.4f.00.cc TOADDR=`ifconfig en1 inet | sed -nl 's/\w*inet \([^ ]*\).*/\1/p'` TO=`echo -n ${TOADDR//[[:space:]]}` echo "ADDING ROUTE TO $1 VIA en1 (wi-fi): $TO" route -n add -host $1 $wifi_router -ifp $wifi_address -ifa $TO -static echo "" echo "ROUTE ADDED:" route get $1 ``` Use like this: ``` > sudo ./route_wifi.sh IP_ADDRESS ``` It assumes that wifi interface is: en1. Don't forget to put correct values for wifi\_router and wifi\_address variables. Note wifi\_address format, which is: network interface name':'interface mac address with '.' delimiters. Sure most of required information can be parsed out of ifconfig command output, but I'm just too lazy for that =) answered - Welcome to Superuser. Please try to contain most relevant information from the link in your post. Read more about it here. – styrofoam fly Commented Aug 21, 2017 at 10:08 1 The OS X route command is documented here. The -ifscope parameter and its value allow you to specify an interface-bound route. This is, however, not what you want. You need to fix your networks so their IP ranges are unique. Other than that, interface metrics (aka priorities) affect which interface is chosen from otherwise equally opportune option. answered 0 Here's how to translate the user-defined name 'Wi-Fi' into whatever device name (e.g. en0, en1, en9, ...) that MacOS has assigned at that time. You can put these functions in a specific script, or just keep them in your .bash\_profile. ``` function get_srvc_name () { cat < 0 On macos 14.2.1 (23C71), I added a subnet to my home vpn as follows: ``` sudo route -n add -net 192.168.253.0/24 -iface ppp0 ``` answered -1 So the vendor server you're trying to talk to regarding the service "HipChat" you claim is 54.81.143.201? In this case, I'd make a routing entry for 54.81.143.0 255.255.255.0 to give it a bigger range. Maybe when using the software, you aren't always talking to this specific server, but a cluster of them on the same subnet 54.81.143.0/24. Also, additionally, make sure your route metrics are correct when creating a new entry. If you create a route to 54.81.143.0/24 192.168.15.1 Metric 20 En5, but also have a route to 0.0.0.0/0 10.7.90.1 Metric 10 En0. The computer will ignore your new entry and continue routing traffic through the default route (via En0) because its more preferable. I just skimmered through this and wanted to point that out. Cheers! answered -1 You should try adding the NIC name: ``` route add -net 10.13.0.0 netmask 255.255.0.0 dev NicNameHere ``` This works for me in CentOS. answered - I get this -> route: bad address: dev – Sean256 Commented May 19, 2014 at 17:45 ## You must log in to answer this question. . Earn 10 reputation (not counting the ) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity. Start asking to get answers Find the answer to your question by asking. Explore related questions - macos - routing See similar questions with these tags. - The Overflow Blog - How self-supervised language revolutionized natural language processing and... - “We’re not replacing you; we’re with you”: Where AI meets infrastructure - Featured on Meta - Updates to advertising guidelines - Evolving comments: An experiment to encourage engagement and follow-up questions #### Related 2 3 1 0 2 0 2 #### Hot Network Questions - How to handle teammates pressuring me (even publicly) to redo my work after I already explained my reasoning? - Output the 32 points of the compass - How can I fill a 4 inch gap between carpet and vinyl flooring? - Is there an epistemic difference between "unintuitive" and "counterintuitive" samples/cases? - How do you create episodic/procedural campaigns? - Diagonalizing Pascal's triangle - Is it legal for the president to charge different people different tariffs? - Pronunciation of וּמְלֹאוֹ - John 14:13: Pray to Jesus or the Father? - Protecting Secrets in Lost F/A-18 Super Hornet - Chern classes in Čech cohomology - What happens to an almost finished PhD thesis? - How has the rotation of Earth been accounted for in the theory of gravitational time dilation? - How to read a line from a file and output the line to a file - Retrieving connected components from list of neighbors - What does "Transparent selection" do in MS Paint? - Why is Qxb2 so much better than Bxb2? - Integro-differential equation of one function of one variable with periodic condition - Do limits leave residual infinitesimals, or do they resolve exactly? - Is there a way to get \marginpar to work with enumext*? - Medieval isekai manhwa about a woman who works in a palace as a florist - How to identify which USB device is failing - How do I calculate the equivalent resistance between this pair of nodes? - Has our understanding of genetics damaged existentialism? # Subscribe to RSS To subscribe to this RSS feed, copy and paste this URL into your RSS reader. ##### Super User - Tour - Help - Chat - Contact - Feedback ##### Company - Stack Overflow - Teams - Advertising - Talent - About - Press - Legal - Privacy Policy - Terms of Service - Cookie Settings - Cookie Policy ##### Stack Exchange Network - Technology - Culture & recreation - Life & arts - Science - Professional - Business - API - Data - Blog - Facebook - Twitter - LinkedIn - Instagram Site design / logo © 2025 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2025.5.1.25932