Skip to content

Instantly share code, notes, and snippets.

@cute
Forked from cpthooch/route_wifi.sh
Created September 26, 2018 05:58
Show Gist options
  • Save cute/dbac4f2cf07c138a5053ebf749f3a491 to your computer and use it in GitHub Desktop.
Save cute/dbac4f2cf07c138a5053ebf749f3a491 to your computer and use it in GitHub Desktop.
Routing all traffic to particular IP address via wifi network interface on MacOS
#!/bin/bash
# NOTE: wifi network interface is: en1
wifi_router=192.168.200.1
wifi_address=en1:ec.35.86.4f.00.bc
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment