ラベル Raspberry Pi の投稿を表示しています。 すべての投稿を表示
ラベル Raspberry Pi の投稿を表示しています。 すべての投稿を表示

2016年1月26日火曜日

Raspberry Piに無線LANアダプタを使ってWPAで接続する。

このエントリーをはてなブックマークに追加

Raspberry Piを買った時に同時にBUFFALO 無線LAN子機 コンパクトモデル 11n技術・11g/b対応 WLI-UC-GNMも一緒に買ってたので、もったいないから設定してみようと思う。



Raspberry Piに無線LANアダプタを挿した状態で電源を投入してみる。
OS起動後に無線LANアダプタが認識されているか試して見る。

# lsusb
Bus 001 Device 004: ID 0411:01a2 BUFFALO INC. (formerly MelCo., Inc.) WLI-UC-GNM Wireless LAN Adapter [Ralink RT8070]
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

interfaceとしてはどうなっているのか。

# ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:37:97:9a
          inet addr:192.168.2.90  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::e227:b59c:6e54:2f0f/64 Scope:Link
          inet6 addr: 2001:a450:1e6:9900:5f66:5ee:8bd2:afaa/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:750 errors:0 dropped:2 overruns:0 frame:0
          TX packets:585 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:55504 (54.2 KiB)  TX bytes:73519 (71.7 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr dc:fb:02:58:0d:c7
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

IPアドレスは設定されていない。ワイヤレスポイントへのアクセス設定何もしてないから当たり前と言えば当たり前。

/etc/network/interfacesを編集する。

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

WPAのSSIDやキーは/etc/wpa_supplicant/wpa_supplicant.confで設定を行う。
設定を行う前に、wpa_supplicant.conf内に記載するSSIDとキーを暗号化したものを生成しよう。

wpa_passphrase SSID KEYで生成してくれる。

# wpa_passphrase elecom2g-xxxx KEY
network={
 ssid="SSID"
 #psk="平文のキー"
 psk=HASH化されたキー
}

これを/etc/wpa_supplicant/wpa_supplicant.confにコピペし平文のキーは消す。

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
 ssid="SSID"
 psk=HASH化されたキー
 #RSNはWPA2
 proto=RSN
        key_mgmt=WPA-PSK
 #AESの場合CCMP
 pairwise=CCMP
 group=CCMP
        auth_alg=OPEN
}

ここで/etc/init.d/networking restartifconfig wlan0 downifconfig wlan0 upとかやっても無線LANが認識されず。
rebootしたら認識された。。なんでだろう。。。

この時点では
wlan0 Link encap:Ethernet HWaddr dc:fb:02:58:0d:c7
inet addr:192.168.2.112 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: 2001:a450:1e6:9900:6d48:b73:6ca1:d1f1/64 Scope:Global
inet6 addr: fe80::feac:c88:a171:e209/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:353 errors:0 dropped:2 overruns:0 frame:0
TX packets:46 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:110916 (108.3 KiB) TX bytes:8350 (8.1 KiB)
となっていてて、うちの環境では無線LANルータからDHCPで割り振られたIPなので、これを有線LANと同様、固定IPを割り振る。

/etc/dhcpcd.confにIPアドレスを設定する。

interface wlan0
static ip_address=192.168.2.80/24

これでもう一度rebootする。

これで固定IPが無線LANアダプタに割り振られた!

wlan0 Link encap:Ethernet HWaddr dc:fb:02:58:0d:c7
inet addr:192.168.2.80 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: 2001:a450:1e6:9900:6d48:b73:6ca1:d1f1/64 Scope:Global
inet6 addr: fe80::feac:c88:a171:e209/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:657 errors:0 dropped:1 overruns:0 frame:0
TX packets:73 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:174294 (170.2 KiB) TX bytes:11328 (11.0 KiB)

2016年1月25日月曜日

Raspberry Piの有線LANの固定IP設定

このエントリーをはてなブックマークに追加
Raspberry PiのIPは無線LANルータから割り当てられたIPを調べたが、毎回、そんなのもやってられないのでIPを固定化することにする。


とりあえず、今の状況を確認する。

$ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:37:97:9a
          inet addr:192.168.2.111  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: 2001:a450:1e6:9900:6ea:ea6e:6dcd:b12e/64 Scope:Global
          inet6 addr: fe80::e227:b59c:6e54:2f0f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:378 errors:0 dropped:2 overruns:0 frame:0
          TX packets:280 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:30437 (29.7 KiB)  TX bytes:33541 (32.7 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth0にDHCPで割り当てられている。

/etc/network/interfacesを編集しようと思ったら行頭のコメントに

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

とあった。どうやら/etc/dhcpcd.confを編集する必要があるみたい。下記の記述を追記した。

interface eth0
static ip_address=192.168.2.90/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1

そして再起動した後でIPアドレスが変更されているかを確認する。

$ssh pi@192.168.2.90
The authenticity of host '192.168.2.90 (192.168.2.90)' can't be established.
ECDSA key fingerprint is SHA256:j9mtVhz5CCRaCMFi4xR1PcAWEhI+Ot1mFr/HHCQofBg.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.90' (ECDSA) to the list of known hosts.
pi@192.168.2.90's password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Jan 24 19:10:49 2016 from 192.168.2.101
pi@raspberrypi:~ $

できてた。

Raspberry Piにログインしてやったパッケージアップデート

このエントリーをはてなブックマークに追加
Raspberry PiをMacでセットアップするの続き。


rootになってみよう。とりあえずsudoしてみると、すんなりrootになれた。

pi@raspberrypi:~ $ sudo -s
root@raspberrypi:/home/pi#

初期はどうなってるか確認しておこう。とりあえず割と普通。

root@raspberrypi:/home/pi# cd /root
root@raspberrypi:~# pwd
/root
root@raspberrypi:~# ls -aFC
./  ../  .bashrc  .profile

updateをかけてみたくなったのでやってみる。Debian系だからapt-getでできるはず。

まずはパッケージリスト自体の更新を行う。
root@raspberrypi:~# apt-get update
Get:1 http://archive.raspberrypi.org jessie InRelease [13.4 kB]
Get:2 http://mirrordirector.raspbian.org jessie InRelease [15.0 kB]
Get:3 http://archive.raspberrypi.org jessie/main armhf Packages [109 kB]
Get:4 http://mirrordirector.raspbian.org jessie/main armhf Packages [8,962 kB]
Get:5 http://archive.raspberrypi.org jessie/ui armhf Packages [7,639 B]
Ign http://archive.raspberrypi.org jessie/main Translation-en_GB
Ign http://archive.raspberrypi.org jessie/main Translation-en
Ign http://archive.raspberrypi.org jessie/ui Translation-en_GB
Ign http://archive.raspberrypi.org jessie/ui Translation-en
Get:6 http://mirrordirector.raspbian.org jessie/contrib armhf Packages [37.5 kB]
Get:7 http://mirrordirector.raspbian.org jessie/non-free armhf Packages [70.3 kB]
Get:8 http://mirrordirector.raspbian.org jessie/rpi armhf Packages [1,356 B]
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/contrib Translation-en
Ign http://mirrordirector.raspbian.org jessie/main Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/main Translation-en
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/non-free Translation-en
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en_GB
Ign http://mirrordirector.raspbian.org jessie/rpi Translation-en
Fetched 9,217 kB in 40s (226 kB/s)
Reading package lists... Done
root@raspberrypi:~#

この後、インストールされているパッケージのアップデートを行う。apt-get dist-upgradeを使うと依存関係も含めてパッケージをアップデートしてくれる。

# apt-get dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  apt apt-utils bind9-host ca-certificates dpkg dpkg-dev file isc-dhcp-client isc-dhcp-common libapt-inst1.5
  libapt-pkg4.12 libbind9-90 libc-bin libc-dev-bin libc6 libc6-dbg libc6-dev libdns-export100 libdns100 libdpkg-perl
  libirs-export91 libisc-export95 libisc95 libisccc90 libisccfg-export90 libisccfg90 liblwres90 libmagic1
  libpam-modules libpam-modules-bin libpam-runtime libpam0g libpcre3 libpng12-0 libpng12-dev libssl1.0.0 libsystemd0
  libudev1 libwbclient0 libxml2 locales login multiarch-support openssh-client openssh-server openssh-sftp-server
  openssl passwd perl perl-base perl-modules python-rpi.gpio raspi-config rsyslog samba-common ssh sudo systemd
  systemd-sysv tzdata udev
61 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 42.1 MB of archives.
After this operation, 38.9 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.raspberrypi.org/debian/ jessie/main python-rpi.gpio armhf 0.6.1-1 [23.1 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main dpkg armhf 1.17.26 [2,927 kB]
Get:3 http://archive.raspberrypi.org/debian/ jessie/main raspi-config all 20160108 [13.4 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main login armhf 1:4.2-3+deb8u1 [716 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main perl-modules all 5.20.2-3+deb8u3 [2,545 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main perl armhf 5.20.2-3+deb8u3 [2,055 kB]
Get:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main libapt-pkg4.12 armhf 1.0.9.8.2 [711 kB]
:
(省略)
:
Get:56 http://mirrordirector.raspbian.org/raspbian/ jessie/main libsystemd0 armhf 215-17+deb8u3 [84.0 kB]
Get:57 http://mirrordirector.raspbian.org/raspbian/ jessie/main systemd armhf 215-17+deb8u3 [2,214 kB]
Get:58 http://mirrordirector.raspbian.org/raspbian/ jessie/main systemd-sysv armhf 215-17+deb8u3 [34.8 kB]
Get:59 http://mirrordirector.raspbian.org/raspbian/ jessie/main passwd armhf 1:4.2-3+deb8u1 [927 kB]
Get:60 http://mirrordirector.raspbian.org/raspbian/ jessie/main multiarch-support armhf 2.19-18+deb8u2 [179 kB]
Get:61 http://mirrordirector.raspbian.org/raspbian/ jessie/main rsyslog armhf 8.4.2-1+deb8u2 [497 kB]
Fetched 42.1 MB in 4min 1s (174 kB/s)
Extracting templates from packages: 100%
Preconfiguring packages ...
(Reading database ... 30215 files and directories currently installed.)
Preparing to unpack .../dpkg_1.17.26_armhf.deb ...
Unpacking dpkg (1.17.26) over (1.17.25) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up dpkg (1.17.26) ...
(Reading database ... 30215 files and directories currently installed.)
Preparing to unpack .../login_1%3a4.2-3+deb8u1_armhf.deb ...
Unpacking login (1:4.2-3+deb8u1) over (1:4.2-3) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up login (1:4.2-3+deb8u1) ...
(Reading database ... 30215 files and directories currently installed.)
Preparing to unpack .../perl_5.20.2-3+deb8u3_armhf.deb ...
Unpacking perl (5.20.2-3+deb8u3) over (5.20.2-3+deb8u1) ...
Preparing to unpack .../perl-base_5.20.2-3+deb8u3_armhf.deb ...
Unpacking perl-base (5.20.2-3+deb8u3) over (5.20.2-3+deb8u1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up perl-base (5.20.2-3+deb8u3) ...
:
(省略)
:

電源OFFしてもバージョンアップできているか確認してみる。
電源OFFはshutdown -h nowでできる。電源ONはUSBケーブルを抜き差しする。

$ dpkg -l openssh-server
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                     Version           Architecture      Description
+++-========================-=================-=================-=====================================================
ii  openssh-server           1:6.7p1-5+deb8u1  armhf             secure shell (SSH) server, for secure access from rem

無事アップデートは完了していた。



2016年1月24日日曜日

Raspberry PiをMacでセットアップする

このエントリーをはてなブックマークに追加
1年ほど前に買ったRaspberry Pi Type B 512MBをそのまま放ったらかしにしてたので、改めてセットアップしてみることにした。


まずはSDカードにRaspberry Pi用のOSをインストールしないといけない。今回はTranscend SDHCカード 16GB Class10 (無期限保証) TS16GSDHC10E (FFP)を使う事にした。




まずはRaspberry Pi Downloads - Software for the Raspberry PiのサイトからRaspbian Liteを選んでみた。ダウンロードしたファイルを解凍するとimgファイルが出てくる。

そのあと、SDカードにimgファイルを書き込むためのRPi-sd card builderをダウンロードする。
*本日時点でv1.2
これを解凍するとこんなマークのアプリがでてくるので実行する。


するとファイルを選択するウィンドウが表示されるので、先ほど解凍してできたRaspberryのimgファイルを選択する。

SDカードが刺さっているか聞かれるので「Continue」を選択。


刺さっているSDカードを選んでOK。


パスワードを入力。


右上で処理中は歯車が回るのでそのままにしておく。


終わったらこうなる。


SDカードを抜いてRaspberry Piに刺そう。

家にはUSBキーボードもないしテレビも見ながらセットアップしたいので、こんな感じでつないでみた。


無線LANルータからIPアドレスを調べてSSHでログインしてみる。

ID:pi
PASSWORD:raspberry

$ ssh pi@192.168.2.111
The authenticity of host '192.168.2.111 (192.168.2.111)' can't be established.
ECDSA key fingerprint is SHA256:165kpyzknnWOrFZW604DKsaGtzRDf6jPhFrOB/Hdiks.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.111' (ECDSA) to the list of known hosts.
pi@192.168.2.111's password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
pi@raspberrypi:~ $

ログイン成功!