WAN IPv4 checker & email notifier for computers behind dynamic IP/DHCP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Pekka Helenius 766c93a5be Service file: remove unneeded [Install] section 6 years ago
images Initial commit 6 years ago
LICENSE Add LICENSE 6 years ago
README.md README: re-add license section 6 years ago
wanchecker.sh Rename the script + use systemd timer functionality 6 years ago
wanchecker@.service Service file: remove unneeded [Install] section 6 years ago
wanchecker@.timer Rename the script + use systemd timer functionality 6 years ago

README.md

WAN IP checker

WAN IPv4 checker & email notifier for server environments behind dynamic DHCP.

About

In many home networks, WAN (Wide Area Network) IP addresses are dynamically allocated by a local ISP. Usually this is acceptable in common household/home use, but not in server use where static DHCP lease/static IP address is very much a mandatory requirement.

However, static IPs are usually offered only to corporate environments, and not everyone wants to pay extra for such in order to establish a simple server environment in home.

This repository contains a systemd service file & a simple bash script to refresh current WAN IPv4 of a Linux server, and notify server admins for any changes in the server WAN IPv4 (Internet) address. This helps in several issues:

  • Server admins are always aware of the current server IPv4 address, whether the address is dynamic or not.

  • Server admins are able to remotely connect to the server environment although the server IP has been changed. This is possible because admins are notified about any WAN IPv4 address changes via email by the server itself, automatically.

Requirements

  • A server computer of any kind

  • Linux OS

    • systemd - service file

    • SSMTP - (SMTP) email client (package: ssmtp (Arch Linux), ssmtp (Ubuntu))

    • dig (package: bind-tools (Arch Linux), dnsutils (Ubuntu))

    • bash

    • awk

Contents

  • systemd user service file: wanchecker@.service

  • systemd user timer file: wanchecker@.timer

  • bash script: wanchecker.sh

Installation

1) Insert wanchecker@.service and wanchecker@.timer into /usr/lib/systemd/user/ folder

  • WAN IP check interval is customizable in systemd timer file. Default value is 20min

2) Insert wanchecker.sh into your /home/myuser/ folder (where myuser is your real username on your Linux system)

3) Configure your email address and message form in wanchecker.sh file. In addition, configure WAN IPv4 log file location (default is $HOME)

  • log file is updated only when WAN IPv4 changes have been detected

3) Install ssmtp, and configure files /etc/ssmtp/revaliases and /etc/ssmtp/ssmtp.conf as described on SSMTP Arch Wiki site.

4) Run

systemctl --user enable wanchecker@myusername.timer && \
systemctl --user start wanchecker@myusername.timer

NOTE: If you change the shell script contents, make sure to run systemctl --user restart wanchecker@myusername.timer afterwards.

Obviously, myusername above refers to your true username on your Linux system.

Images

When server computer discovers a change in its WAN IPv4, it automatically sends an email notification to system administrator(s):

Additionally, server computer keeps a log file which include WAN IPv4 changes and corresponding timestamps:

Useful commands

  • systemctl --user --all list-timers = list all user-specific timers on Linux system, including wanchecker

  • systemctl --user is-active wanchecker@myusername.timer = tells whether wanchecker is running or not

  • systemctl --user status wanchecker@myusername.timer = more compherensive output about the status of wanchecker

etc.

License

This repository uses GPLv3 license. See LICENSE file for details.