Help us understand the problem. What is going on with this article?

[メモ] Raspberry Pi 3で、Wi-Fi アクセスポイントルータ

More than 3 years have passed since last update.

概要

環境

  • 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

    /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;
    }
    
  4. sudo vi /etc/default/isc-dhcp-server

    /etc/default/isc-dhcp-server
    ... # wlan0記述
    INTERFACES="wlan0"
    
  5. sudo vi /etc/network/interfaces

    /etc/network/intefaces
    iface wlan0 inet manual
    #    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    ... #↑ コメントアウト
    
  6. 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

    /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
  8. sudo vi /etc/default/hostapd

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

    /etc/sysctl.conf
    #コメントをはずす
    net.ipv4.ip_forward=1
    
  10. 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

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

  13. テスト

    #コマンドラインへこぴぺ
    #
    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
    
  15. 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

    #コマンドラインへこぴぺ
    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
    
    /etc/hostapd/hostapd.conf
    ...
    # driver=nl80211
    driver=rtl871xdrv
    ...
    
    参考: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:~$
    
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away