This uses the linux specific TPROXY mechanism, if your desktop doesn't run linux you'll need to figure out the alternative.
In /etc/tor/torrc:
DNSPort 127.191.0.1:53
TransPort 9040
TransProxyType TPROXY
AutomapHostsOnResolve 1
Add iptables rules: iptables -t mangle -A PREROUTING -d 127.192.0.0/10 -j TPROXY --on-ip 127.0.0.1 --on-port 9040 -p tcp
iptables -t mangle -A PREROUTING -d 127.192.0.0/10 -j TPROXY --on-ip 127.0.0.1 --on-port 9040 -p udp
Make sure you start tor with relevant capabilities (I use systemd, so here is my override snippet): [Service]
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_ADMIN
Split horizon dns to send .onion lookups via the tor daemon. e.g. my dnsmasq config contains server=/onion/127.191.0.1
Note that some programs might need some coercing. e.g. firefox needs network.dns.blockDotOnion set to false in about:config (see https://twitter.com/mrphs/status/708548201800982528)