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.

89 lines
3.4 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. # WAN IP checker
  2. WAN IPv4 checker & email notifier for server environments behind dynamic DHCP.
  3. ## About
  4. 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.
  5. 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.
  6. 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:
  7. - Server admins are always aware of the current server IPv4 address, whether the address is dynamic or not.
  8. - 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.
  9. ## Requirements
  10. - A server computer of any kind
  11. - Linux OS
  12. - systemd - service file
  13. - [SSMTP](https://wiki.archlinux.org/index.php/SSMTP) - (SMTP) email client (package: `ssmtp` (Arch Linux), `ssmtp` (Ubuntu))
  14. - dig (package: `bind-tools` (Arch Linux), `dnsutils` (Ubuntu))
  15. - bash
  16. - awk
  17. ## Contents
  18. - systemd **user** service file: `wanchecker@.service`
  19. - systemd **user** timer file: `wanchecker@.timer`
  20. - bash script: `wanchecker.sh`
  21. ## Installation
  22. **1)** Insert `wanchecker@.service` and `wanchecker@.timer` into `/usr/lib/systemd/user/` folder
  23. - WAN IP check interval is customizable in systemd timer file. Default value is `20min`
  24. **2)** Insert `wanchecker.sh` into your `/home/myuser/` folder (where `myuser` is your real username on your Linux system)
  25. **3)** Configure your email address and message form in `wanchecker.sh` file. In addition, configure WAN IPv4 log file location (default is `$HOME`)
  26. - log file is updated only when WAN IPv4 changes have been detected
  27. **3)** Install `ssmtp`, and configure files `/etc/ssmtp/revaliases` and `/etc/ssmtp/ssmtp.conf` as described on [SSMTP Arch Wiki site](https://wiki.archlinux.org/index.php/SSMTP).
  28. **4)** Run
  29. ```
  30. systemctl --user enable wanchecker@myusername.timer && \
  31. systemctl --user start wanchecker@myusername.timer
  32. ```
  33. **NOTE:** If you change the shell script contents, make sure to run `systemctl --user restart wanchecker@myusername.timer` afterwards.
  34. Obviously, `myusername` above refers to your true username on your Linux system.
  35. ## Images
  36. When server computer discovers a change in its WAN IPv4, it automatically sends an email notification to system administrator(s):
  37. ![](images/wanip_email.png)
  38. Additionally, server computer keeps a log file which include WAN IPv4 changes and corresponding timestamps:
  39. ![](images/wanip_log.png)
  40. ## Useful commands
  41. - `systemctl --user --all list-timers` = list all user-specific timers on Linux system, including `wanchecker`
  42. - `systemctl --user is-active wanchecker@myusername.timer` = tells whether wanchecker is running or not
  43. - `systemctl --user status wanchecker@myusername.timer` = more compherensive output about the status of `wanchecker`
  44. etc.
  45. ## License
  46. This repository uses GPLv3 license. See [LICENSE](./LICENSE) file for details.