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:~ $

できてた。

0 件のコメント:

コメントを投稿