|
本帖最后由 heq 于 2019-8-26 18:23 编辑
家里的主路由Netgear WNDR4300刷了OpenWRT使用多年,质量稳定可靠。但随着家庭网络要求的提高渐不堪重负。去年买的Raspberry Pi 3B一直吃灰。遂打算将两者组合使用,利用RPi提升路由器的运算能力。奈何RPi只有一个有线网络接口,单臂路由(router-on-a-stick)就成了最佳选择。RPi的百兆有线网络应付当前的50M带宽带倒也够了。经过这种改造,带有线网口的电脑(比如淘汰下来的笔记本)都能胜任软路由,多线接入要求可以通过路由器vlan实现,。
下面是具体实现步骤,前几天经过实战试验成功。友情提醒:需要基本linux能力,熟悉CLI操作。
一、预备:
1 RPi刷raspbian,路由刷OpenWRT(支持vlan即可,对版本基本无要求)
2 RPi无线网络开启,便于进入系统更改调试。全部设定成功后可以关闭无线,统一使用WNDR4300的无线网络。
3 WAN口接光猫,LAN4接RPi3,如下图
二、 RPi3设置
1 增加vlan 11做为WAN界面,vlan 22 作为LAN界面- # vconfig add eth0 11
- # vconfig add eth0 22
复制代码
2 确认上述设置生效
- $ ls -l /proc/net/vlan
- total 0
- -rw------- 1 root root 0 Dec 4 11:01 config
- -rw------- 1 root root 0 Dec 4 11:01 eth0.11
- -rw------- 1 root root 0 Dec 4 11:01 eth0.22
复制代码 3 设置vlan,假设光猫端完成PPPoE拨号,WAN端口通过DHCP获取IP信息。
3a create new file to config vlan
# vi /etc/network/interfaces.d/vlans
- # WAN
- auto eth0.11
- iface eth0.11 inet dhcp
- vlan-raw-device eth0
- # LAN
- auto eth0.22
- iface eth0.22 inet static
- address 192.168.100.1
- netmask 255.255.255.0
- vlan-raw-device eth0
复制代码 3b 更改原来eth0的设置
# vi /etc/network/interfaces
- allow-hotplug eth0
- iface eth0 inet manual
复制代码 4 设置DHCP、DNS服务(自动分配网段为192.168.100.0/24)
# vi /etc/dnsmasq.conf
- ...
- interface=eth0.22
- dhcp-range=eth0.22,192.168.100.100,192.168.100.230,255.255.255.0, 24h
- ...
复制代码 5 设置masquerade
# vi /etc/rc.local
- ...
- iptables -t nat -A POSTROUTING -o eth0.11 -j MASQUERADE
- iptables -A FORWARD -i eth0.11 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
- iptables -A FORWARD -i eth0.11 -o eth0.22 -m state --state RELATED,ESTABLISHED -j ACCEPT
- iptables -A FORWARD -i wlan0 -o eth0.11 -j ACCEPT
- iptables -A FORWARD -i eth0.22 -o eth0.11 -j ACCEPT
- ...
复制代码 6 确认系统允许ip forwarding
# vi /etc/sysctl.conf
- ...
- net.ipv4.ip_forward=1
- net.ipv6.conf.all.forwarding=1
- ...
复制代码 7 重启系统使得上述设定生效
三、 路由器设置
1 调整原有vlan设置,将WAN口与LAN4(RPi3接入口)绑定,其它LAN口与openwrt系统绑定。vlan ID与RPi3的设置相对应,取11与22
# vi /etc/config/network 更改原来的switch_vlan设置,注意CPU(openwrt系统)对应vlan 0#,WAN端口对应vlan 5#,LAN4端口对应vlan 1#- ###### original setting, to modify ######
- config interface 'lan'
- ...
- option ifname 'eth0.1'
- ...
- config interface 'wan'
- ...
- option ifname 'eth0.2'
- ...
- config switch_vlan
- option device 'switch0'
- option vlan '1'
- option ports '1 2 3 4 0t'
- config switch_vlan
- option device 'switch0'
- option vlan '2'
- option ports '5 0t'
- ...
- ####### new settting ######
- config interface 'lan'
- ...
- option ifname 'eth0.22'
- ...
- config interface 'wan'
- ...
- option ifname 'eth0.11'
- ...
- config switch_vlan
- option device 'switch0'
- option vlan '11'
- option vid '11'
- option ports '1t 5'
- config switch_vlan
- option device 'switch0'
- option vlan '22'
- option vid '22'
- option ports '0t 1t 2 3 4'
复制代码
这个步骤更建议通过网页luci界面完成,因为openwrt vlan的端口与实际端口无直观对应,网页下设置不容易出错
2 取消LAN界面的DHCP服务
# vi /etc/config/dhcp- ...
- config dhcp 'lan'
- option interface 'lan'
- option ignore '1'
- ...
复制代码
3 重启相应服务,使得上述更改生效
- # /etc/init.d/network restart
- # /etc/init.d/dnsmasq restart
复制代码
全部设定至此结束,RPi3的有线网口兼具WAN与LAN功能,其WAN端口eth0.11获得了上级光猫分配的IP地址,并由LAN端口eth0.22向接入路由的设备提供服务。连接到路由的设备可以正常上网,其分配的IP地址隶属RPi3指定的192.168.100.100/24网段。
补充内容 (2019-6-1 00:13):
Luci设置图片部分被遮挡,调整后的图片上传到53#。
更改内容(2019-8-26 18:15)
因为自己对设置内容很熟悉,就会忽略很多技术细节。原来的设定很容易导致路由器“失联”,因为路由器设置了新vlan ID(11, 22)而忘记同步更改原来LAN/WAN的VLAN ID(2, 1)。更改后就好了。
请大家设置时及时提出疑问,能让这篇指南帮到更多的人。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
评分
-
查看全部评分
|