Skip to content

Instantly share code, notes, and snippets.

@maxguru
Created December 7, 2017 06:58
Show Gist options
  • Save maxguru/5ae1f74ec7b33d747a2d8b8687d21e0e to your computer and use it in GitHub Desktop.
Save maxguru/5ae1f74ec7b33d747a2d8b8687d21e0e to your computer and use it in GitHub Desktop.
Script that sets up a different default route for all processes of a particular user on the system
OTHER_IFACE="eth1"
OTHER_GW="10.0.3.2"
USER="xyz"
ip rule add fwmark 35 table 35
ip route add default via $OTHER_GW dev $OTHER_IFACE table 35
ip route flush cache
iptables -t mangle -A OUTPUT -m owner --uid-owner $USER -j MARK --set-mark 35
iptables -t nat -A POSTROUTING -o $OTHER_IFACE -m mark --mark 35 -j MASQUERADE
@maxguru
Copy link
Author

maxguru commented Dec 7, 2017

Requires the following on OpenWrt/LEDE,

Module for -m owner

# opkg install iptables-mod-extra

For adding a user and running as one,

# opkg install shadow-useradd
# opkg install sudo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment