Skip to content

Instantly share code, notes, and snippets.

@spali
Last active February 17, 2026 14:19
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);
}
Copy link

ghost commented Sep 25, 2025

The script doesn't break, it gets reset to default if you update to the next version. I haven't checked what Claude made differentl, however the latest versions posted above still work well.

@USBAkimbo
Copy link

@coderph0x sorry I mean I had a different, older script - not one from this thread

@kronenpj
Copy link

kronenpj commented Sep 26, 2025

I used my script at https://gist.github.com/kronenpj/e90258f12f7a40c4f38a23b609b3288b many times last week while diagnosing a problem. It works very well for me on Opnsense 25.7.

@kayti
Copy link

kayti commented Feb 17, 2026

I have some problems with using this script. 2 things I can think about:

  1. I specify $ifkey wrongly (I take the interface name visible in opnsense, lagg0_vlan2 in my case)
  2. 26.1 changed something, and the methods for enabling/disabling the interface changed.

I see error log for triggering action, but interface is still UP.

Can anyone help me?

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