路由器更换wan口及vlan配置

情况:

在给新的硬件烧录固件并测试性能的过程中,因为新的设备只有两个网口,测试下来发现两个网口互通,在一个vlan下。

导致两个网口只能设置成一种模式,要么是wan口,要么是lan口。wan口状态下可以收到上级路由的dhcp,但同时接入的pc也能收到上级路由的dhcp。如果是其他连接方式的话导致下级pc可能无法正常联网。

分析:

测试下来不管怎么配置,总是感觉两个端口在一个网段上。感觉是vlan的原因。

尝试:

1、在etc/config/network中配置vlan

config switch
        option name 'vlans'
        option enable_vlan '1'

config switch_vlan
        option device 'vlans'
        option vlan '1'
        option ports '0'

config switch_vlan
        option device 'vlans'
        option vlan '2'
        option ports '1'

没有任何效果

2、更换uboot

在日志列表中看到uboot启动时有提示 SET WAN/LAN LLLLW,便在uboot编译时更换模式为WLLLL,编译烧录。

结果每次启动好之后呗程序修改了,日志上开机上电时打印WLLLL,启动好时打印LLLLW。没有用

3、更改固件配置

在编译工程目录下找到内存配置文件

target/linux.ramips/dts/mt7621.dtsi,找到llllw 改为 wllll 再编译烧录

没用

4、命令行手动配置

通过整个系统的搜索,找到配置的关键代码,在package/ramips/a[[lications/switch/files/switch.sh :111

if [ "$1" = "LLLLW" ]; then
 62                 if [ "$CONFIG_RAETH_SPECIAL_TAG" == "y" ]; then
 63                 #set PVID
 64                 switch reg w 2014 10007 #port0
 65                 switch reg w 2114 10007 #port1
 66                 switch reg w 2214 10007 #port2
 67                 switch reg w 2314 10007 #port3
 68                 switch reg w 2414 10008 #port4
 69                 switch reg w 2514 10007 #port5
 70                 #VLAN member port
 71                 switch vlan set 0 1 10000011
 72                 switch vlan set 1 2 01000011
 73                 switch vlan set 2 3 00100011
 74                 switch vlan set 3 4 00010011
 75                 switch vlan set 4 5 00001011
 76                 switch vlan set 5 6 00000111
 77                 switch vlan set 6 7 11110111
 78                 switch vlan set 7 8 00001011
 79                 else
 80                 #set PVID
 81                 switch reg w 2014 10001 #port0
 82                 switch reg w 2114 10001 #port1
 83                 switch reg w 2214 10001 #port2
 84                 switch reg w 2314 10001 #port3
 85                 switch reg w 2414 10002 #port4
 86                 switch reg w 2514 10001 #port5
 87                 #VLAN member port
 88                 switch vlan set 0 1 11110111
 89                 switch vlan set 1 2 00001011
 90                 fi
 91         elif [ "$1" = "WLLLL" ]; then
 92                 if [ "$CONFIG_RAETH_SPECIAL_TAG" == "y" ]; then
 93                 #set PVID
 94                 switch reg w 2014 10008 #port0
 95                 switch reg w 2114 10007 #port1
 96                 switch reg w 2214 10007 #port2
 97                 switch reg w 2314 10007 #port3
 98                 switch reg w 2414 10007 #port4
 99                 switch reg w 2514 10007 #port5
100                 #VLAN member port
101                 switch vlan set 4 5 10000011
102                 switch vlan set 0 1 01000011
103                 switch vlan set 1 2 00100011
104                 switch vlan set 2 3 00010011
105                 switch vlan set 3 4 00001011
106                 switch vlan set 5 6 00000111
107                 switch vlan set 6 7 01111111
108                 switch vlan set 7 8 10000011
109                 else
110                 #set PVID
111                 switch reg w 2014 10002 #port0
112                 switch reg w 2114 10001 #port1
113                 switch reg w 2214 10001 #port2
114                 switch reg w 2314 10001 #port3
115                 switch reg w 2414 10001 #port4
116                 switch reg w 2514 10001 #port5
117                 #VLAN member port
118                 switch vlan set 0 1 01111111
119                 switch vlan set 1 2 10000011
120                 fi
121         elif [ "$1" = "W1234" ]; then
122                 echo "W1234"
123                 #set PVID
124                 switch reg w 2014 10005 #port0
125                 switch reg w 2114 10001 #port1
126                 switch reg w 2214 10002 #port2
127                 switch reg w 2314 10003 #port3
128                 switch reg w 2414 10004 #port4
129                 switch reg w 2514 10006 #port5
130                 #VLAN member port
131                 switch vlan set 4 5 10000011
132                 switch vlan set 0 1 01000011
133                 switch vlan set 1 2 00100011
134                 switch vlan set 2 3 00010011
135                 switch vlan set 3 4 00001011
136                 switch vlan set 5 6 00000111
137         elif [ "$1" = "12345" ]; then
138                 echo "12345"
139                 #set PVID
140                 switch reg w 2014 10001 #port0
141                 switch reg w 2114 10002 #port1
142                 switch reg w 2214 10003 #port2
143                 switch reg w 2314 10004 #port3
144                 switch reg w 2414 10005 #port4
145                 switch reg w 2514 10006 #port5
146                 #VLAN member port
147                 switch vlan set 0 1 10000011
148                 switch vlan set 1 2 01000011
149                 switch vlan set 2 3 00100011
150                 switch vlan set 3 4 00010011
151                 switch vlan set 4 5 00001011
152                 switch vlan set 5 6 00000111
153         elif [ "$1" = "GW" ]; then
154                 echo "GW"
155                 #set PVID
156                 switch reg w 2014 10001 #port0
157                 switch reg w 2114 10001 #port1
158                 switch reg w 2214 10001 #port2
159                 switch reg w 2314 10001 #port3
160                 switch reg w 2414 10001 #port4
161                 switch reg w 2514 10002 #port5
162                 #VLAN member port
163                 switch vlan set 0 1 11111011
164                 switch vlan set 1 2 00000111
165         fi

参照这里的配置,学会了使用switch命令。

通过switch reg r 2014 -- 2414 发现原有路由器上的配置如同81-86行,所以改成111-116行即可确实分割两个网口

发布了64 篇原创文章 · 获赞 3 · 访问量 4582

猜你喜欢

转载自blog.csdn.net/qq_37631516/article/details/103564436