2017年12月7日木曜日

What's Tips for Raspberry Pi :Stretch liteの IP アドレス固定と 通信許可(SSH)

Raspberry Pi Raspbian stretch が今夏公開されました。
Desktop版は、イメージが4Gbyte SDカードに収まらなくなって久しいのですが、余っている4GbyteのSDカードを使って Lite版で24時間稼働サーバー(..といっても超低消費電力ですから)の構築を行います。IPアドレスの固定と、各種設定をCUI (character user interface, CUI)入力を行うためのSSHサーバーを構築します。
以後ターミナル接続して各種カスタマイズを行えます。

1) IPアドレス固定
IPアドレスが判らないまたはDHCPにより電源投入時にランダムに決定されるIPアドレスの場合ターミナル接続する場合のアドレスが変化し接続が難しいため最初にIPアドレスを固定します。
以前は、/etc/network/interfacesに記載していましたがstretchでは/etc/dhcpd.confに記述するように..
とコメントに記載されていますので これを編集します。


ログインします。

初期ユーザー名は :pi
初期パスワードは :raspberry
です




現在値を確認


root@raspberrypi:/etc/network# ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.xx.65 netmask 255.255.255.0 broadcast 192.168.xx.255

inet6 xxxx::xxxx:xxxx:xxxx:xxxx prefixlen 64 scopeid 0x20<link>

ether xx:xx:xx:xx:xx:xx txqueuelen 1000 (Ethernet)

RX packets 5377 bytes 563288 (550.0 KiB)

RX errors 0 dropped 2 overruns 0 frame 0

TX packets 1065 bytes 100796 (98.4 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10<host>

loop txqueuelen 1 (Local Loopback)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


管理者権限を得ます。

pi@raspberrypi:~ $ sudo su

dhcpd.confに固定ipを設定します。

root@raspberrypi:/# cd /etc

ファイル名を確認します


root@raspberrypi:/etc# ls -l .
total 748
-rw-r--r-- 1 root root    2981 Sep  7 14:47 adduser.conf
drwxr-xr-x 2 root root    4096 Sep  7 15:13 alternatives
:
:

-rw-r--r-- 1 root root    2969 May 21  2017 debconf.conf
-rw-r--r-- 1 root root       4 Jul 27 22:17 debian_version
drwxr-xr-x 2 root root    4096 Sep  7 15:12 default
-rw-r--r-- 1 root root     604 Jun 26  2016 deluser.conf
drwxr-xr-x 4 root root    4096 Sep  7 14:53 dhcp
-rw-rw-r-- 1 root netdev  1630 Jul 17 14:13 dhcpcd.conf

-rw-r--r-- 1 root root      42 Sep  7 15:54 dhcpcd.duid
-rw-r--r-- 1 root root    1100 Sep  7 15:12 dphys-swapfile
drwxr-xr-x 4 root root    4096 Sep  7 15:11 dpkg



:
:


root@raspberrypi:/etc#


簡易テキストエディタ nanoを起動して dhcpcd.confを編集します。
nanoは単純な作業しかできませんが、設定ファイルを編集するなら簡単に覚えることができて便利なテキストエディタです。ubuntuでも使えますので是非マスターしておいてください。

変更部分はご自身のネットワーク環境に合わせてください。

root@raspberrypi:/etc# nano 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

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# Example static IP configuration:

#interface eth0

interface eth0

#static ip_address=192.168.0.10/24
static ip_address=192.168.0.10/24

#static routers=192.168.0.1

static routers=192.168.0.1

#static domain_name_servers=192.168.0.1 8.8.8.8
static domain_name_servers=192.168.0.1 8.8.8.8

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0
root@raspberrypi:/etc#





再起動します
root@raspberrypi:/etc#reboot












0 件のコメント:

コメントを投稿