Jun 9, 2018

raspberry pi を access point 化

◆前提

クライアントデバイス → wlan0 → eth0 → 上位ルータ

interface (eth0, wlan0/mon0), routing, name resolution などは設定済み&稼働していること。

◆インストール

sudo apt-get update
sudo apt-get install hostapd dnsmasq

設定

NIC
vi /etc/network/interfaces
お好みで

hostapd.conf
vi /etc/hostapd/hostapd.conf
お好みで、、、コメント参照

hostapd
vi /etc/default/hostapd   # で下記一行を追加。
DAEMON_CONF=”/etc/hostapd/hostapd.conf”

dnsmasq.conf  
vi /etc/dnsmasq.conf  
ここも参考サイトをコピペでOK
私は、「listen-address」は設定なし(コメントアウト)しました。

nexmonパッチ対応。mon0インターフェイスアップ
iw phy0 interface add mon0 type monitor; ifconfig mon0 up

・起動
sudo service hostapd start
現状エラー発生していて、次のコマンドを使っている。
/usr/sbin/hostapd -B /etc/hostapd/hostapd.conf
sudo service dnsmasq start  ←きちんと設定を見直すと、/etc/rc.d/のデフォルトスクリプトで自動起動できるようになりました。2019.01.03 訂正

Masquerading (要注意: こっちで大幅変更 2019.01.03)
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"


◆参考にしたところ

・Raspberry Pi 3のWIFIをAPモードにする方法 (2017/07/05)
http://nw-electric.way-nifty.com/blog/2017/07/raspberry-pi-3w.html

・hostapd 設定 覚書 (2016/04/11)
https://qiita.com/JhonnyBravo/items/947e480f7f3eb0728e19

・hostapdが起動しない時の確認事項 (2017/05/28)
http://kosuke128.hatenadiary.jp/entry/2017/05/28/214224
nat 、iptables や
Wi-Fiドングルのドライバー hostapd.conf のdriver=rtl871xdrvなど、紹介されています。

・Hostapd Problems (2015/01/21)
https://www.raspberrypi.org/forums/viewtopic.php?t=97253

・Access point configuration problem on RPi3 (2018/02/06)
https://forums.kali.org/showthread.php?38920-Access-point-configuration-problem-on-RPi3
「最新raspberry piイメージは、内部Wi-Fiアダプタにnexmonパッチを含んでいて、
これは追加ステップを要する」との事。そのステップは次の通り
iw phy0 interface add mon0 type monitor; ifconfig mon0 up

この記事内のリンク先の起動シェルも参考になります。
https://github.com/Re4son/Kali-Pi/tr...r/Menus/RAS-AP

・mame82/P4wnP1_nexmon_additions
https://github.com/mame82/P4wnP1_nexmon_additions#access-point-mode-with-hostapd
ここにも mon0 や、nexmon の記載があります。

・hostapd will not start via “service” — but will start directly
https://unix.stackexchange.com/questions/119209/hostapd-will-not-start-via-service-but-will-start-directly
ここのNo.9 の /etc/network/interfaces に dhcpdやhostapdの起動を定義する方法も参照




1 comment:

  1. ◆hostapd.confのサンプル

    # This is the name of the WiFi interface we configured above
    interface=wlan0

    # Use the nl80211 driver with the brcmfmac driver
    driver=nl80211

    # This is the name of the network
    ssid=お好みで

    # Use the 2.4GHz band
    hw_mode=g

    # Use channel 6
    channel=6

    # Enable 802.11n
    ieee80211n=1

    # Enable WMM
    wmm_enabled=1

    ### Enable 40MHz channels with 20ns guard interval
    ## ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
    ## これは使用しなかった

    # Accept all MAC addresses
    macaddr_acl=0

    # Use WPA authentication
    auth_algs=1

    # Require clients to know the network name
    ignore_broadcast_ssid=0

    # Use WPA2
    wpa=2

    # Use a pre-shared key
    wpa_key_mgmt=WPA-PSK

    # The network passphrase
    wpa_passphrase=お好みで

    # Use AES, instead of TKIP
    rsn_pairwise=CCMP

    以上

    ReplyDelete