报告路由器的运行状态

网络示意图:报告路由器的运行状态

运行指定的show相关命令的结果,定期的以邮件的形式发送给管理员。
可以定期确认在远处的路由器的运行情况。

RTX1200的设置例

LAN的
接口的设置
(使用LAN1接口)

ip lan1 address 192.168.0.1/24

WAN的
接口的设置
(使用LAN2接口)

pp select 1
pp always-on on
pppoe use lan2
pp auth accept pap chap
pp auth myname(连接ISP的ID) (连接ISP的密码)
ppp lcp mru on 1454
ppp ipcp ipaddress on
ppp ipcp msext on
ip pp mtu 1454
ip pp nat descriptor 1
pp enable 1
ip route default gateway pp 1

NAT的设置

nat descriptor type 1 masquerade

DHCP的设置

dhcp service server
dhcp scope 1 192.168.0.2-192.168.0.100/24

DNS的设置

dns server(ISP指定的DNS服务器地址)
dns private address spoof on

过滤的设置

ip filter source-route on
ip filter directed-broadcast on
ip filter 1010 reject * * udp,tcp 135 *
ip filter 1011 reject * * udp,tcp * 135
ip filter 1012 reject * * udp,tcp netbios_ns-netbios_ssn *
ip filter 1013 reject * * udp,tcp * netbios_ns-netbios_ssn
ip filter 1014 reject * * udp,tcp 445 *
ip filter 1015 reject * * udp,tcp * 445
ip filter 1020 reject 192.168.0.0/24 *
ip filter 1030 pass * 192.168.0.0/24 icmp
ip filter 2000 reject * *
ip filter 3000 pass * *
ip filter dynamic 100 * * ftp
ip filter dynamic 101 * * www
ip filter dynamic 102 * * domain
ip filter dynamic 103 * * smtp
ip filter dynamic 104 * * pop3
ip filter dynamic 105 * * netmeeting
ip filter dynamic 106 * * tcp
ip filter dynamic 107 * * udp
pp select 1
ip pp secure filter in 1020 1030 2000
ip pp secure filter out 1010 1011 1012 1013 1014 1015 3000 dynamic 100 101 102 103 104 105 106 107 # 注释1
pp enable 1

Lua脚本的启动设置

schedule at 1 startup * lua(Lua脚本文件名)

Lua脚本例

设置值

-- 监控间隔 (1-864000 秒)
idle_time =(监控间隔)

-- 列出show系列的命令,用逗号分隔
cmd_tbl = {
 "(show系列命令1)",
 "(show系列命令2)"
}

-- 邮件的设置
mail_tbl = {
   smtp_address = "(SMTP服务器地址)",
   smtp_auth_name = "(邮箱用户名)",
   smtp_auth_password = "(邮箱密码)",
   smtp_auth_protocol = "(验证方式)",     #验证方式一般为plain
   from = "(发件人邮箱)",
   to = "(收件人邮箱)"
     }

-- 邮件发送失败时,输出的SYSLOG的等级(info, debug, notice)
log_level = "(SYSLOG等级)"

输出命令运行结果
的函数

function exec_command(cmd)
 local rtn, str

 rtn, str = rt.command(cmd)
 if (not rtn) or (not str) then
  str = "exec failed.\r\n"
 end

 return rtn, string.format("# %s\r\n%s\r\n", cmd, str)
end

取得当前时间的函数

function time_stamp()
 local t

 t = os.date("*t")
 return string.format("%d/%02d/%02d %02d:%02d:%02d",
  t.year, t.month, t.day, t.hour, t.min, t.sec)
end

主程序

local rtn, str

while (true) do
 mail_tbl.text = ""
 for i, cmd in ipairs(cmd_tbl) do
  rtn, str = exec_command(cmd)
  mail_tbl.text = mail_tbl.text .. str
 end

 mail_tbl.subject = string.format("summary of show commands (%s)", time_stamp())
 rtn = rt.mail(mail_tbl)
 if (not rtn) then
  rt.syslog(log_level, "failed to send mail.(Lua脚本文件名)")
 end

 rt.sleep(idle_time)
end

返回顶部