Raspbianの固定IP化
Raspbianを固定IP化するのにあたり、以下の順番でやっていく。
- DHCPで割り振られたIPアドレスを調べる
- 他のPC(母艦)から調べたIPアドレスにSSHでログインする
- /etc/dhcpcd.confを書き換える
- リブートする
ipアドレスを調べる
$ ifconfig -a
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.110.15 netmask 255.255.255.0 broadcast 192.168.110.255
inet6 fe80::20f:d13f:7743:392 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:be:63:00 txqueuelen 1000 (イーサネット)
RX packets 102986 bytes 149294615 (142.3 MiB)
RX errors 0 dropped 631 overruns 0 frame 0
TX packets 55456 bytes 5171364 (4.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
もしくは
ip a s | grep global
inet 192.168.110.15/24 brd 192.168.110.255 scope global wlan0
で、IPアドレスがわかる
sshでRaspbianにログインする
$ ssh -l pi 192.168.110.15
/etc/dhcpcd.confを書き換える
昔は、/etc/networks/interfacesを書き換えればよかたんだけど、Stretchは/etc/dhcpcd.confを書き換えるらしい。
以下の部分を追記した。
/etc/dhcpcd.conf
interface wlan0
static ip_address=192.168.110.50/24
static routers=192.168.110.1
static domain_name_servers=192.168.110.1
リブート
リブートすると、IPアドレスが先程設定した固定IPアドレスで立ち上がってくるので、再度sshでログインできることを確認する。
$ ssh -l pi 192.168.110.50
これでRapiroにRaspberryPiを載せても、遠隔で設定できるようになった。