基于Openwrt iptables 限速

孩子天天看pad怎么办,买一个阿里儿童路由器吗?功能太多,太复杂,太费钱。
20行搞定限定时长功能,路由器系统依托于Openwrt系统开发。

脚本文件:

#!/bin/ash

unallow()
{
    echo "noallow $1 access internet"
    iptables -t raw -D PREROUTING -s $1 -j DROP
    iptables -t raw -A PREROUTING -s $1 -j DROP
}

allow()
{
    echo "allow $1 access internet"
    iptables -t raw -D PREROUTING -s $1 -j DROP
}

if [ $1 == "allow" ] 
then
    allow $2
else
    unallow $2
fi

crontab如下:

30 12 * * * sh /root/allow.sh allow 192.168.10.100 
30 13 * * * sh /root/allow.sh unallow 192.168.10.100 
30 19 * * * sh /root/allow.sh allow 192.168.10.100 
30 20 * * * sh /root/allow.sh unallow 192.168.10.100 
30 21 * * * sh /root/allow.sh allow 192.168.10.100 
30 22 * * * sh /root/allow.sh unallow 192.168.10.100
OpenWrt is a Linux-based firmware for routers that provides a wide range of network features, including firewall capabilities using iptables. iptables is a command-line tool that allows you to configure firewall rules in Linux. To configure iptables on OpenWrt, you can use the following steps: 1. Log in to your OpenWrt router using SSH or the LuCI web interface. 2. Navigate to the Firewall section in the web interface or use the command-line tool to create firewall rules. 3. Create a new firewall zone that defines the rules for the traffic to be allowed or blocked. For example, you can create a "wan" zone for incoming traffic from the Internet, and a "lan" zone for traffic between devices in your local network. 4. Add rules to the firewall zone using the iptables syntax. For example, you can allow incoming SSH traffic from the Internet to a specific device in your local network using the following command: iptables -A zone_wan_input -p tcp --dport 22 -d 192.168.1.100 -j ACCEPT This rule allows incoming TCP traffic to port 22 (SSH) on the device with IP address 192.168.1.100 in the "lan" zone. 5. Save the firewall rules to the OpenWrt configuration file to make them persistent across reboots: /etc/init.d/firewall save 6. Restart the firewall service to apply the changes: /etc/init.d/firewall restart These are just some examples of how to configure iptables on OpenWrt. For more information and advanced configuration options, refer to the OpenWrt documentation or consult with a network administrator.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值