0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Raspberry Pi 4Bで自宅サーバー入門-②ネットワークの設定

Last updated at Posted at 2025-06-24

※自宅ネットワークの関係で更新停止中です

前回→Raspberry Pi 4Bで自宅サーバー入門-①OSインストール
次回→
ドメインを取得している前提です。


IPアドレスの固定

OSインストール時にユーザ/パスワードを設定していたら、それを使用してログインします。
(設定していない場合 初期ユーザ名/パスワード:ubuntu)

$ sudo apt update
$ sudo apt install net-tools

使用するIPアドレスを決定します。
Raspberry PiでUbuntu Serverの初期設定(初回起動からIPアドレス固定まで)

$ cd /etc/netplan

バックアップを取ります。

$ sudo cp 50-cloud-init.yaml 50-cloud-init.yaml.bak

以下を記入します。
キーボードがUS配列で入力しにくい場合は、以下の記事を参考に日本語レイアウトへ変更します。
Ubuntu Serverのキーボード を日本語レイアウトに変更

network:
    ethernets:
        eth0:
            dhcp4: false
            addresses: [固定したいIPアドレス/サブネットマスク]
            routes: 
              - to: default
                via: デフォルトゲートウェイのIPアドレス
            nameservers:
              addresses: [DNSアドレス]
    version: 2

※addressesには[ ]が必要です。

$ sudo reboot

IPアドレスとホスト名を関連付ける

$ sudo hostnamectl set-hostname your-hostname
$ hostnamectl

hostnamectlでホスト名が変更されているか確認します。
続いて、

$ sudo nano /etc/hosts

でhostsファイルをひらき、

IPアドレス ドメイン名

を追加します。

$ sudo reboot

で再起動し、設定を確認します。

SSHリモートログインの設定

OSインストール時にSSH認証の設定をしていれば、別のPCからログインできるはずです。

ssh username@IPアドレス

デーモンの自動起動を有効にします

$ sudo systemctl enable ssh

SSHデーモンの状態を確認します。

$ sudo systemctl status ssh

sudo rebootで再起動してもアクティブかを確認します。

ファイアウォール(ufw)を設定する

$ sudo apt update
$ sudo apt install ufw
$ sudo ufw enable
$ sudo ufw allow ssh

sudo ufw status verboseを実行し、Status: activeであることを確認します。

タイムゾーンの設定

dateでタイムゾーンを確認します。JSTならそのままで大丈夫です。
UTCだったので、タイムゾーンを変更します。

$ sudo timedatectl set-timezone Asia/Tokyo

再度dateを実行し、JSTになっていることを確認してください。


前回→Raspberry Pi 4Bで自宅サーバー入門-①OSインストール
次回→

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?