Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Iptables rule to unblock internet acess, and block it again 3600 seconds later

I do this, from my son's terminal, to sometimes give him internet access (disabled by default):
./unblockinternet.sh
<enter password>

with this script:
su -c "iptables -D OUTPUT -m owner --uid-owner son -j REJECT"


How to make that it automatically blocks networking again, say, 1 hour after? (It already blocks it again for user son after a reboot, but I also want to block it after 3600 seconds)

More precisely, how to add a timer to do su -c "iptables -A OUTPUT -m owner --uid-owner son -j REJECT" 3600 seconds later, without having to enter password at this time? Obviously I won't be precisely on his terminal 3600 seconds later exactly.
by

1 Answer

Amit8z4mc
If you have systemd you could write a small Unit file, say
/etc/systemd/system/unblockinternet.service holding
[Unit]
Description=unblock internet 1 hour
[Service]
Type=simple
ExecStartPre=/usr/sbin/iptables ...
ExecStart=/usr/bin/sleep 3600
ExecStop=/usr/bin/iptables ...


To start it enter systemctl restart unblockinternet and it will ask you to authenticate as root.

Login / Signup to Answer the Question.