2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[メモ] Raspberry Pi 3で、WiFi-EthブリッジAP

Posted at

概要

TL;DR

  • Default: SSID=raspberry WPA_PASSPHRASE=passw0rd CHANNEL=11
コピペ
# 2018-11-13-raspbian-stretch-lite
grep '^denyinterfaces wlan0' /etc/dhcpcd.conf || echo denyinterfaces wlan0 | sudo tee -a /etc/dhcpcd.conf && \
sudo sed -i -e 's/^#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf && \
sudo sh -c 'sysctl -p && systemctl daemon-reload && systemctl restart dhcpcd' && \
curl -fsSL https://get.docker.com | sh 
#
# 一度再起動
sudo reboot
#
#
sudo usermod -aG docker ${USER} && \
sudo docker pull mt08/rpi-wifibridge && \
DHCP_SERVER=$(grep -R "offered" /var/log/* 2>/dev/null | tail -n1 | awk '{print $(NF)}') && \
sudo docker run -d --net host --privileged --rm --name rpi-wifibridge \
   -e DHCP_SERVER=${DHCP_SERVER} \
   mt08/rpi-wifibridge && \
sleep 5 && sudo docker logs rpi-wifibridge && \
ip -4 -br addr show | grep UP && echo DHCP-Server: ${DHCP_SERVER}
実行例(rebootのあと)
pi@raspberrypi:~ $ sudo usermod -aG docker ${USER} && \
> sudo docker pull mt08/rpi-wifibridge && \
> DHCP_SERVER=$(grep -R "offered" /var/log/* 2>/dev/null | tail -n1 | awk '{print $(NF)}') && \
> sudo docker run -d --net host --privileged --rm --name rpi-wifibridge \
>    -e DHCP_SERVER=${DHCP_SERVER} \
>    mt08/rpi-wifibridge && \
> sleep 5 && sudo docker logs rpi-wifibridge && \
> ip -4 -br addr show | grep UP && echo DHCP-Server: ${DHCP_SERVER}
Using default tag: latest
latest: Pulling from mt08/rpi-wifibridge
dc95218aa9a9: Pull complete
08105d289242: Pull complete
943cb8ac165f: Pull complete
2bcf02afc443: Pull complete
c6e1574200da: Pull complete
918a9e777733: Pull complete
48951e7a1fc0: Pull complete
Digest: sha256:dbb46454bef8c335747e935804f9d91d33a5f9f1b7e6130b2650f0369014e244
Status: Downloaded newer image for mt08/rpi-wifibridge:latest
3d24fe6c468d2322430261e69dea115b9a1a90cc68f542abe9af08452b570015
set ip_forward to 1
1
Starting HostAP daemon ...
Configuration file: /etc/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr b8:27:eb:eb:a3:c9 and ssid "raspberry"
random: Only 15/20 bytes of strong random data available from /dev/random
random: Not enough entropy pool available for secure operations
WPA: Not enough entropy in random pool for secure operations - update keys later when the first station connects
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
eth0             UP             192.168.1.54/24
wlan0            UP             192.168.1.54/32
DHCP-Server: 192.168.1.1
pi@raspberrypi:~ $

環境

  • Raspberry Pi 3B or 3B+
  • Raspbian: 2018-11-13-raspbian-stretch-lite
  • Docker
  • ネット環境
    • DHCPサーバは、RPiでない (例: 無線APルータの有線ポートにRPi接続)
    • RPi Ethernet(eth0)
      • DHCPでIPを取得している(例:192.168.1.5/24)
    • RPi Wifi(wlan0)
      • hostapdを動かす
      • ipは、eth0に割り当てられたものと同じ、ネットマスク /32 (例: 192.168.1.5/32)

手順

  1. Raspbian Lite を焼く

  2. 初期設定を適当に済ます

    • hostname
    • aptパッケージ更新
    • パスワード変更
    • タイムゾーンとか、言語設定とか
    • お好みパッケージ導入(例: sudo apt install haveged byobu -y )
  3. ネット設定関係

    • /etc/dhcpcd.conf : denyinterfaces wlan0を最後に追記

       echo denyinterfaces wlan0 | sudo tee -a /etc/dhcpcd.conf
      
    • /etc/sysctl.conf : net.ipv4.ip_forward=1のとこのコメント外す。

       sudo sed -i -e 's/^#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
      
  4. Dockerインストール、再起動

    curl -fsSL https://get.docker.com | sh && sudo usermod -aG docker ${USER} && sudo reboot
    
  5. Dockerにて、起動

    # イメージ取得
    sudo docker pull mt08/rpi-wifibridge
    
    # ラズパイのeth0にIPを割り当てたDHCPサーバを探す
    DHCP_SERVER=$(grep -R "offered" /var/log/* 2>/dev/null | tail -n1 | awk '{print $(NF)}')
    echo DHCP SERVER IP: ${DHCP_SERVER}
    
    # コンテナ起動 (デフォルト: SSID=raspberry WPA_PASSPHRASE=passw0rd CHANNEL=11)
    sudo docker run -d --net host --privileged --rm --name rpi-wifibridge \
       -e DHCP_SERVER=${DHCP_SERVER} \
       mt08/rpi-wifibridge
    
    # コンテナ起動 (SSIDなどを指定して起動)
    docker run -d --net host --privileged --rm --name rpi-wifibridge \
      -e SSID=sukina_ssid_name \
      -e CHANNEL=6 \
      -e WPA_PASSPHRASE=himitsu123 \
      -e DHCP_SERVER=${DHCP_SERVER} \
      mt08/rpi-wifibridge   
    

説明

このあたりを使用

  • parprouted:
  • dhcp-helper:
  • bcrelay:

その他 / TODO

  • 自動起動の設定
  • (?) ネット周りの図をかく
  • (?) wlan0 - wlan1 のブリッジ
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?