光猫ip:192.168.1.1
拨号路由:192.168.2.1
电脑如何访问光猫?
在路由器启动项里,添加下面二行代码即可:
ip address add 192.168.1.254/24 dev vlan2
iptables -I POSTROUTING -t nat -o vlan2 -d 192.168.1.0/24 -j MASQUERADE
如果极少访问光猫,也可以不在路由器上设置,当需要访问光猫的时候,直接在电脑上ssh登录光猫,然后执行上面二行代码,也可以。为了方便,我写了一个在pc端自动ssh登录路由,然后执行上面二行代码的vbs:
set wshshell=Wscript.CreateObject("WScript.Shell")
wshshell.Run "ssh admin@192.168.2.1"
Wscript.Sleep 1000
wshshell.SendKeys "路由器的ssh密码,一般同登录密码"
wshShell.SendKeys "{ENTER}"
Wscript.Sleep 1000
wshshell.SendKeys "ip address add 192.168.1.254/24 dev vlan2"
wshShell.SendKeys "{ENTER}"
Wscript.Sleep 1000
wshshell.SendKeys "iptables -I POSTROUTING -t nat -o vlan2 -d 192.168.1.0/24 -j MASQUERADE"
wshShell.SendKeys "{ENTER}"
Wscript.Sleep 1000
wshshell.SendKeys "exit"
将上面代码保存为.vbs,然后双击运行即可。
操作系统 win11,路由器K3,测试通过。
0 comments:
发表评论