I'm trying to mimic the Windows firewall to define rules by software.
So a software has access to internet only if started by a specific group. I can then create a .sh file for each program that I want to access internet. By following this question How to control internet access for each program? I'm trying to block all programs access internet if not started by a specific group.
- I created a group has-internet (I did not join this group):
sudo addgroup has-internet
Restarted pc to be sure new group is well loaded
Add a rule to iptables that all processes not (!) belonging to the group has-internet from using the network (use ip6tables to also prevent IPv6 traffic)
sudo iptables -A OUTPUT -m owner ! --gid-owner has-internet -j DROP
sudo ip6tables -A OUTPUT -m owner ! --gid-owner has-internet -j DROP
Execute ping somesite.xyz
(can't connect GOOD! : )
Execute sudo ping somesite.xyz
(can't connect GOOD! : )
Execute sudo -g has-internet ping somesite.xyz
(can't connect BAD! : (
What am I doing wrong? Pls Help!!!
EDIT
I tried (just to experiment) to block the group and it works...
sudo iptables -A OUTPUT -m owner --gid-owner has-internet -j DROP
Execute sudo ping somesite.xyz
(can connect)
Execute sudo -g has-internet ping somesite.xyz
(can't connect)
I don't understand why this way works and the other way round doesn't.... ?
sudo -u newuser ping site.xyz
? (to run command as newuser, I always have to use sudo... Sorry I'm new to linux : o ! – codeispoetry Mar 07 '23 at 17:29