Already marked solved, but for the sanity of anyone else running into this issue, I thought I'd elaborate here and explain the actual cause of the problem you discovered. The issue is with iptables. Specifically, it does not handle group ID filtering as us humans expect it to. I'm not sure if it's WAD or a bug. IMHO, it's a bug in the iptables -m owner extension code.
The issue is with the handling of --gid-owner. It appears the iptables extensions code does not filter the group id literally (i.e. is user in this group, yes or no?). It's apparent from the module's behavior that it digs deeper and examines the username settings, and then makes a decision based on primary group membership of the user. That is versus a literal examination of the list of group members (expected by myself and others who've had this problem). This behavior is not documented in any of the relevant man pages.
To wit, Ubuntu's implementation of iptables only examines the primary group of the owner of the current network packet. Let's say you wish to create a split VPN, where a specific user group vpn will have its traffic forced to the VPN interface.
If you were to specify each owner, the --uid-owner parameter under the -m owner extension will work as expected. Then let's say you have multiple usernames that you want to branch, and the user list may change over time. So, you decide it would be more efficient to use group id filtering instead (--gid-owner). You place all your VPN traffic users into a single group called vpn and change the iptables parameter to --gid-owner vpn. As you've seen, in many cases the filter fails to perform as expected. Why?
Only the primary/default group of the owner of the packet will be compared. Therefore, any username you added to your vpn group after the user was created will be in the vpn group as a secondary user, and they won't be branched even though they are a member of the group!
The reason the 'root' user didn't work for you is because its primary/default group is 'root'.
Illustrated Example
Say you have username vpn in primary group vpn and username testdummy in primary group test but testdummy is also a member of the vpn group. To testdummy, vpn is a secondary group.
This iptables rule will mark packets belonging to the vpn user but not the testdummy user, even though instinctively one would think packets from both users would be marked because they both belong to group vpn:
iptables -t mangle -A OUTPUT ! -d 192.168.1.1 -m owner --gid-owner vpn -j MARK --set-mark 0x1
To solve the problem, you will have to create another rule, such as this solution:
iptables -t mangle -A OUTPUT ! -d 192.168.1.1 -m owner --gid-owner vpn -j MARK --set-mark 0x1 iptables -t mangle -A OUTPUT ! -d 192.168.1.1 -m owner --uid-owner testdummy -j MARK --set-mark 0x1
iptables -A OUTPUT -j LOGto log any dropped packet and compare it with your rule? You may also try using nc or telnet (i.e. "telnet 8.8.8.8 53") to check if it works.iptables -Lmay help.