> For the complete documentation index, see [llms.txt](https://docs.mikopbx.com/mikopbx/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mikopbx.com/mikopbx/faq/management/backup-internet.md).

# Резервный интернет и перерегистрация провайдеров

Если АТС работает за NAT и серый публичный IP адрес изменился, то АТС не сможет получить входящий вызов пока не пройдет регистрация на стороне провайдера, по умолчанию это может занять от 2х до 6 мин.

## Создание скрипта проверки IP

1. Подключитесь к MikoPBX по протоколу SSH (документация о различных способах подключения — [здесь](/mikopbx/faq/troubleshooting/connecting-to-a-pbx-using-ssh.md))
2. Создайте новый файл скрипта командой:

```
cat > /storage/usbdisk1/mikopbx/custom_modules/update_ip.sh
```

Система запросит ввод с клавиатуры, вставьте содержимое скрипта:

```bash
#!/bin/bash
# Файл для хранения предыдущего IP
IP_FILE="/tmp/last_ip.txt"
# Команда для получения текущего IP
CURRENT_IP=$(/usr/bin/curl -s https://checkip.amazonaws.com)
# Проверка, существует ли файл с предыдущим IP
if [ -f "$IP_FILE" ]; then
    LAST_IP=$(cat "$IP_FILE")
else
    LAST_IP=""
fi
# Сравнение текущего IP с предыдущим
if [ "$CURRENT_IP" != "$LAST_IP" ]; then
    /bin/busybox logger -t 'UpdateIP' "IP изменился: $LAST_IP -> $CURRENT_IP";
    echo "$CURRENT_IP" > "$IP_FILE"
    # Выполнение команды Asterisk
    /usr/sbin/asterisk -rx 'pjsip send register *all'
fi
```

3. Нажмите `CTRL + D` для завершения ввода.
4. Сделайте файл исполняемым:

```
chmod +x /storage/usbdisk1/mikopbx/custom_modules/update_ip.sh
```

## Планирование сценария перерегистрации

1. Перейдите в web-интерфейс MikoPBX -> "**Система**" -> "**Кастомизация системных файлов**":

<figure><img src="/files/Upq0VL0XG34cyY35yCmo" alt=""><figcaption><p>Раздел "<strong>Кастомизация системных файлов</strong>"</p></figcaption></figure>

2. Откройте для редактирования файл `/var/spool/cron/crontabs/root` :

<figure><img src="/files/63T7t8ZVuyuXCJvUxevu" alt=""><figcaption><p>Редактирование файла crontabs/root</p></figcaption></figure>

3. Добавьте задачу в конец файла `/var/spool/cron/crontabs/root`

```
*/1 * * * * /storage/usbdisk1/mikopbx/custom_modules/update_ip.sh > /dev/null 2> /dev/null
```

Теперь каждую минуту будет выполняться проверка на изменение публичного адреса, если адрем изменился, то будет выполнена перерегистрация всех провайдеров.

<figure><img src="/files/6h633PlQIm1LMJ1YARzH" alt=""><figcaption><p>Планирование задачи</p></figcaption></figure>

{% hint style="success" %}
В системном логе `system/messages` отобразиться информационное сообщение об изменении IP.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mikopbx.com/mikopbx/faq/management/backup-internet.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
