Skip to content

Instantly share code, notes, and snippets.

@cpthooch
Last active April 4, 2023 11:19
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save cpthooch/706943dfe9a62771f4c3ab5adecf2b5b to your computer and use it in GitHub Desktop.
Save cpthooch/706943dfe9a62771f4c3ab5adecf2b5b 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