Skip to content

Instantly share code, notes, and snippets.

@spali
Last active April 11, 2026 18:03
Show Gist options
  • Select an option

  • Save spali/2da4f23e488219504b2ada12ac59a7dc to your computer and use it in GitHub Desktop.

Select an option

Save spali/2da4f23e488219504b2ada12ac59a7dc to your computer and use it in GitHub Desktop.
Disable WAN Interface on CARP Backup
#!/usr/local/bin/php
<?php
require_once("config.inc");
require_once("interfaces.inc");
require_once("util.inc");
$subsystem = !empty($argv[1]) ? $argv[1] : '';
$type = !empty($argv[2]) ? $argv[2] : '';
if ($type != 'MASTER' && $type != 'BACKUP') {
log_error("Carp '$type' event unknown from source '{$subsystem}'");
exit(1);
}
if (!strstr($subsystem, '@')) {
log_error("Carp '$type' event triggered from wrong source '{$subsystem}'");
exit(1);
}
$ifkey = 'wan';
if ($type === "MASTER") {
log_error("enable interface '$ifkey' due CARP event '$type'");
$config['interfaces'][$ifkey]['enable'] = '1';
write_config("enable interface '$ifkey' due CARP event '$type'", false);
interface_configure(false, $ifkey, false, false);
} else {
log_error("disable interface '$ifkey' due CARP event '$type'");
unset($config['interfaces'][$ifkey]['enable']);
write_config("disable interface '$ifkey' due CARP event '$type'", false);
interface_configure(false, $ifkey, false, false);
}
@oLeDfrEeZe
Copy link
Copy Markdown

For anyone landing here later: I made a working fork for my setup, tested on OPNsense 26.1.6.

Warning: it is vibe-coded / AI-assisted, so please review it carefully before using it in production.

You must adapt the CARP trigger subsystem, interface key, and gateway name placeholders to your own setup.

In my environment, it correctly keeps the DHCP WAN inactive on BACKUP and active on MASTER.

Fork: Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment