LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-01-2021, 07:31 PM   #1
rcx11
Member
 
Registered: Oct 2006
Location: Louisana, USA
Distribution: Fedora 34 x86_64, new to Raspbian
Posts: 83

Rep: Reputation: 15
Blocking Internet traffic for specific users while allowing local traffic


Though I've been a linux user for over a decade, I've yet to have to truly deal with iptables. I'm trying to setup a new Raspberry Pi with iptables rules as described here in order to block my son's access to the internet but maintain access to local network resources. After installing ufw, enabling it, and applying the rules as described, I'm still able to reach the internet. What could be wrong?
 
Old 07-01-2021, 11:42 PM   #2
MikeDeltaBrown
Member
 
Registered: Apr 2013
Location: Arlington, WA
Distribution: Slackware
Posts: 96

Rep: Reputation: 10
I'm guessing the computer you added these rules to is connecting to the internet through a gateway/modem separate from the computer your son is using.

I looked at your StackExchange reference; did you verify the following files:
/etc/group
/home/username/.local/bin/no-internet

Note that in order for this to block access, programs have to be started like the example:
Code:
no-internet "firefox"
This doesn't seem too secure to me.
To block all user's access to the internet, leave the gateway address blank. That is only used to send packets "off-network".
Another way would be to add a firewall rule:
Code:
iptables -I OUTPUT ! -d 192.168.1.0/24 -j REJECT
Change 192.168.1.0/24 to your LAN network address CIDR.

Last edited by MikeDeltaBrown; 07-01-2021 at 11:43 PM.
 
Old 07-01-2021, 11:51 PM   #3
rcx11
Member
 
Registered: Oct 2006
Location: Louisana, USA
Distribution: Fedora 34 x86_64, new to Raspbian
Posts: 83

Original Poster
Rep: Reputation: 15
This is being performed on the same machine. I'm using my account to set the rules, and then switching to his account to see if the changes took effect. Files were verified.
Code:
$ cat /etc/group
...
son:x:1001:
no-internet:x:1002:son
$ sudo cat /home/son/.local/bin/no-internet
#!/bin/bash
exec sg no-internet "$@"
$ sudo ls -l /home/son/.local/bin
total 4
-rwxr-xr-x 1 son son 37 Jul  1 18:21 no-internet
 
Old 07-02-2021, 12:41 AM   #4
MikeDeltaBrown
Member
 
Registered: Apr 2013
Location: Arlington, WA
Distribution: Slackware
Posts: 96

Rep: Reputation: 10
I think the problem is the wrapper script isn't being called. As an example, try these two commands (or just think about them):

1) ping 8.8.8.8

2) no-internet "ping 8.8.8.8"

(1) should work, (2) should not.... assuming everything else is right.

One more thing to check;
Code:
echo $PATH
and make sure "/home/son/.local/bin/" is at the beginning.
 
Old 07-02-2021, 10:00 AM   #5
rcx11
Member
 
Registered: Oct 2006
Location: Louisana, USA
Distribution: Fedora 34 x86_64, new to Raspbian
Posts: 83

Original Poster
Rep: Reputation: 15
I did check the PATH, and /home/son/.local/bin is at the beginning. (1) did return successful pings. (2) returned "Operation not permitted". However, opening Chromium, I was able to successfully browse the internet, which is what I'm trying to deny. My son will not be opening a terminal to start his programs.
 
Old 07-02-2021, 10:56 PM   #6
MikeDeltaBrown
Member
 
Registered: Apr 2013
Location: Arlington, WA
Distribution: Slackware
Posts: 96

Rep: Reputation: 10
So the method works as advertised. The problem is that you'd have to write wrapper scripts for every program that your son may run. Ugh! That's alot of work. Probably just easier to remove the default route (mentioned in the middle of my first post.
 
Old 07-04-2021, 04:42 PM   #7
rcx11
Member
 
Registered: Oct 2006
Location: Louisana, USA
Distribution: Fedora 34 x86_64, new to Raspbian
Posts: 83

Original Poster
Rep: Reputation: 15
Is there another method that you know that would achieve the same effect? I want to allow network resource access while blocking internet access on a per-user basis.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] DHCP server configuration allowing and blocking DNS for its specific clients rohitchauhan Linux - Server 4 02-27-2013 11:33 PM
phpMyAdmin not allowing logins from users setup to specific databases. snooze1 Linux - Newbie 4 04-14-2012 05:07 AM
Blocking mail to specific domain from specific user orko Linux - Server 0 03-26-2009 02:18 PM
Allowing only certain hosts / domains while blocking the rest using IPTables? lolmannz Linux - Networking 2 10-19-2008 12:16 PM
blocking specific websites, but allowing internet access poiuytrewq Linux - General 6 08-31-2006 11:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration