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.
| 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. |
linuxdyndns.sh runs an endless loop:
- Reads the IP currently registered in DNS with
dig $HOST.$DOMAIN +short. - Every
INTERVALminutes, asks Google's resolver for the machine's real public IP (dig TXT +short o-o.myaddr.l.google.com @ns1.google.com). - 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.
- calls
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.
bash,dig(dnsutils/bind-utils), andcurl- Python 3 with
python-telegram-botandrequests:pip install python-telegram-bot requests
- A domain whose DNS is hosted by Namecheap, with Dynamic DNS enabled
- A Telegram bot token from @BotFather
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 checksIn 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.txtis a runtime scratch file — it holds whatever address the server last resolved to, so it is better left out of version control.
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.shTo start it automatically at boot, add a crontab entry:
@reboot sh /path/to/linuxdyndns.shTo run the interactive bot on its own:
python3 -m ramsus_bot.ramsus_telegramTelegram_bot is the standalone
earlier version of the bot in this repository.