Tweaks to force application-specific routing on linux using SO_MARK, advanced routing, LD_PRELOAD and file namespace mounting. It allows to route packets generated by socket-based application (almost any) using specicifed routing table. Supports application-specific DNS name resolution by substituting a modified resolv.conf for a namespace the app is running.
Full usage pattern to change default route and name servers for a specific program is the following:
ip rule add fwmark 10 table 100
ip route add default via 192.168.2.1 table 100
echo "nameserver 192.168.2.1" > /tmp/resolv.conf.2
newns sh -c "mount -n --bind /tmp/resolv.conf.2 /etc/resolv.conf; MARK=10 LD_PRELOAD=mark.so wget http://example.com"
this will launch wget with default gateway set to 192.168.2.1
and default nameserver set to 192.168.2.1
Compilation instructions are inside the sources. OpenWrt package makefile included.