pomocí IPtables:
1. Create, validate new group; add required users to this group:Create:
groupadd no-internet
Validate:
grep no-internet /etc/group
Add user:
useradd -g no-internet username
Note: If you're modifying already existing user you should run:
usermod -a -G no-internet userName
check with :
sudo groups userName
2. Create a script in your path and make it executable:Create:
nano /home/username/.local/bin/no-internet
Executable:
chmod 755 /home/username/.local/bin/no-internet
Content:
#!/bin/bash
sg no-internet "$@"
3. Add iptables rule for dropping network activity for group no-internet:iptables -I OUTPUT 1 -m owner --gid-owner no-internet -j DROP
Note: Don't forget to make the changes permanent, so it would be applied automatically after reboot. Doing it, depends on your Linux distribution.
4. Check it, for example on Firefox by running:no-internet "firefox"
5. In case you would want to make an exception and allow a program to access local network:iptables -A OUTPUT -m owner --gid-owner no-internet -d 192.168.1.0/24 -j ACCEPT
iptables -A OUTPUT -m owner --gid-owner no-internet -d 127.0.0.0/8 -j ACCEPT
iptables -A OUTPUT -m owner --gid-owner no-internet -j DROP
6. Make it permanentOne way to apply the iptables rule at boot is to add the rule as a service with systemd
cat /usr/lib/systemd/system/nonet.service
[Unit]
Description=Nonet group iptable update
After=network.target
After=xsession.target
After=iptables.service
After=shorewall.service
[Service]
Type=oneshot
RemainAfterExit=true
StandardOutput=journal
ExecStart=/bin/bash /home/user/Scripts/Nonet.iptables.sh