Changing the local address of an EoIP (Ethernet over IP) tunnel on a Mikrotik router can be done using a script. Below is a step-by-step guide on how to achieve this using Mikrotik's scripting language, which is based on RouterOS commands.
Step-by-Step Script to Change the Local Address of an EoIP Tunnel
-
Identify the EoIP Tunnel:
First, you need to identify the name or number of the EoIP tunnel you want to modify. You can list all EoIP tunnels to find the correct one.
-
Script to Change the Local Address:
Here is a script that changes the local address of a specified EoIP tunnel.
:local tunnelName "eoip-tunnel1" ; # Change this to your EoIP tunnel name or number
:local newLocalAddress "192.168.2.1" ; # Change this to the new local address you want to set
# Check if the EoIP tunnel exists
/interface eoip tunnel print where name=$tunnelName limit=1 do={
:local tunnelFound true
:local currentTunnel [$tunnel]
}
:if ({$tunnelFound} != true) do={
:put "EoIP tunnel $tunnelName not found!"
exit
}
# Change the local address of the EoIP tunnel
/interface eoip tunnel set $currentTunnel local-address=$newLocalAddress
:put "Local address of EoIP tunnel $tunnelName changed to $newLocalAddress"
Explanation:
-
:local tunnelName "eoip-tunnel1"
- Replace
"eoip-tunnel1" with the name or number of your EoIP tunnel.
-
:local newLocalAddress "192.168.2.1"
- Replace
"192.168.2.1" with the new local address you want to assign to the EoIP tunnel.
-
/interface eoip tunnel print where name=$tunnelName limit=1 do={...}
- This command checks if the EoIP tunnel with the specified name exists. If it does the tunnel is stored in the variable
currentTunnel
-
:if ({$tunnelFound} != true) do={...}
- This condition checks if the tunnel was found. If not it will print an error message and exit the script.
-
/interface eoip tunnel set $currentTunnel local-address=$newLocalAddress
- This command sets the new local address for the EoIP tunnel.
-
:put "Local address of EoIP tunnel $tunnelName changed to $newLocalAddress"
- This line prints a confirmation message to the console.
Running the Script
-
Access the Mikrotik Router:
- Use Winbox, WebFig, or SSH to access your Mikrotik router.
-
Open the Script Window:
- In Winbox, go to
System > Scripts.
- In WebFig, go to
System > Scripts.
- If using SSH, you can directly enter the script in the terminal.
-
Create a New Script:
- Click on the
+ button to create a new script.
- Copy and paste the script above into the script editor.
-
Modify the Script:
- Change the
tunnelName and newLocalAddress variables to match your configuration.
-
Run the Script:
- Click on the
Run button to execute the script.
- Alternatively you can save the script and run it using the command
/system script run <script-name>
-
Verify the Change:
Scheduling the Script (Optional)
If you need to run this script automatically at a certain time or event, you can schedule it:
- Go to
System > Scheduler.
- Click the
+ button to create a new scheduler.
- Set the
Name, Start Time, Interval, and On Event.
- In the
Action field, select system script and choose the script you created.
- Click
OK to save the scheduler.
This will automatically run your script according to the schedule you set.
By following these steps, you can successfully change the local address of an EoIP tunnel on your Mikrotik router using a script.