LEDE(openwrt) 树莓派3 raspberry pi3 配置为路由器router(含IPv6)

来源:互联网 发布:win7最大优化 编辑:程序博客网 时间:2024/06/18 08:27

烧写镜像

项目组购进了一批树莓派3,想用openwrt 使之成为一个路由器,但是openwrt 目前不支持树莓派3,只有他的分支LEDE 可以支持raspberry pi3

官方源https://downloads.lede-project.org/ ,注意要选择releases 版本,笔者一度使用了snapshots 版本,发现默认opkg(一个apt-get 一样的存在) 源不存在,更改后也没有成功,只能重新下载镜像后烧写。

官方镜像下载地址https://downloads.lede-project.org/releases/17.01.2/targets/brcm2708/bcm2710/lede-17.01.2-brcm2708-bcm2710-rpi-3-ext4-sdcard.img.gz
(树莓派系列的代号是1代2708,2代2709以及3代2710)
官方镜像大概8M,作为备份,中科大的源也可以使用http://mirrors.ustc.edu.cn/lede/releases/17.01.2/targets/brcm2708/bcm2710/lede-17.01.2-brcm2708-bcm2710-rpi-3-ext4-sdcard.img.gz ,在国内速度官方源要快一些。
解压缩后大概300M,烧写方式不在此赘述。(本人是在windows 下用SD Card FormatterWin32DiskImager
这里写图片描述

安装luci和usb有线网卡

树莓派只有一个网卡(千兆),所以需要再接一个外接网卡,但是由于usb口传输速率限制,无法做到双臂千兆,这里我购买了CE-LINK的百兆网卡,其内置芯片是RTL8152 ,外接网卡不能直接使用,需要驱动。

这里,下载安装驱动使用opkg ,但需要首先配置网络。

首次进入LEDE 根据提示更改密码,passwd

连接网线,配置网络,修改/etc/config/network ,如果是静态地址,添加

    config interface 'wan'    option ifname 'eth0'    option proto 'static'    option ipaddr 'xxx.xxx.xxx.xxx'    option netmask '255.255.255.0'    option gateway 'xxx.xxx.xxx.xxx'    option dns 'xxx.xxx.xxx.xxx'

另外,将lanifname 暂时改成wlan0 防止冲突。

完成修改后,reboot,再ping www.baidu.com 测试。

网络可达后,首先安装luci

   opkg update   opkg install luci

注意:每次重启后都要运行opkg update ,否则opkg 不正常工作

下面安装网卡驱动

   opkg install kmod-libphy   opkg install kmod-mii   opkg install kmod-usb-net   opkg install kmod-usb-net-rtl8152

最后一条命令根据自己的有线网卡芯片型号修改。
安装后出现

   Configuring kmod-usb-net.   failed to find a module named usbnet   Collected errors:   * pkg_run_script: package "kmod-usb-net" postinst script returned status 255.

是正常现象,不影响使用(ipk包和之前分支的问题),在之后每次使用opkg 的时候也都会出现。

这时,我们可以ip a 看到eth1 ,将network 文件中的lanifname 改为eth1 ,路由器基本成形了。
用网线连接外接网卡,默认192.168.1.1luci 的地址,
启动luci

    /etc/init.d/uhttpd start    /etc/init.d/uhttpd enable

可以用浏览器访问进行配置,另外其默认开启ssh 访问。

luci

luci界面很是好用,值得大家探索,另外也可以安装luci-i18n-base-zh-cn 包来获取中文界面,安装后在 系统-语言和界面 处修改。
这里写图片描述

换源

虽然官方源可用,但是还是提供换源的方式,修改/etc/opkg/distfeeds.conf
将网址中的http://downloads.lede-project.org/ 换成其他源,这里推荐中科大源。

ipv6

由于校园网有原生的IPv6,所以我配置了nat66
opkg install ip6tables kmod-ipt-nat6

wan 的配置,增加一个interface ,因为无法同时static v4dhcp v6

    config interface 'wan6'    option proto 'dhcpv6'    option reqaddress 'try'    option reqprefix 'auto'    option _orig_ifname 'eth0'    option _orig_bridge 'false'    option ifname 'eth0'

注意,在luci 下经过奇妙配置可能出现option _orig_bridge 'true' 改不回去,所以尽量在命令行下配置。(再次安装的时候,又是死活拿不到地址,好像是玄学问题,准备认真学习DHCPv6 后解决这个问题)

这时,树莓派应该已经能够拿到地址,并且可以访问IPv6

可以使用http://simpledns.com/private-ipv6.aspx 生成随机私有地址,在lan 下增加

    option ip6assign '64'    option ip6ifaceid 'xxxx:xxxx:xxxx:xxxx'

并更改

    config globals 'globals'    option ula_prefix 'xxxx:xxxx:xxxx:xxxx::/64'

此时,lan 口有IPv6 私有地址。
之后的步骤参见https://lixingcong.github.io/2017/04/24/ipv6-nat-lede/
即可实现nat66

原创粉丝点击