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.

91 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
  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
  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](wanchecker.service)
  19. - systemd **system** timer file: [wanchecker.timer](wanchecker.timer)
  20. - [sSMTP sample configuration files](ssmtp_conf-sample)
  21. - [ssmtp.conf](ssmtp_conf-sample/ssmtp.conf)
  22. - [revaliases](ssmtp_conf-sample/revaliases)
  23. - [wanchecker.sh](ssmtp_conf-sample/wanchecker.sh)
  24. ## Installation & configuration
  25. **1)** Install `ssmtp` package
  26. **2)** Configure files `/etc/ssmtp/revaliases` ([sample](ssmtp_conf-sample/revaliases)) and `/etc/ssmtp/ssmtp.conf` ([sample](ssmtp_conf-sample/ssmtp.conf)). More information about these files on [sSMTP Arch Wiki site](https://wiki.archlinux.org/index.php/SSMTP).
  27. **3)** Insert [wanchecker.sh](ssmtp_conf-sample/wanchecker.sh) into `/etc/ssmtp/` folder.
  28. **4)** Configure sSMTP as described in [sSMTP Readme file](ssmtp_conf-sample/README.md).
  29. **5)** Insert `wanchecker.service` and `wanchecker.timer` into `/usr/lib/systemd/system/` folder
  30. - WAN IP check interval is customizable in systemd timer file. Default value is `20min`
  31. - This log file is updated only when WAN IPv4 changes have been detected
  32. **6)** Run (as root or with `sudo`)
  33. ```
  34. systemctl enable wanchecker.timer && \
  35. systemctl start wanchecker.timer
  36. ```
  37. ## Images
  38. When server computer discovers a change in its WAN IPv4, it automatically sends an email notification to system administrator(s):
  39. ![](images/wanip_email.png)
  40. Additionally, server computer keeps a log file which include WAN IPv4 changes and corresponding timestamps:
  41. ![](images/wanip_log.png)
  42. ## Useful commands
  43. - `systemctl --all list-timers` = list all system timers on Linux system, including `wanchecker`
  44. - `systemctl is-active wanchecker.timer` = tells whether `wanchecker` is running or not
  45. - `systemctl status wanchecker.timer` = more compherensive output about the status of `wanchecker`
  46. ## License
  47. This repository uses GPLv3 license. See [LICENSE](./LICENSE) file for details.