You want to look into "transparent" vs. "isolating" proxies. Transparent proxies, like what you are trying to do, are strenuously discouraged as they leak packets. The Tor project has some discussion of the dangers, which include "Identity correlation through circuit sharing;" issues with the clipboard, particularly download managers and antivirus software; and perhaps other issues with software you are running.
There are ways to do it, if you insist. See that first link, which involves extensive use of iptables, and/or look into redsocks, transocks, or lcat (redsocks is probably the best - see the discussion at the lcat link). The correct approach is an isolating proxy, eg. Whonix, which uses a pair of virtual machines as a means of isolation. One machine is the virtual OS, the other is a virtual router. The Qubes OS is built around this approach. Isolation can be engineered to insure there are no packet leaks, and so is much more secure. Instead of toggling the proxy on one OS, you switch between virtual OS's, or your host and a virtual OS. An alternative to Whonix is Subgraph OS, which locks down the network so all packets go through Tor. You could run that in a virtual machine, keeping your host machine as is. (But be aware that Subgraph is still alpha.)
Another transparent proxy, by the way, which is in addition obfuscating, is shadowsocks. This is extensively used in China, much like VPN's are used. Rather than connecting to Tor, you need a server on the other end - shadwosocks provides both client and server software - but you don't need superuser status there, so it's easy to get a cheap shell account and set it up. You could also use redsocks for this approach, though it wouldn't be obfuscated. The best server software to go with it is dante-server, though that does need superuser status to install. (dante-server is an apt package in Ubuntu. There is a dante-client, but that's not transparent, so you would want redsocks.). One advantage of shadowsocks or dante/redsocks is that they will proxy UDP, while Tor is only TCP. But that's perhaps off topic.