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
help chat
or to customize your list.
Log in
Sign up
1. Home
2. Questions
3. Unanswered
4. Tags
5. Chat
6. Users
7. Companies
Teams
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Try Teams for free Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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
asked
– David Schwartz
Commented May 19, 2014 at 19:56
– Sean256
Commented May 19, 2014 at 21:48
– David Schwartz
Commented May 19, 2014 at 22:39
– Sean256
Commented May 20, 2014 at 16:05
– David Schwartz
Commented May 20, 2014 at 16:58
10
67
Try:
route add -host 54.81.143.201 -interface en0
answered
This is what I get when I try that: route: bad address: en0
– Sean256
Commented May 19, 2014 at 17:42
– drkblog
Commented May 19, 2014 at 17:47
same thing sadly -> route: bad address: en0
– Sean256
Commented May 19, 2014 at 19:18
– drkblog
Commented May 19, 2014 at 19:36
– Sean256
Commented May 19, 2014 at 21:53
6
As others indicated, this is actually 3 problems.
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
– Sean256
Commented May 20, 2014 at 16:00
– 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
– 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 <<EOF | scutil | \
grep 'UserDefinedName' | \
awk -F': ' '{print $2}'
show Setup:/Network/Service/$1
EOF
}
function get_srvc_ids ()
{
cat <<EOF | scutil | \
sed -nEe '
/ServiceOrder/ {
:ids
n
/[0-9]+ :/ {
s/ *[0-9]+ : ([0-9A-Z-]+) */\1/p
b ids
}
}'
show Setup:/Network/Global/IPv4
EOF
}
function get_srvc_id_by_name ()
{
local srvc_ids=$(get_srvc_ids)
for srvc_id in $srvc_ids
do
local srvc_name=$(get_srvc_name "$srvc_id")
if [[ "$srvc_name" == "$1" ]]
then
echo $srvc_id
return
fi
done
}
function get_int_name ()
{
local srvc_id=$(get_srvc_id_by_name "$1")
cat <<EOF | scutil | \
sed -nEe '
s/ *DeviceName : ([a-zA-Z0-9]+) */\1/p'
show Setup:/Network/Service/$srvc_id/Interface
EOF
}
Then just call get_int_name 'Wi-Fi' to get the assigned device name.
For example:
route add -host 54.81.143.201 -interface $(get_int_name 'Wi-Fi')
answered
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
– Sean256
Commented May 19, 2014 at 17:45
. 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
See similar questions with these tags.
2
3
1
0
2
0
2
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Data
Blog
Site design / logo © 2025 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2025.5.1.25932