I expose here my project. I have a server running a ubuntu.
The server is set up with multiple VPN connection (tun0, tun1, tun2 ect) I use this to launch my VPNs: sudo systemctl start openvpn-client@The_VPN_I_Want.service I want to keep one user (1000) and RDP acces on eth0.
And route users through tunX interfaces. For example user 1002 on tun0, user 1003 on tun1.
I've restart my rules from 0.
So if i want to block the traffic (out) from eth0 for user 1002 i doing this:
sudo iptables -I OUTPUT -o eth0 -m owner --uid-owner 1002 -j REJECT
And if i want to allow the traffic (out) from tun0 i doing this:
sudo iptables -I OUTPUT -o tun0 -m owner --uid-owner 1002 -j ACCEPT
I'm right ? I'm not suppose to have acces with user 1002 from eth0 ?
From user 1002 session when i do a wget https://wtfismyip.com/text
My public ip is return not the VPN ip.
I'm little confuse right now :3
[EDIT] I'm dumb, my interface was ens33 not eth0 so i fix this and now i use this rules:
# Mark traffic user
iptables -t mangle -A OUTPUT -o eth0 -m owner --uid-owner 1002 -j MARK --set-mark 10
# Source 2 VPN address
iptables -t nat -A POSTROUTING -o tun0 -m mark --mark 10 -j MASQUERADE
# Forward 2 tun0
iptables -P FORWARD ACCEPT
iptables -A FORWARD -o tun0 -j ACCEPT
iptables -A FORWARD -i tun0 -j ACCEPT
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
So my user 1002 don't pass through tun0 because of the default route i think:
default via 192.168.0.254 dev eth0 proto dhcp metric 100
169.254.0.0/16 dev eth0 scope link metric 1000
172.18.11.1 via 172.18.11.37 dev tun0
172.18.11.37 dev tun0 proto kernel scope link src 172.18.11.38
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.117 metric 100