```bash sudo addgroup no-internet sudo iptables -A OUTPUT -m owner --gid-owner no-internet -j DROP ```
to block `no-internet` Linux Mint 22.3 Cinnamon group Internet access, how can I still allow a given `localhost` port?
May 8, 2:12pm
To allow a specific localhost port (e.g., port 8080) for the no-internet group while still blocking all other internet access, you need to add an exception rule before the DROP rule in your iptables configuration.
Solution:
Run the following commands to allow traffic to a specific localhost port (replace 8080 with your desired port):
bash
# Allow localhost traffic on port 8080 for the no-internet group
sudo iptables -A OUTPUT -p tcp -d 127.0.0.1 --dport 8080 -m owner --gid-owner no-internet -j ACCEPT
sudo iptables -A OUTPUT -p udp -d 127.0.0.1 --dport 8080 -m owner --gid-owner no-internet -j ACCEPT
# Block all other internet access for the no-internet group
sudo iptables -A OUTPUT -m owner --gid-owner no-internet -j DROP
Explanation:
Allow Rule:
-p tcp or -p udp: Specifies the protocol (TCP or UDP).
-d 127.0.0.1: Destination is localhost.
--dport 8080: Destination port (replace 8080 with your port).
-m owner --gid-owner no-internet: Applies to the no-internet group.
-j ACCEPT: Allows the traffic.
Block Rule:
The DROP rule remains in place for all other traffic.
Persist the Rules:
To ensure the rules persist after a reboot, save them:
bash
sudo iptables-save | sudo tee /etc/iptables/rules.v4
Verify:
Check your rules with:
bash
sudo iptables -L OUTPUT -v -n
Notes:
If you want to allow all localhost traffic (all ports), use: