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.

155 lines
5.9 KiB

6 years ago
4 years ago
6 years ago
6 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
6 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
4 years ago
6 years ago
4 years ago
4 years ago
4 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
6 years ago
4 years ago
6 years ago
6 years ago
6 years ago
6 years ago
4 years ago
6 years ago
4 years ago
4 years ago
  1. # WAN IP checker
  2. WAN IPv4 checker & email notifier for computer 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. If configuring a static WAN IP is not an option to you, consider setting up a simple notifier which let's you know when your WAN IP address changes.
  6. 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.
  7. This repository contains a Systemd service & a simple bash script to refresh current WAN IPv4 of a Linux computer, and notify administration for any changes in the WAN IPv4 (Internet) address. This method addresses to several issues:
  8. - Administreation is always aware of the current server IPv4 address, whether the address is dynamic or not.
  9. - Administration is 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.
  10. ## Failure countermeasures
  11. The WAN IP checker script has several countermeasures for the following failures:
  12. - **DNS name resolution fails**: DNS servers defined in `/etc/resolv.conf` can not be contacted
  13. - Fall back to DNS servers listed in [wanchecker.sh](ssmtp_conf-sample/wanchecker.sh)
  14. - **Sending email fails**
  15. - Attempt several times until informing that sending an email message has failed
  16. ------------
  17. ## Requirements
  18. - Linux OS
  19. - systemd
  20. - [sSMTP](https://wiki.archlinux.org/index.php/SSMTP) - (SMTP) email client (package: `ssmtp` (Arch Linux), `ssmtp` (Ubuntu))
  21. - curl
  22. - bash
  23. - awk
  24. - cat
  25. - grep
  26. - sed
  27. - wc
  28. - **Optionally:** [resolvconf-override (GitHub/hadess)](https://github.com/hadess/resolvconf-override)
  29. ## Contents
  30. - systemd **system** service file: [wanchecker.service](wanchecker.service)
  31. - Service is run as user `mail` and group `mail`. Change these if necessary.
  32. - systemd **system** timer file: [wanchecker.timer](wanchecker.timer)
  33. - WAN IP check interval is customizable in systemd timer file. Default value is `15min`
  34. - [sSMTP sample configuration files](ssmtp_conf-sample)
  35. - [ssmtp.conf](ssmtp_conf-sample/ssmtp.conf)
  36. - [revaliases](ssmtp_conf-sample/revaliases)
  37. - [wanchecker.sh](ssmtp_conf-sample/wanchecker.sh)
  38. - [wanchecker.conf](ssmtp_conf-sample/wanchecker.conf)
  39. - Default log file location `/var/spool/mail/ip_wan.log` is defined in this file. The log file is updated only when WAN IPv4 changes have been detected.
  40. ## Manual installation & configuration
  41. **1)** Install `ssmtp` package
  42. **2)** Deploy provided files as follows:
  43. | Repository location | Filesystem location |
  44. |-----------------------------------|----------------------------------------|
  45. | ssmtp_conf-sample/wanchecker.sh | /etc/ssmtp/wanchecker.sh |
  46. | ssmtp_conf-sample/wanchecker.conf | /etc/ssmtp/wanchecker.conf |
  47. | wanchecker.service | /etc/systemd/system/wanchecker.service |
  48. | wanchecker.timer | /etc/systemd/system/wanchecker.service |
  49. | File | Owner (u.g) | Permission bits |
  50. |----------------------------------------|-------------|-----------------|
  51. | /etc/ssmtp/wanchecker.sh | root.mail | 0750 |
  52. | /etc/ssmtp/wanchecker.conf | root.mail | 0640 |
  53. | /etc/systemd/system/wanchecker.service | root.root | 0644 |
  54. | /etc/systemd/system/wanchecker.service | root.root | 0644 |
  55. **3)** Configure `sSMTP` files `/etc/ssmtp/revaliases` ([sample](ssmtp_conf-sample/revaliases)), `/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).
  56. **4)** Configure file `/etc/ssmtp/wanchecker.conf` ([sample](ssmtp_conf-sample/wanchecker.conf))
  57. **5)** If necessary, configure sSMTP as described in [sSMTP Readme file](ssmtp_conf-sample/README.md).
  58. **6)** Run (as root or with `sudo`):
  59. ```
  60. systemctl enable wanchecker.timer && \
  61. systemctl start wanchecker.timer
  62. ```
  63. **7) (optional)** Install [resolvconf-override](https://github.com/hadess/resolvconf-override)
  64. ## Arch Linux installation & configuration
  65. **1)** Use provided [PKGBUILD](arch_linux/PKGBUILD) file
  66. **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).
  67. **3)** Configure file `/etc/ssmtp/wanchecker.conf` ([sample](ssmtp_conf-sample/wanchecker.conf))
  68. **4)** Run (as root or with `sudo`):
  69. ```
  70. systemctl enable wanchecker.timer && \
  71. systemctl start wanchecker.timer
  72. ```
  73. **5) (optional)** Install [resolvconf-override](https://github.com/hadess/resolvconf-override). Use provided Arch Linux [PKGBUILD file](arch_linux/resolvconf-override/PKGBUILD).
  74. ----------
  75. ## Images
  76. When server computer discovers a change in its WAN IPv4, it automatically sends an email notification to system administrator(s):
  77. ![](images/wanip_email.png)
  78. Additionally, server computer keeps a log file which include WAN IPv4 changes and corresponding timestamps:
  79. ![](images/wanip_log.png)
  80. ## Useful commands
  81. - `systemctl --all list-timers` = list all system timers on Linux system, including `wanchecker` timer
  82. - `systemctl is-active wanchecker.timer` = tells whether `wanchecker` timer is running or not
  83. - `systemctl status wanchecker.timer` = more compherensive output about the status of `wanchecker` timer
  84. ## License
  85. This repository uses GPLv3 license. See [LICENSE](./LICENSE) file for details.