OpenWrt on Raspberry Pi

OpenWrt是一款开源路由器系统, 可以在树莓派上完美运行.
如果直接把Raspbian系统打造成一款路由器, 就有点麻烦了.

                                 <-- LAN
                               /
Internet <-- aWiFi <-- OpenWrt  
                         (PI)  \
                                 <-- Router <-- Guest

注: aWiFi是附近的广告Wi-Fi, 可以通过它免费上网.

硬件

  • Home Router (For Initial Setup)
  • Raspberry Pi 2B
  • 8GB SD Card
  • USB SD Card Reader
  • USB Wireless Adapter (ALFA AWUS036NH)
  • 5V/1A Power Adapter

安装

# Flash image file (On MacOSX)
diskutil list  
diskuitl umountDisk diskX  
wget https://downloads.openwrt.org/chaos_calmer/15.05.1/brcm2708/bcm2709/openwrt-15.05.1-brcm2708-bcm2709-sdcard-vfat-ext4.img.gz  
gzip -cd openwrt-15.05.1-brcm2708-bcm2709-sdcard-vfat-ext4.img.gz | dd of=/dev/rdiskX bs=32m  
diskutil eject diskX

# Extend file system (On Linux)
fdisk /dev/sdX  
e2fsck -f /dev/sdX2  
resize2fs /dev/sdX2  

配置

首先, 可以通过下列方法首次登录到树莓派:

  • hdmi monitor + usb keyboard
  • usb2ttl cable (via minicom)
  • ethernet cable (via telnet)

其次, 把树莓派连接到路由器的LAN口

cd /etc/config  
cat network

uci set network.lan.proto=dhcp  
uci commit  
reload_config

opkg -V4 update  
cp -r /tmp/opkg-lists ~  
opkg install kmod-cfg80211 kmod-rt2800-usb hostapd wpa-supplicant

最后, 把树莓派连接到路由器的WAN口

uci set network.lan.proto=static  
uci commit

reboot

rmdir /tmp/opkg-lists  
ln -s ~/opkg-lists /tmp  
opkg list-installed  
opkg find '*vpn*'  

管理

在浏览器中打开 http://192.168.1.1/

Administration:  
  Router Password: ******
  SSH Access: ******

Wifi:  
  - SSID: aWiFi
    Mode: Client
  - SSID: OpenWrt
    Mode: Master

Interfaces:  
  LAN: br-lan (eth0, Mater "OpenWrt")
  WWAN: Client "aWiFi"

网卡同时支持MasterClient模式, 把原先的路由器作为Guest专用.