0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RaspberryPi4 DDNS編

Last updated at Posted at 2020-02-09

#はじめに
停電とか起きてもRaspberryPiにドメインアクセスできるようにieServer + systemdで自動化する。

ieServerの登録

ココらへんを参考に登録する
https://www.akakagemaru.info/port/ieserver.html

スクリプトの準備

mkdir ~/ddns
cd ~/ddns
wget http://ieserver.net/ddns-update.txt
mv ddns-update.txt ddns-update.pl
vim ddns-update.pl

ddns-update.plはshift-jisなのでvimで:e ++enc=shift-jisでエンコード指定して開く
以下の設定を自身の登録内容に合わせて設定する

ddns-update.pl
$ACCOUNT         = "xxxxxxx";     # アカウント(サブドメイン)名設定
$DOMAIN          = "orz.hm";     # ドメイン名設定
$PASSWORD        = "xxxxxxx";     # パスワード設定

実行してみて、グローバルIPが表示されればOK

./ddns-update.pl
cat current_ip
 xxx.xxx.xxx.xxx # 自分のグローバルIP

systemdへの登録

/etc/systemd/system/ddns.serviceを作成

ddns.service
[Unit]
Description=ddns update script

[Service]
Type=simple
WorkingDirectory=/home/pi/ddns/
ExecStart=/usr/bin/perl /home/pi/ddns/ddns-update.pl

[Install]
WantedBy=multi-user.target

/etc/systemd/system/ddns.timerを作成

ddns.timer
[Unit]
Description=ddns update timer

[Timer]
OnCalendar=*-*-* 0,12:00
Unit=ddns.service

[Install]
WantedBy=multi-user.target

起動許可

sudo systemctl enable ddns.timer
sudo reboot
# 再起動後
sudo systemctl status ddns.timer

指定した時間に~/ddns/current_ipが更新されていればOK
確認前に一度削除しておくと良いかも

以上

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?