My Linux machine have two accounts. I want to set different default gateway for the different accounts. How can I do this, if it is possible?
The routing table is a system-wide thing, and not user-specific. So, it is not really simple.
The steps are the following:
1: Create the multiple routing tables with the extensive usage of the
ip route and
ip rule commands.
2: Set up iptables to mark the outgoing packets based on the UID of the sender process.
3: Set up your routing tables based on the marks (which the outgoing packets got from the iptables).
The solution will be that all processes belonging to an user will use the alternate routing table.
Extension #1: Unfortunately the
ip route and
ip rule isn't really well documented. But you can create multiple routing tables with their different rules. Beware: they are routing tables, a totally different thing as the iptables! And, the trick is that you can "mark" packets in iptables, which essentially means that you can give them a single integer value. And finally, you can set up iptables rules to route other ways (with other routing tables) the marked packets. It is clean, and a good functioning feature, but not really well documented.
Extension #2: AFAIK
ip rule is the command to handle the multiple routing table entities. With
ip route you can also set, into which routing table you want to insert (modify) a given route.
Extension #3: Changing the routing tables of outgoing packets by iptables is not trivial, this post does what also by me worked.