Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save willwhui/eb4df8c41110f0c10286001be19bb12e to your computer and use it in GitHub Desktop.
Save willwhui/eb4df8c41110f0c10286001be19bb12e to your computer and use it in GitHub Desktop.
让两个子网内的设备可以互通访问
@willwhui
Copy link
Author

基本参考:http://vod.sjtu.edu.cn/help/Article_Print.asp?ArticleID=1095

  • 小米路由器
    • 自身ip:192.168.31.225
    • 网段网关:192.168.28.1
    • 配置:目的ip=192.168.10.0,掩码:255.255.255.0,下一跳:路由器Y自身ip
  • Openwrt路由器
    • 自身ip:192.168.31.231
    • 网段网关:192.168.10.1
    • 配置:目的ip=192.168.20.0,掩码:255.255.224.0,下一跳:路由器X自身ip

在小米路由器设置允许访问Openwrt路由器

查看当前路由表:

root@XiaoQiang:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.31.0    *               255.255.255.0   U     0      0        0 eth0.2
169.254.29.0    *               255.255.255.0   U     0      0        0 wl1.3
192.168.28.0    *               255.255.255.0   U     0      0        0 br-lan
default         192.168.31.1    0.0.0.0         UG    0      0        0 eth0.2
default         192.168.31.1    0.0.0.0         UG    50     0        0 eth0.2

添加静态路由规则,并查看新的路由表:

root@XiaoQiang:~# route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.31.231
root@XiaoQiang:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     192.168.31.231  255.255.255.0   UG    0      0        0 eth0.2
192.168.31.0    *               255.255.255.0   U     0      0        0 eth0.2
169.254.29.0    *               255.255.255.0   U     0      0        0 wl1.3
192.168.28.0    *               255.255.255.0   U     0      0        0 br-lan
default         192.168.31.1    0.0.0.0         UG    0      0        0 eth0.2
default         192.168.31.1    0.0.0.0         UG    50     0        0 eth0.2

可见添加成功,自动绑定在eth0.2接口上

按照这里的提示http://www.miui.com/forum.php?mod=redirect&goto=findpost&ptid=2122469&pid=163834045
可以将静态路由设为开机自动配置

vi /etc/config/network

在文件末尾追加:

config route                 
        option interface 'eth0.2'
        option target '192.168.1.0'
        option netmask '255.255.255.0'
        option gateway '192.168.31.231'

在Openwrt路由器设置允许访问小米路由器

因为可以在luci界面进行设置,就直接设置了。
注意interface要选择Openwrt当初设置成为中继路由时创建的那个接口(wlanxxx)

然而按照上述方法设置好之后,都只能ping通gateway本身

无法ping通子网内的设备。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment