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.

68 lines
2.5 KiB

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. This repository contains a systemd service file & a simple bash script to refresh current WAN IPv4 of a server, and notify server admin for any changes in the server WAN (Internet) address. This helps in several issues:
  5. - Server admin is always aware of the current server IPv4 address, whether the address is dynamic or not.
  6. - Server admin is able to remotely connect to the server environment although the server IP may have been changed. This is possible because the admin is notified about any WAN IPv4 address changes via email by the server itself, automatically.
  7. In many home networks, WAN (Wide Area Network) IP addresses are dynamically allocated by a local ISP. Usually this is okay in common household/home use, but not in server use.
  8. In most server environments, static DHCP lease/static IP address is a mandatory requirement. However, static IPs are usually offered only for corporate environments, and not everyone wants to pay extra for such in order to establish a simple server environment in home.
  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) - email client
  14. - bash
  15. - awk
  16. ## Contents
  17. - systemd **user** service file: `wanip-checker@.service`
  18. - bash script: `wanip-checker.sh`
  19. ## Installation
  20. **1)** Insert `wanip-checker@.service` into `/usr/lib/systemd/user/` folder
  21. - WAN IP check interval is customizable in systemd service file. Default value is `60` (1 min)
  22. **2)** Insert `wanip-checker.sh` into your `/home/myuser/` folder
  23. **3)** Configure your email address and message form in `wanip-checker.sh` file
  24. **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).
  25. **4)** Run
  26. ```
  27. systemctl --user enable wanip-checker@myusername.service && \
  28. systemctl --user start wanip-checker@myusername.service && \
  29. systemctl --user daemon-reload
  30. ```
  31. **NOTE:** If you change the script contents, make sure to run `systemctl --user restart wanip-checker@myusername.service` afterwards.
  32. ## Images
  33. When server computer discovers changes in WAN IPv4, it automatically sends an email notification for system administrators:
  34. ![](images/wanip_email.png)
  35. Additionally, server computer keeps a log file which include WAN IPv4 changes and corresponding timestamps:
  36. ![](images/wanip_log.png)