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.

93 lines
3.3 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
  1. # WAN IP checker
  2. WAN IPv4 checker & email notifier for server environments behind dynamic IP address.
  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 **system** service file: `wanchecker@.service`
  19. - systemd **system** timer file: `wanchecker@.timer`
  20. - bash script: `wanchecker.sh`
  21. ## Installation
  22. Configuration can be splitted into two parts as follows.
  23. ### ssmtp
  24. To-be-added
  25. ### wanip-checker
  26. **1)** Insert `wanchecker@.service` and `wanchecker@.timer` into `/usr/lib/systemd/system/` folder
  27. - WAN IP check interval is customizable in systemd timer file. Default value is `20min`
  28. **2)** Insert `wanchecker.sh` into your `/home/myuser/` folder (where `myuser` is your real username on your Linux system)
  29. **3)** Configure your email address and message form in `wanchecker.sh` file. Configure WAN IPv4 log file location (default is `$HOME`)
  30. - log file is updated only when WAN IPv4 changes have been detected
  31. **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).
  32. **4)** Run (as root or with `sudo)
  33. ```
  34. systemctl enable wanchecker@myusername.timer && \
  35. systemctl start wanchecker@myusername.timer
  36. ```
  37. where `myusername` refers to your true username on your Linux system.
  38. ## Images
  39. When server computer discovers a change in its WAN IPv4, it automatically sends an email notification to system administrator(s):
  40. ![](images/wanip_email.png)
  41. Additionally, server computer keeps a log file which include WAN IPv4 changes and corresponding timestamps:
  42. ![](images/wanip_log.png)
  43. ## Useful commands
  44. - `systemctl --all list-timers` = list all system timers on Linux system, including `wanchecker`
  45. - `systemctl is-active wanchecker@myusername.timer` = tells whether wanchecker is running or not
  46. - `systemctl status wanchecker@myusername.timer` = more compherensive output about the status of `wanchecker`
  47. ## License
  48. This repository uses GPLv3 license. See [LICENSE](./LICENSE) file for details.