LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-04-2018, 03:50 PM   #1
boredazfcuk
LQ Newbie
 
Registered: Oct 2014
Posts: 7

Rep: Reputation: Disabled
iptables not dropping from specific device


Hi,

I've been scratching my head at this one for the past few weeks. No idea why it's happening. Maybe someone smarter than me can work it out...

So here's the background... I've got a smart TV with the YouTube Kids app on it in the kid's play room. I want to restrict the times of day that the kids can watch.

I've have a Debian 9 VM, which I've enabled ipv4 forwarding on. DHCP sets the TV's default gateway to the IP of the VM. I've created a couple of scripts which insert iptables rules, one to reject/drop traffic from the TV's IP and the other to allow traffic again.

block-tv:

Code:
/sbin/iptables -I FORWARD -s 192.168.1.x -i ens3 -j DROP
/sbin/iptables -I INPUT -s 192.168.1.x -i ens3 -j DROP
/sbin/iptables -I FORWARD -s 192.168.1.x -i ens3 -j REJECT
/sbin/iptables -I INPUT -s 192.168.1.x -i ens3 -j REJECT
allow-tv:

Code:
/sbin/iptables -D FORWARD -s 192.168.1.242 -i ens3 -j DROP
/sbin/iptables -D INPUT -s 192.168.1.242 -i ens3 -j DROP
/sbin/iptables -D FORWARD -s 192.168.1.242 -i ens3 -j REJECT
/sbin/iptables -D INPUT -s 192.168.1.242 -i ens3 -j REJECT
Using cron, I have set allow-tv to run at 6am and block-tv to run at 10am. I've confirmed that these scripts are being executed in syslog and can see the rules when running iptables -L

When the block rules are in place, the output of that command looks like this:

Code:
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  PlayRoomTV.home       anywhere             reject-with icmp-port-unreachable
DROP       all  --  PlayRoomTV.home       anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  PlayRoomTV.home       anywhere             reject-with icmp-port-unreachable
DROP       all  --  PlayRoomTV.home       anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
I've opened up a few videos, run the scripts manually, and can confirm that it blocks the videos, prevents browsing, etc... But this morning, even though the blocking rules were in place, the kids were still watching at at 12:30pm. The stuff they watch is usually 30-45mins long so I'm certain it's not cached. They've also been using the search function which can't be cached either.

Why would iptables not be dropping the data? Is it because the script is being run from cron? Is it because it's UDP traffic? Is it due to the connection already being established?

I'm just at a loss as to why this doesn't work. Ideas welcome.

Thanks.
 
Old 02-05-2018, 09:49 AM   #2
tocii.
LQ Newbie
 
Registered: Jan 2018
Distribution: Ubuntu, Mint
Posts: 27

Rep: Reputation: Disabled
Hi.

Debian VM is your router? Or your TV's packets go through the VM?
First give a static IP to your SMART tv, because if get another IP from DHCP, then you need to write another script...
Then make two simple bash script:

#!/bin/bash
iptables -D INPUT -s [your TV'S ip address] -j REJECT
iptables -D INPUT -s [your TV'S ip address] -j DROP
and make then make ACCEPT script.

After you need to setup the schedule with crontab, and thats all.
Hope i can help yu. (sry for my english.)
 
Old 02-06-2018, 04:00 AM   #3
boredazfcuk
LQ Newbie
 
Registered: Oct 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi, thanks for your reply.

The TV's packets go through the VM. The Debian VM forwards them on to its gateway address.

The TV has a reserved IP address via the DHCP config file:

Code:
host PlayRoomTV-LAN {
  option host-name "PlayRoomTV.home";
  ddns-hostname "PlayRoomTV";
  hardware ethernet xx:xx:xx:xx:xx:xx;
  fixed-address 192.168.1.x;
  option routers 192.168.1.n;
}
My scripts are working as they're creating the rules to drop traffic. My 'allow' traffic rules just delete the drop rules.

I've created a 2nd set of scripts to block my mobile, and these work perfectly. It seems it's something about the way YouTube is operating. Does IP tables not block existing connections, or is it because it's UDP?

It just doesn't make sense to me.
 
Old 02-06-2018, 08:50 AM   #4
tocii.
LQ Newbie
 
Registered: Jan 2018
Distribution: Ubuntu, Mint
Posts: 27

Rep: Reputation: Disabled
Add to the bash script last line: service iptables restart
 
Old 02-07-2018, 11:57 AM   #5
boredazfcuk
LQ Newbie
 
Registered: Oct 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by tocii. View Post
Add to the bash script last line: service iptables restart
iptables isn't a service on Debian so this doesn't work, unfortunately.
 
Old 02-09-2018, 09:06 AM   #6
tocii.
LQ Newbie
 
Registered: Jan 2018
Distribution: Ubuntu, Mint
Posts: 27

Rep: Reputation: Disabled
systemctl restart firewall.service
 
Old 02-10-2018, 04:54 AM   #7
boredazfcuk
LQ Newbie
 
Registered: Oct 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
I tried firewall.service and firewalld.service but these don't exist either

This system was installed with nothing but SSH server so it's only got core features/services on it.

I'm also running squid on there, but it's non transparent, and it's just so I can log the kids' mobile traffic (and block porn).
 
  


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
How do I allow only a specific ip with a specific mac on lan with iptables? tkmbe Linux - Networking 2 07-10-2012 05:20 PM
IPTABLES rerouting only specific ips to a specific internal pc paulspinsmash Linux - Networking 3 01-06-2011 09:59 PM
[SOLVED] iptables not dropping ip zamorac Linux - Security 5 05-01-2010 08:39 AM
router dropping connection at specific times cs-cam Linux - Networking 0 02-12-2006 09:17 PM

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

All times are GMT -5. The time now is 12:10 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