Open ShogoHirasawa opened 2 years ago
現状: Raspberry Piをwifi接続でssh接続できている状態
現状の理解
tips: アクセスポイント化の資料はここを参考。結構わかりやすかった https://www.youtube.com/watch?v=ec4Mn-knTIE
このサイトをみながらアクセスポイント化にチャレンジする https://www.itmedia.co.jp/news/articles/2008/14/news042.html
初っ端からエラー発生
sudo systemctl stop dhcpcd
``
<img width="483" alt="スクリーンショット 2021-12-20 14 47 02" src="https://user-images.githubusercontent.com/29940264/146717863-bb99b83b-c455-4d60-b75a-1be8967c4571.png">
<img width="485" alt="スクリーンショット 2021-12-20 14 47 28" src="https://user-images.githubusercontent.com/29940264/146717894-c96f4b33-83f2-4e28-9214-4b2312a25a0f.png">
ちなみに、Raspberry Piをみたら緑のランプが消えていた...
control + C も受け付けず何もできない状態
たぶん、しばらく操作せず放置していると不具合がでるよう。(中のデータが破損する場合もあるとか、ないとか) GUI操作での例だが、CUIの場合でも同じなのかも。 https://dev.classmethod.jp/articles/restore-the-raspberry-pi-4-model-b-os-destroyed-by-a-biginner/
OSをこの手順にそって再インストール
再インストールしてssh接続完了
wifiでRaspberry Piに接続してるのに、dhcpcdをストップさせるコマンド打ったのが原因。
Ethernetケーブルで接続してsudo systemctl stop dhcpcd
を実行したら無事に通った
sudo nano /etc/dhcpcd.conf
を実行。
以下の画面が表示される
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.
# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel
# Inform the DHCP server of our hostname for DDNS.
hostname
# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid
# Persist interface configuration when dhcpcd exits.
persistent
最後の行に以下を記述
interface wlan0
static ip_address=192.168.87.1/24
以下のコマンド実行
sudo systemctl restart dhcpcd
以下のコマンド実行
sudo apt install hostapd
エラー発生
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
libfuse2
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
hostapd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 665 kB of archives.
After this operation, 1,817 kB of additional disk space will be used.
Err:1 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf hostapd armhf 2:2.9.0-21
Temporary failure resolving 'raspbian.raspberrypi.org'
E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/w/wpa/hostapd_2.9.0-21_armhf.deb Temporary failure resolving 'raspbian.raspberrypi.org'
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
apt-get update
を実行したところ以下のエラー発生
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
Permissionで問題になっている部分を権限を"755"に変更
同じようなエラーがでたので、/var/lib/apt/lists/lock と/var/cache/aptを再帰的に777に変更
再度apt-get update
をやるも以下のエラー発生
Err:1 http://raspbian.raspberrypi.org/raspbian bullseye InRelease
Temporary failure resolving 'raspbian.raspberrypi.org'
Err:2 http://archive.raspberrypi.org/debian bullseye InRelease
Temporary failure resolving 'archive.raspberrypi.org'
Reading package lists... Done
W: Problem unlinking the file /var/lib/apt/lists/partial/raspbian.raspberrypi.org_raspbian_dists_bullseye_InRelease - PrepareFiles (13: Permission denied)
W: Problem unlinking the file /var/lib/apt/lists/partial/archive.raspberrypi.org_debian_dists_bullseye_InRelease - PrepareFiles (13: Permission denied)
W: Failed to fetch http://raspbian.raspberrypi.org/raspbian/dists/bullseye/InRelease Temporary failure resolving 'raspbian.raspberrypi.org'
W: Failed to fetch http://archive.raspberrypi.org/debian/dists/bullseye/InRelease Temporary failure resolving 'archive.raspberrypi.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Permission エラーが出ている部分を再び777に変更する
再度、sudo apt install hostapd
をするも以下のエラー発生
sudo apt install hostapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
libfuse2
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
hostapd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 665 kB of archives.
After this operation, 1,817 kB of additional disk space will be used.
Err:1 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf hostapd armhf 2:2.9.0-21
Temporary failure resolving 'raspbian.raspberrypi.org'
E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/w/wpa/hostapd_2.9.0-21_armhf.deb Temporary failure resolving 'raspbian.raspberrypi.org'
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
pi@admin:~ $ hostapd -v
-bash: hostapd -v: command not found
hostapdがインストールできていないもよう....。
Slackにも書きましたが、
権限は元に戻してください。
インターネットと疎通できない場合は。一旦 dhcpd
を停止してwifiをルータに接続してパッケージのインストールが終わった後に改めて設定したらいいと思います。
dhcpdを停止してwifiをルータに接続してパッケージのインストールが終わった後に改めて設定
dhcpdを停止した後に Wi-Fiで通信ってできるものなのでしょうか? Wi-Fiで通信するためのものがdhcpdだと認識していました....。すいません。勉強不足で誤って認識しているかもしれません... 。
@mq-sol さんのアドバイス通り、hostapdとdnsmasqのインストールをしてから、最後にdhcpcd.confの設定をしてみる
支障なささそうな、dhcpcd.confの書き換えからスタート
sudo nano /etc/dhcpcd.conf
に以下の記述をした
interface wlan0
static ip_address=192.168.87.1/24
sudo apt install hostapd
をやってみる。成功
pi@Shogo:~ $ sudo apt install hostapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
libfuse2
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
hostapd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 665 kB of archives.
After this operation, 1,817 kB of additional disk space will be used.
Get:1 http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian bullseye/main armhf hostapd armhf 2:2.9.0-21 [665 kB]
Fetched 665 kB in 2s (373 kB/s)
Selecting previously unselected package hostapd.
(Reading database ... 99508 files and directories currently installed.)
Preparing to unpack .../hostapd_2%3a2.9.0-21_armhf.deb ...
Unpacking hostapd (2:2.9.0-21) ...
Setting up hostapd (2:2.9.0-21) ...
Created symlink /etc/systemd/system/multi-user.target.wants/hostapd.service → /lib/systemd/system/hostapd.service.
Job for hostapd.service failed because the control process exited with error code.
See "systemctl status hostapd.service" and "journalctl -xe" for details.
Created symlink /etc/systemd/system/hostapd.service → /dev/null.
Processing triggers for man-db (2.9.4-2) ...
sudo nano /etc/hostapd/hostapd.conf
以下の通り記述
interface=wlan0
driver=nl80211
hw_mode=b
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
ieee80211ac=0
wmm_enabled=1
ieee80211d=1
country_code=JP
ieee80211h=1
local_pwr_constraint=3
spectrum_mgmt_required=1
wpa=3
wpa_key_mgmt=WPA-PSK
ssid=raspi
wpa_passphrase=admin
sudo nano /etc/default/hostapd
「#DAEMON_CONF=""」の部分を以下の通り記述
DAEMON_CONF="/etc/hostapd/hostapd.conf"
マスクを外すため、以下のコマンドを実行
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
sudo systemctl status hostapd
を打ち動作を確認
pi@Shogo:~ $ sudo systemctl status hostapd
● hostapd.service - Access point and authentication server for Wi-Fi and Ethernet
Loaded: loaded (/lib/systemd/system/hostapd.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Sat 2021-10-30 20:53:12 JST; 44ms ago
Docs: man:hostapd(8)
Process: 1702 ExecStart=/usr/sbin/hostapd -B -P /run/hostapd.pid -B $DAEMON_OPTS ${DAEMON_CONF} (code=exited, status=1/FAILURE)
CPU: 22ms
sudo nano /etc/sysctl.conf
で設定ファイルを開く
以下の行の先頭にある「#」を削除。
net.ipv4.ip_forward=1
以下のコマンドを実行
sudo apt install dnsmasq
エラー発生。ネットにつながっていない模様。
pi@Shogo:~ $ sudo apt install dnsmasq
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
libfuse2
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
dns-root-data dnsmasq-base libnetfilter-conntrack3 libnfnetlink0
The following NEW packages will be installed:
dns-root-data dnsmasq dnsmasq-base libnetfilter-conntrack3 libnfnetlink0
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 498 kB of archives.
After this operation, 1,159 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Err:1 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf dns-root-data all 2021011101
Temporary failure resolving 'raspbian.raspberrypi.org'
Err:2 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf libnfnetlink0 armhf 1.0.1-3+b1
Temporary failure resolving 'raspbian.raspberrypi.org'
Err:3 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf libnetfilter-conntrack3 armhf 1.0.8-3
Temporary failure resolving 'raspbian.raspberrypi.org'
Err:4 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf dnsmasq-base armhf 2.85-1
Temporary failure resolving 'raspbian.raspberrypi.org'
Err:5 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf dnsmasq all 2.85-1
Temporary failure resolving 'raspbian.raspberrypi.org'
E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/d/dns-root-data/dns-root-data_2021011101_all.deb Temporary failure resolving 'raspbian.raspberrypi.org'
E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/libn/libnfnetlink/libnfnetlink0_1.0.1-3%2bb1_armhf.deb Temporary failure resolving 'raspbian.raspberrypi.org'
E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/libn/libnetfilter-conntrack/libnetfilter-conntrack3_1.0.8-3_armhf.deb Temporary failure resolving 'raspbian.raspberrypi.org'
E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/d/dnsmasq/dnsmasq-base_2.85-1_armhf.deb Temporary failure resolving 'raspbian.raspberrypi.org'
E: Failed to fetch http://raspbian.raspberrypi.org/raspbian/pool/main/d/dnsmasq/dnsmasq_2.85-1_all.deb Temporary failure resolving 'raspbian.raspberrypi.org'
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
スタンドアロンだったらdnsは無くてもいいよ。 hostapdとdhcpdを止めてから、入れなおしてみて
SSID: dronebirdとしてアクセスポイント化は成功。しかし、パスワードを打ってもWi-Fiに接続しない。跳ね返されてしまう
sudo systemctl restart network
ping ntp.nict.jp
sudo apt update -y
sudo apt install -y apache2 hostapd dnsmasq
sudo apt upgrade -y
sudo apt autoremove -y
sudo systemctl stop dhcpcd
sudo echo "interface wlan0" >> /etc/dhcpcd.conf
sudo echo "static ip_address=192.168.20.1/24" >> /etc/dhcpcd.conf
cat << _EOF_ | sudo tee /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
hw_mode=b
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
ieee80211ac=0
wmm_enabled=1
ieee80211d=1
country_code=JP
ieee80211h=1
local_pwr_constraint=3
spectrum_mgmt_required=1
wpa=3
wpa_key_mgmt=WPA-PSK
ssid=dronebird
wpa_passphrase=dronebird
_EOF_
sudo sed -i -e "s@#DAEMON_CONF=\"\"@DAEMON_CONF=\"/etc/hostapd/hostapd.conf\"@g" /etc/default/hostapd
sudo systemctl status hostapd
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl stop dnsmasq
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.def
cat << _EOF_ | sudo tee /etc/dnsmasq.conf
interface=wlan0
dhcp-range=192.168.20.2,192.168.20.100,255.255.255.0,24h
_EOF_
sudo systemctl restart dhcpcd
sudo systemctl restart hostapd
sudo systemctl restart dnsmasq
スマホのwifiリストにdronebirdが表示されること
スマホのdronebirdにログインできる
@mq-sol さんの指示通りに実行してみる。 まずは、Mac側のIPの固定化
pi@dronebird4:~ $ sudo systemctl restart network
Failed to restart network.service: Unit network.service not found.
代わりに以下のコマンドを実行
sudo ifconfig eth0 down
sudo ifconfig eth0 up
sudo ifconfig eth0 down
実行後固まる。
その後、ssh接続もできなくなったので、OS再インストール
RaspberryPIの固定IPは以下の方法を試してください
cat << _EOF_ | sudo tee -a /etc/dhcpcd.conf
interface eth0
static ip_address=192.168.10.1/24
_EOF_
sudo systemctl restart dhcpcd
ありがとうございます。一度、この方法で試してみますm( )m
上記の指示どおりにやったら、IPの固定化成功。 IP固定化後、この通りにやったが、Wi-Fiの一覧にdronebirdの文字は現れず....。
以下のコマンドを再度打ち込んだら、表示された
sudo systemctl restart dhcpcd
sudo systemctl restart hostapd
sudo systemctl restart dnsmasq
無事、接続を確認
上記の作業でうまく行かなかったときはここも参考になると思う https://dekuo-03.hatenablog.jp/entry/2020/06/08/225915
Raspberry Piをローカルwi-fi接続するためのIsuue