【问题标题】:Block port every twenty minutes for a couple of seconds每二十分钟阻塞端口几秒钟
【发布时间】:2014-01-10 16:22:12
【问题描述】:
我希望能够每隔 10 到 20 分钟(任意数量)阻塞我们家庭网络的特定数量的端口,持续几秒钟(同样不是很重要)。
原因是我儿子玩电脑游戏太多,他同意每周只玩两次,但几乎每天都玩。我理解退出游戏并不“好”,因为这样一个人就被同龄人称为“投掷者”或其他东西。 (他经常告诉我,如果我拔掉插头,他们会打电话给他)。所以通过上面描述的方法,我打算用这种同伴压力风格的武力让他遵守我们的协议。如果我以上述方式阻止端口,他将始终能够开始游戏,但几分钟后就会被踢出游戏,我希望他因此不会尝试在休息日和仅在我们的日子里玩同意。
我知道我可以阻止他们,让我们整天说 mo-thu 和 sa,但是这对我来说更像是一种强制控制。通过另一种方法,它更像是一个同行的事情,我希望他更有可能坚持。我不想禁止他玩我只是想让他在那段时间不想玩(因为那时他会继续被称为滴管)
【问题讨论】:
标签:
networking
port
router
【解决方案1】:
您没有告诉我们您使用的是什么路由器。我会给你命令在 Linux 中设置它,使用 iptables 和 recent 模块。
您必须相应地更改$port_to_block、$play_seconds 和$stop_seconds。
iptables -N PLAY_CHECK
iptables -N PLAY_START
iptables -N PLAY_STOP
iptables -A FORWARD -p tcp --dport $port_to_block -j PLAY_CHECK
iptables -A PLAY_CHECK -m recent --name NOT_PLAYING --rcheck --seconds $stop_seconds -j DROP
iptables -A PLAY_CHECK -m recent --name PLAYING ! --rcheck -j PLAY_START
iptables -A PLAY_CHECK -m recent --name PLAYING --rcheck --seconds $play_seconds -j ACCEPT
iptables -A PLAY_CHECK -j PLAY_STOP
iptables -A PLAY_START -m recent --name NOT_PLAYING --remove
iptables -A PLAY_START -m recent --name PLAYING --set
iptables -A PLAY_START -j RETURN
iptables -A PLAY_STOP -m recent --name PLAYING --remove
iptables -A PLAY_STOP -m recent --name NOT_PLAYING --set
iptables -A PLAY_STOP -j DROP