52
60

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で、Wi-Fi アクセスポイントルータ

Last updated at Posted at 2016-06-09

概要

環境

  • Raspberry Pi 3
  • Raspberry Pi 2 + USB WiFiドングル(RTL8188CUS) (追記)
    =>hostapdの差し替えとhostapd.confの書き換え その他参照
  • Jessie-lite : 2016-05-27-raspbian-jessie-lite.img

手順

  1. Raspbianを焼く

  2. いつもの++

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y hostapd isc-dhcp-server

3. `sudo vi /etc/dhcp/dhcpd.conf`
    
    ```txt:/etc/dhcp/dhcpd.conf
.
. #コメントアウト
.
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
.
. #コメントをはずす .
.
authoritative;
.
. #最後に追記 .
.
subnet 192.168.42.0 netmask 255.255.255.0 {
        range 192.168.42.10 192.168.42.50;
        option broadcast-address 192.168.42.255;
        option routers 192.168.42.1;
        default-lease-time 600;
        max-lease-time 7200;
        option domain-name "local";
        option domain-name-servers 8.8.8.8, 8.8.4.4;
}
  1. sudo vi /etc/default/isc-dhcp-server

    /etc/default/isc-dhcp-server

... # wlan0記述
INTERFACES="wlan0"


5. `sudo vi /etc/network/interfaces`

    ```txt:/etc/network/intefaces
iface wlan0 inet manual
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
... #↑ コメントアウト
  1. sudo vi /etc/dhcpcd.conf

    /etc/dhcpcd.conf

... 最後に追記: wlan0をstatic ip (192.168.42.1)へ
interface wlan0
static ip_address=192.168.42.1/24


7. `sudo vi /etc/hostapd/hostapd.conf`

    ```txt:/etc/hostapd/hostapd.conf
#新規作成
interface=wlan0
driver=nl80211
#driver=rtl871xdrv
ssid=Pi3-AP
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=raspberry
rsn_pairwise=CCMP
- SSID: `ssid`=`Pi3-AP`
- パスワード: `wpa_passphrase`=`raspberry`
  1. sudo vi /etc/default/hostapd

    /etc/default/hostapd

#コメントをはずして、編集
DAEMON_CONF="/etc/hostapd/hostapd.conf"


9. `sudo vi /etc/sysctl.conf`

    ```txt:/etc/sysctl.conf
#コメントをはずす
net.ipv4.ip_forward=1
  1. iptablesの設定

#コマンドラインへこぴぺ

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

11. `sudo vi /lib/dhcpcd/dhcpcd-hooks/70-ipv4-nat`

    ```txt:/lib/dhcpcd/dhcpcd-hooks/70-ipv4-nat
#新規作成
iptables-restore < /etc/iptables.ipv4.nat
  1. sudo reboot

  2. テスト

#コマンドラインへこぴぺ

sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf

    - Windowsとかで、`Pi3-AP`というのが現れるか確認して、`CTRL-c`で、抜ける
14. サービス起動

    ```
#コマンドラインへこぴぺ
#サービス開始
sudo service hostapd start
sudo service isc-dhcp-server start
#
#サービス状態
#sudo service hostapd status
#sudo service isc-dhcp-server status
#
#サービス登録.
sudo update-rc.d hostapd enable
sudo update-rc.d isc-dhcp-server enable
#
#サービス解除.
#sudo update-rc.d hostapd disable
#sudo update-rc.d isc-dhcp-server disable
  1. sudo vi /etc/init.d/isc-dhcp-server

    • (!!要確認!!) - アドバイスおねがいします
    /etc/init.d/isc-dhcp-server

...
start)
test_config
log_daemon_msg "Starting $DESC" "$NAME"
#
sleep 7 # 起動時にこけるのでWaitをいれる.
#
start-stop-daemon --start --quiet --pidfile "$DHCPD_PID"
...


16. クライアントで、接続してチェック
IPは`192.168.42.xx`がアサインされる

## その他

1. Raspberry Pi 2
    - <font color='red'>8188cus/8192cu</font>などのWifi-USBドングルの場合はそのままの`hostapd`では動かない。
    - <del>Adafruitのとこから、`hostapd`のzipを入手して入れ替える</del>。
    - (NEW)`hostapd v2.5`ベースで、ビルドしました。
        - パッチ: https://github.com/pritambaral/hostapd-rtl871xdrv
        - [ビルド方法はこれををそのまま](https://github.com/pritambaral/hostapd-rtl871xdrv/issues/12#issuecomment-191822619)...

    ```
#コマンドラインへこぴぺ
wget https://raw.githubusercontent.com/mt08xx/vgc/master/bin/hostapd_v2.5-rtl871xdrv.zip
unzip hostapd_v2.5-rtl871xdrv.zip
sudo mv -i /usr/sbin/hostapd /usr/sbin/hostapd.ORIG
sudo mv -i hostapd /usr/sbin
sudo chmod 755 /usr/sbin/hostapd
```txt:/etc/hostapd/hostapd.conf

...

driver=nl80211

driver=rtl871xdrv
...


    ```shell-session:参考:hostapdバージョン
pi@raspberrypi:~$ /usr/sbin/hostapd -v
hostapd v2.5 for Realtek rtl871xdrv
User space daemon for IEEE 802.11 AP management,
IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator
Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi> and contributors
pi@raspberrypi:~$
pi@raspberrypi:~$ /usr/sbin/hostapd.ORIG -v
hostapd v2.3
User space daemon for IEEE 802.11 AP management,
IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator
Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi> and contributors
pi@raspberrypi:~$
52
60
5

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
52
60

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?