Port forward automation using Event Juggler
Introdutcion
This configuration example demonstrates how to automate port forwarding using the Event Juggler function on Teltonika devices. By leveraging this feature, users can automatically create a port forwarding rule for the most recent DHCP lease IP address. This is especially useful in dynamic network environments, as it eliminates the need for manual updates and significantly reduces setup time during on-site deployments.
Port_forward script
The script used in this setup utilizes UCI commands to create a new firewall port forwarding rule, which is applied to the most recent IP address lease from the router's DHCP server. For instructions on creating a runnable script file, refer to our configuration example article - User Scripts examples.
#!/bin/sh
LAN_INTERFACE="br-lan" # Adjust if needed
FORWARD_PORT=8080 # External port to forward
DEST_PORT=443 # Internal port on the target device
PROTO="tcp" # Protocol (tcp, udp, both)
RULE_NAME="DHCP_Forward"
LATEST_LEASE=$(head -n 1 /tmp/dhcp.leases | awk '{print $3}')
LEASE_IP=$(head -n 1 /tmp/dhcp.leases | awk '{print $3}')
if [ -z "$LEASE_IP" ]; then
echo "No DHCP leases found. Exiting."
exit 1
fi
#Remove existing port forward rule if it exists
uci delete firewall.$RULE_NAME 2>/dev/null
uci set firewall.$RULE_NAME="redirect"
uci set firewall.$RULE_NAME.name="$RULE_NAME"
uci set firewall.$RULE_NAME.src="wan"
uci set firewall.$RULE_NAME.src_dport="$FORWARD_PORT"
uci set firewall.$RULE_NAME.dest="lan"
uci set firewall.$RULE_NAME.dest_ip="$LEASE_IP"
uci set firewall.$RULE_NAME.dest_port="$DEST_PORT"
uci set firewall.$RULE_NAME.proto="$PROTO"
uci commit firewall
/etc/init.d/firewall restart
Event juggler configuration
To begin with open router's WebUI, navigate to Services → Event juggler and creat a new instance by entering the name and clicking on "Add" button.
Event data configuration
After creating a new event juggler instance, you will be redirected to the event data configuration window. In this window select the following options:
- Enable - On
- Event type - Log
- Events logs type - Port state
- Events log subtype - LAN1 (depending on the specific port you want to monitor)
- Click on Save & Apply
Action data configuration
In this setup, we will use multiple actions triggered by changes in the LAN1 port status. The first action will run a script stored on the router, which creates a custom port forwarding rule for the latest IP lease. The second action will trigger when the LAN1 port goes DOWN, sending an SMS notification to a specific recipient to let them know the device has been disconnected or is no longer detected on the LAN1 port.
Script action
- Action name - Enter your preferred action name
- Delay - 5 (Sets a time for a delay in seconds when the action will be performed after the event is triggered.)
- Action tpye - Script
- Script file type - Path
- Script file path - Script file location
- Save & Apply
Send SMS action
- Action name - Enter your preferred action name
- Action type - Send SMS
- Text message - Enter your preferred text (In this configuration we will send routers name and the timestamp)
- Recipients - Single
- Phone number - Enter recipients phone number
- Save & Apply
Conditions
Conditions allows to monitor the value of the monitoring event.





