Мой AC68U прошитый Merlin подключается к OpenVPN серверу и весь трафик идет через туннель, но на некоторые адреса мне нужен прямой линк, поэтому я создаю скрипт для добавления статического маршрута до нужного хоста/сети
1. Включаем в администрировании jffs, ssh
2. Подключаемся по ssh, идем в /jffs/scripts и создаем там файлик openvpn-event [touch openvpn-event]
3. Добавляем в него следующую запись: echo «#!/bin/sh» > openvpn-event
4. Далее добавляю в конец файла нужный мне маршрут: echo «route add -host 85.28.195.50 gw 85.28.192.68» >> openvpn-event
5. Делаем созданный файл исполняемым: chmod a+rx /jffs/scripts/*
Для того чтобы в логе GUI отобразилась какая-нибудь информация, в скрипт можно добавить строчку: logger «openvpn-event скрипт отработал»
Полная команда:
echo «#!/bin/sh
> route add -host 85.28.195.50 gw 85.28.192.68
> logger \»Скрипт openvpn-event успешно отработал\» » > openvpn-event
chmod a+rx /jffs/scripts/*
Доступные скрипты:
services-start
After all other system services have been started at boot. This is the best place to stop one of these services, and restart it with a different configuration, for example (be aware that any time the service gets manually restarted it will revert back to the original setup however).
services-stop
Before all system services are stopped, usually on a reboot.
wan-start
When the WAN interface just came up. Good place to put scripts that depend on the WAN interface (for example, to update an IPv6 tunnel, or a dynamic DNS).
NOTE: Internet connection is unlikely to be active when this script is run. Add a sleep line to delay running until connection complete, or loop until your command succeeds.
firewall-start
The firewall just got started, and filtering rules have been applied. This is where you will usually put your own custom rules in the filter table (but NOT the nat table). Script receives wan interface name (e.g. ppp0) as first parameter.
nat-start
NAT rules (i.e. port forwards and such) have been applied to the NAT table. This is where you will want to put your own NAT table custom rules. For example, a port forward that only allows connections coming from a specific IP.
init-start
Right after JFFS just got mounted, and before any of the services get start. This is the earliest part of the boot process where you can insert something.
pre-mount
Just before a partition gets mounted. This is run in a blocking call and will block the mounting of the partition for which it is invoked till its execution is complete. This is done so that it can be used for things like running e2fsck on the partition before mounting. This script is also passed the device path (e.g. /dev/sda1) being mounted as an argument which can be used in the script using $1.
post-mount
Just after a partition got mounted. $1 is a path where partition has been mounted (e.g. /tmp/mnt/OPT).
unmount
Just before unmounting a partition. This is a blocking script, so be careful with it. The mount point is passed as an argument to the script.
dhcpc-event
Called whenever a DHCP event occurs on the WAN interface. The type of event is passed as an argument; possible event types in the version of udhcpc in ASUSWRT are deconfig (when udhcpc starts and when a lease is lost), bound (when a lease and new IP address is acquired), and renew (when a lease is renewed, but the IP did not change).
openvpn-event
Called whenever an OpenVPN server gets started/stopped, or an OpenVPN client connects to a remote server. Uses the same syntax/parameters as the «up» and «down» scripts in OpenVPN.
ddns-start
Script called at the end of a DDNS update process. This script is also called when setting the DDNS type to «Custom». The script gets passed the WAN IP as an argument. When handling a «Custom» DDNS, this script is also responsible for reporting the success or failure of the update process. See the Custom DDNS section for more information.