Skip to content
MikroTik RouterOS Docs

Netwatch (Host Monitoring)

For the impatient: monitor a host and run scripts on state change.

# Basic host monitoring
/tool/netwatch/add host=8.8.8.8 interval=30s comment="Google DNS"
# With failover scripts
/tool/netwatch/add host=8.8.8.8 interval=10s \
down-script="/log warning \"Primary WAN down\"" \
up-script="/log warning \"Primary WAN up\""

Verify with:

/tool/netwatch/print

What this does: Netwatch monitors network host availability using various probe types (ICMP, TCP, HTTP, DNS) and executes scripts when hosts go up or down. It’s essential for WAN failover, service health monitoring, and automated alerting.

When to use this:

  • WAN failover detection and automatic route switching
  • Service availability monitoring (web servers, DNS, etc.)
  • Automated alerts via email or log when hosts fail
  • Triggering configuration changes based on network conditions

Prerequisites:

  • Network connectivity to monitored hosts
  • Scripts must have appropriate permissions (read,write,test,reboot)
  • For email alerts: /tool/e-mail configured
TypeUse CaseVersion
simpleBasic ICMP ping (legacy)6.x+
icmpAdvanced ping with thresholds7.4+
tcp-connTCP port connectivity7.4+
http-getHTTP service check7.4+
https-getHTTPS with certificate validation7.4+
dnsDNS server response7.4+

Monitor a host with simple ICMP:

/tool/netwatch/add host=8.8.8.8 interval=30s timeout=3s comment="Google DNS"

Add scripts that run when the host goes down or comes back up:

/tool/netwatch/set [find host=8.8.8.8] \
down-script="/log error \"Host 8.8.8.8 is DOWN\"" \
up-script="/log info \"Host 8.8.8.8 is UP\""

Check the current status:

/tool/netwatch/print

Expected output:

Flags: X - disabled
# HOST TYPE INTERVAL TIMEOUT STATUS SINCE
0 8.8.8.8 simple 30s 3s up jan/16/2026 10:00:00

Automatically switch routes when primary WAN fails:

Step 1: Configure routes with comments

/ip/route/add dst-address=0.0.0.0/0 gateway=192.168.1.1 distance=1 comment=primary
/ip/route/add dst-address=0.0.0.0/0 gateway=192.168.2.1 distance=2 comment=backup

Step 2: Create netwatch with failover scripts

/tool/netwatch/add host=8.8.8.8 interval=10s timeout=2s \
down-script={
/ip/route/set [find comment=primary] disabled=yes
/log warning "Primary WAN down - switched to backup"
} \
up-script={
/ip/route/set [find comment=primary] disabled=no
/log warning "Primary WAN up - restored"
}

Monitor with latency and packet loss thresholds:

/tool/netwatch/add host=10.0.0.1 type=icmp interval=30s \
packet-count=5 \
packet-interval=100ms \
thr-avg=50ms \
thr-max=200ms \
thr-loss-percent=20 \
down-script="/log error \"High latency or packet loss on link\""

The host is marked “down” if:

  • Average latency exceeds 50ms
  • Maximum latency exceeds 200ms
  • Packet loss exceeds 20%

Monitor a web server:

/tool/netwatch/add host=www.example.com type=http-get port=80 \
interval=1m timeout=10s \
http-code-min=200 http-code-max=299 \
down-script="/log error \"Web server not responding\""

Monitor HTTPS and validate the certificate:

/tool/netwatch/add host=secure.example.com type=https-get port=443 \
check-certificate=yes \
interval=5m \
down-script="/log error \"HTTPS service or certificate issue\""

Monitor a DNS server’s ability to resolve queries:

/tool/netwatch/add host=example.com type=dns \
dns-server=192.168.1.53 \
record-type=A \
interval=1m \
down-script="/log error \"DNS server not responding\""

Send email when a host goes down:

Step 1: Configure email

/tool/e-mail/set server=smtp.example.com port=587 \
start-tls=yes user=alerts@example.com password=secret

Step 2: Create netwatch with email scripts

/tool/netwatch/add host=192.168.1.100 interval=30s \
down-script={
/tool/e-mail/send to=admin@example.com \
subject="Server DOWN" \
body="Host 192.168.1.100 is unreachable"
} \
up-script={
/tool/e-mail/send to=admin@example.com \
subject="Server UP" \
body="Host 192.168.1.100 recovered"
}

Monitor internet connectivity without relying on a specific endpoint (using low TTL):

/tool/netwatch/add host=1.1.1.1 type=icmp \
ttl=3 \
accept-icmp-time-exceeded=yes \
interval=15s \
comment="Internet path check"

This marks “up” if any router along the path responds, even with “TTL exceeded.”

Prevent scripts from running when the router first boots:

/tool/netwatch/add host=8.8.8.8 interval=30s \
ignore-initial-down=yes \
startup-delay=5m \
down-script="/log warning \"Host down\""
  • ignore-initial-down=yes: Don’t run down-script for Unknown→Down transition
  • startup-delay=5m: Wait 5 minutes after boot before monitoring

Monitor if a specific TCP port is accepting connections:

/tool/netwatch/add host=192.168.1.50 type=tcp-conn port=3306 \
interval=30s \
down-script="/log error \"MySQL server not accepting connections\""

Confirm Netwatch is working correctly:

/tool/netwatch/print

Expected: Entries listed with status (up/down/unknown).

/tool/netwatch/print detail

Shows all properties including scripts and thresholds.

/tool/netwatch/print stats

Shows done-tests, failed-tests, and latency statistics.

/tool/netwatch/print where status=down

Shows only hosts that are currently unreachable.

/log/print where topics~"script"

Look for script execution entries.

SymptomCauseSolution
Scripts not executingScript policy exceeds allowed permissionsSet policy to read,write,test,reboot only
Down-script triggers at bootNetwork not ready during startupIncrease startup-delay or use ignore-initial-down=yes
Monitoring doesn’t detect WAN failureMonitoring target uses the failing linkCreate static route for target via specific gateway
Status flapping rapidlyInterval too short or link unstableIncrease interval and packet-count
Inline script syntax errorsQuote escaping issuesUse named scripts instead of inline
Global variables not accessibleNetwatch runs as *sys userUse environment variables or write to file
DNS probe fails unexpectedlyUses /ip/dns settingsSet explicit dns-server property
HTTP fails on redirectsDefault accepts only 2xx codesSet http-code-max=399 to accept redirects

Create the script separately and test it:

/system/script/add name=test-script source="/log info \"Test\""
/system/script/run test-script

If it works, reference it in netwatch:

/tool/netwatch/set 0 down-script="/system/script/run test-script"

Scripts must have limited permissions:

/system/script/print where name=myscript

Ensure policy shows only: read,write,test,reboot

For WAN failover, ensure monitoring traffic uses the correct path:

# Force monitoring traffic through primary WAN
/ip/route/add dst-address=8.8.8.8/32 gateway=192.168.1.1 comment="monitor-route"

Common Mistakes

  • Monitoring target through the link being monitored - If 8.8.8.8 is reached via primary WAN, and primary WAN fails, the monitor can’t reach 8.8.8.8 to detect the failure. Use a static route or monitor the gateway directly.
  • Script permissions too broad - Netwatch can only run scripts with read,write,test,reboot policies. More permissions = script won’t run.
  • Complex inline scripts - Quote escaping in inline scripts is error-prone. Use named scripts for anything complex.
  • No startup delay - Scripts may trigger during boot before network is ready. Use startup-delay and ignore-initial-down.
  • HTTP checking redirect URLs - Sites that redirect (301/302) fail with default settings. Adjust http-code-max or use final URL.

Netwatch provides variables accessible in scripts:

VariableDescription
$"output"Probe output/response
$"status"Current status (up/down)
$"since"Time of last status change

Example using variables:

down-script="/log warning (\"Host down since: \" . \$since)"
CommandDescription
/tool/netwatch/addCreate monitoring entry
/tool/netwatch/printView all entries with status
/tool/netwatch/print statsView performance statistics
/tool/netwatch/setModify existing entry
/tool/netwatch/removeDelete monitoring entry
PropertyTypeDefaultDescription
hoststring-Target IP, domain, or VRF address (required)
typeenumsimpleProbe type: simple/icmp/tcp-conn/http-get/https-get/dns
intervaltime10sTime between probes
timeouttime3sMaximum wait for response
src-addressIP-Source address for probes
startup-delaytime5mDelay after boot before monitoring
start-delaytime3sDelay before first probe
PropertyTypeDescription
up-scriptstringScript on Down→Up transition
down-scriptstringScript on Up→Down transition
test-scriptstringScript after every probe
ignore-initial-upyes/noSuppress up-script for Unknown→Up
ignore-initial-downyes/noSuppress down-script for Unknown→Down
PropertyTypeDefaultDescription
packet-countinteger10Packets per test
packet-intervaltime50msDelay between packets
packet-sizeinteger54Packet size in bytes
thr-avgtime100msAverage RTT threshold
thr-maxtime1sMaximum RTT threshold
thr-loss-percentpercent85%Packet loss threshold
thr-jittertime1sJitter threshold
PropertyTypeDefaultDescription
portinteger80/443HTTP(S) port
http-code-mininteger100Minimum acceptable status code
http-code-maxinteger299Maximum acceptable status code
check-certificateyes/nonoValidate SSL certificate
thr-http-timetime10sResponse time threshold
FlagMeaning
XDisabled
status=upHost reachable
status=downHost unreachable
status=unknownNot yet tested