Port forward automation using Event Juggler: Difference between revisions
No edit summary |
No edit summary |
||
| Line 5: | Line 5: | ||
== Port_forward script == | == Port_forward script == | ||
The script used | 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]]. | ||
| Line 14: | Line 14: | ||
DEST_PORT=443 # Internal port on the target device | DEST_PORT=443 # Internal port on the target device | ||
PROTO="tcp" # Protocol (tcp, udp, both) | PROTO="tcp" # Protocol (tcp, udp, both) | ||
RULE_NAME="DHCP_Forward" | RULE_NAME="DHCP_Forward" | ||
LATEST_LEASE=$(head -n 1 /tmp/dhcp.leases | awk '{print $3}') | LATEST_LEASE=$(head -n 1 /tmp/dhcp.leases | awk '{print $3}') | ||
| Line 35: | Line 36: | ||
uci set firewall.$RULE_NAME.dest_port="$DEST_PORT" | uci set firewall.$RULE_NAME.dest_port="$DEST_PORT" | ||
uci set firewall.$RULE_NAME.proto="$PROTO" | uci set firewall.$RULE_NAME.proto="$PROTO" | ||
uci commit firewall | uci commit firewall | ||
/etc/init.d/firewall restart | /etc/init.d/firewall restart | ||
== Event juggler configuration == | == 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. | |||
[[File:Event juggler new.png|border|class=tlt-border]] | |||
=== Event data configuration === | === 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''' | |||
[[File:Event_juggler_data_configuration.png|border|class=tlt-border]] | |||
=== Action data configuration === | === Action data configuration === | ||
In this setup, we’ll 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. | |||
=== Conditions === | === Conditions === | ||
==== Condition UP ==== | ==== Condition UP ==== | ||
Revision as of 15:00, 16 April 2025
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’ll 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.
