OpenWrt 配置记录

这里会增量记录 OpenWrt 相关的一些技巧或者配置方法。

内网设备直接访问光猫

在光猫桥接的情况下,一般 OpenWrt 和光猫的因为不在一个网段下,所以 OpenWrt 分配的 IP 并不能直接访问光猫。但是通过对 OpenWrt 防火墙进行相关的的配置可以实现访问光猫

准备

  • OpenWrt WAN 口: eth0
  • 光猫IP: 192.168.1.1

配置

登录 OpenWrt 后台。在 网络 -> 防火墙 -> 自定义规则 下添加以下内容

ifconfig eth0 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
iptables -I forwarding_rule -d 192.168.1.1 -j ACCEPT
iptables -t nat -I postrouting_rule -d 192.168.1.1 -j MASQUERADE

解释一下:

  1. 第一行 eth0 是 OpenWrt WAN 口
  2. 第一行 192.168.1.10 是手动分配给 eth0 一个光猫所在网段的 IP,可以时其他的地址,只要不和当前光猫网段下 IP 冲突就行
  3. 第二行和第三行 192.168.1.1 是光猫的 IP 地址

然后重启 OpenWrt,此时内网设备就可以通过浏览器访问 192.168.1.1 登录光猫后台了。

开启 Dnsmasq 日志

编辑 dnsmasq 配置 /etc/dnsmasq.conf 文件

添加以下内容

log-queries
log-facility=/tmp/dnsmasq.log

重启 dnsmasq 服务

/etc/init.d/dnsmasq restart

添加日志解析器

#!/bin/sh

tail -f -n 1 /tmp/dnsmasq.log

系统日志中屏蔽 crontab 相关日志

编辑系统配置 /etc/config/system

system 段中修改相关配置为以下内容

option cronloglevel '4'
option conloglevel '9'

然后重启 crontab 服务即可

/etc/init.d/cron restart