Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Daemons

Background services that keep a self-hosted Linux server reachable at a fixed domain name, even though the ISP hands it a dynamic IP address.

The server sits behind a residential connection whose public IP changes without warning. These two pieces work together to notice the change, push the new address to the DNS provider, and tell the owner over Telegram that it happened.

What's in here

File Role
linuxdyndns.sh The dynamic-DNS daemon. Polls the current public IP, compares it to what DNS reports, and updates the record when they diverge.
ramsus_bot/ramsus_telegram.py A small Telegram bot that reports the server's IP on demand, and is called by the shell script to push an alert when the IP changes.

How it works

linuxdyndns.sh runs an endless loop:

  1. Reads the IP currently registered in DNS with dig $HOST.$DOMAIN +short.
  2. Every INTERVAL minutes, asks Google's resolver for the machine's real public IP (dig TXT +short o-o.myaddr.l.google.com @ns1.google.com).
  3. If the two disagree, it:
    • calls force_send_ip() from the Telegram module to notify the owner,
    • sends the new address to the Namecheap Dynamic DNS endpoint,
    • sleeps 5 minutes to let the DNS record propagate,
    • re-reads DNS so the next comparison uses the updated value.

The bot itself (ramsus_telegram.py) is built on python-telegram-bot and runs in long-polling mode:

Command Effect
/start, /help Explains what the bot does.
/send Replies with the server's current public IP.

force_send_ip() is not a command — it posts straight to the Telegram Bot API so a script can trigger a message without a user asking first.

Requirements

  • bash, dig (dnsutils / bind-utils), and curl
  • Python 3 with python-telegram-bot and requests:
    pip install python-telegram-bot requests
  • A domain whose DNS is hosted by Namecheap, with Dynamic DNS enabled
  • A Telegram bot token from @BotFather

Configuration

The values committed here are placeholders — replace them before running.

In linuxdyndns.sh:

HOST=@                   # subdomain; "@" means the root record
DOMAIN=example.com       # your domain
PASSWORD=<namecheap-ddns-password>
INTERVAL=30              # minutes between checks

In ramsus_bot/ramsus_telegram.py, both main() and force_send_ip() read a literal token = "token", and force_send_ip() posts to 'chat_id'. Set these to your real bot token and chat ID.

Treat the DDNS password and the bot token as secrets. Read them from environment variables or an untracked file rather than committing them, and note that ip.txt is a runtime scratch file — it holds whatever address the server last resolved to, so it is better left out of version control.

Running it

Directly, from the repository root (the script invokes Python with ramsus_bot as an importable package, so the working directory matters):

chmod +x linuxdyndns.sh
./linuxdyndns.sh

To start it automatically at boot, add a crontab entry:

@reboot sh /path/to/linuxdyndns.sh

To run the interactive bot on its own:

python3 -m ramsus_bot.ramsus_telegram

Related

Telegram_bot is the standalone earlier version of the bot in this repository.

About

Repository for Daemons of my Linux personal server

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages