Auto-update blog content from Obsidian: 2025-10-22 19:33:43
All checks were successful
Blog Deployment / Merge (push) Successful in 7s
Blog Deployment / Deploy-Production (push) Successful in 9s
Blog Deployment / Test-Production (push) Successful in 2s
Blog Deployment / Clean (push) Has been skipped
Blog Deployment / Notify (push) Successful in 3s
Blog Deployment / Check-Rebuild (push) Successful in 5s
Blog Deployment / Build (push) Has been skipped
Blog Deployment / Deploy-Staging (push) Successful in 9s
Blog Deployment / Test-Staging (push) Successful in 2s
All checks were successful
Blog Deployment / Merge (push) Successful in 7s
Blog Deployment / Deploy-Production (push) Successful in 9s
Blog Deployment / Test-Production (push) Successful in 2s
Blog Deployment / Clean (push) Has been skipped
Blog Deployment / Notify (push) Successful in 3s
Blog Deployment / Check-Rebuild (push) Successful in 5s
Blog Deployment / Build (push) Has been skipped
Blog Deployment / Deploy-Staging (push) Successful in 9s
Blog Deployment / Test-Staging (push) Successful in 2s
This commit is contained in:
@@ -190,6 +190,60 @@ Now that HA is configured, I can give my networks a virtual IP shared across my
|
||||
|
||||
ℹ️ OPNsense allows by default CARP protocol, there is no need to create specific rules for it.
|
||||
|
||||
---
|
||||
## CARP Failover Script
|
||||
|
||||
In my setup, I only have a single WAN IP address which is served by the DHCP of my ISP box. OPNsense does not provide natively a way to handle this scenario. To manage it, I implement the same trick I used in the [PoC]({{< ref "post/12-opnsense-virtualization-highly-available" >}}).
|
||||
### Copy MAC Address
|
||||
|
||||
I copy the MAC of the `net1` interface of `cerbere-head1` and paste it to the same interface for `cerbere-head2`. Doing so, the DHCP lease for the WAN IP address can be shared among the nodes.
|
||||
|
||||
⚠️ Warning: Having two machines on the network with the same MAC can cause ARP conflicts and break connectivity. Only one VM should keep its interface active.
|
||||
|
||||
### CARP Event Script
|
||||
|
||||
Under the hood, in OPNsense, a CARP event triggers some scripts (when the master dies). These are located in `/usr/local/etc/rc.syshook.d/carp/`.
|
||||
|
||||
To manage WAN interface on each node, I implement this PHP script `10-wan` on both nodes, using SSH (do not forget to make it executable). Depending on their role (master or backup), this will enable or disable their WAN interface:
|
||||
```php
|
||||
#!/usr/local/bin/php
|
||||
<?php
|
||||
|
||||
require_once("config.inc");
|
||||
require_once("interfaces.inc");
|
||||
require_once("util.inc");
|
||||
require_once("system.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);
|
||||
}
|
||||
```
|
||||
|
||||
In the Virtua
|
||||
|
||||
---
|
||||
## Firewall
|
||||
|
||||
|
||||
Reference in New Issue
Block a user