- Introduction
- Prerequisites
- How to Run
- Run as a Service (systemd)
- Run as a Service (rc.local)
- Removing the Service
- Flowchart
This script is designed to create a virtual bridge that combines a specified main connection with other active network interfaces. It continuously monitors the network interfaces, dynamically adjusting the virtual bridge for network redundancy. This is particularly useful in scenarios where multiple network connections are available, providing a seamless and automatic failover mechanism.
Ensure your system meets the following requirements:
- Linux operating system.
- The
ip
,brctl
, andawk
commands are available. sudo
privileges are required to execute the script.
-
Clone or Download the Script:
git clone https://github.com/1999AZZAR/network-redundancy.git
Replace the URL with the actual path if you are downloading manually.
-
Make the Script Executable:
chmod +x /path/to/network_redundancy.sh
-
Run the Script with sudo:
sudo /path/to/network_redundancy.sh
This will execute the script with elevated privileges necessary for managing network interfaces.
-
Create a systemd Service File: Create a new service file for systemd. Open an editor and create
/etc/systemd/system/network_redundancy.service
with the following content:[Unit] Description=Network Redundancy Script [Service] ExecStart=/path/to/network_redundancy.sh Restart=always User=root Group=root [Install] WantedBy=multi-user.target
Replace
/path/to/network_redundancy.sh
with the actual path to your script. -
Reload systemd:
sudo systemctl daemon-reload
-
Enable the Service to Start on Boot:
sudo systemctl enable network_redundancy.service
-
Start the Service:
sudo systemctl start network_redundancy.service
The script will now run as a service and automatically start on system boot.
-
Edit the rc.local File: Edit the
rc.local
file using your preferred text editor:sudo nano /etc/rc.local
-
Add the Command to Run the Script: Add the following line before
exit 0
:/path/to/network_redundancy.sh &
Replace
/path/to/network_redundancy.sh
with the actual path to your script. -
Make rc.local Executable:
sudo chmod +x /etc/rc.local
-
Reboot Your System:
sudo reboot
The script will run automatically on system boot using
rc.local
.
-
If Using systemd:
sudo systemctl disable network_redundancy.service sudo systemctl stop network_redundancy.service
-
If Using rc.local: Remove the line added to
rc.local
. -
Delete the systemd Service File (if created):
sudo rm /etc/systemd/system/network_redundancy.service
-
Reboot Your System:
sudo reboot
-
Remove the Script (if no longer needed):
rm /path/to/network_redundancy.sh
The script and associated configurations will be removed from your system.
graph TB
subgraph Initialization
A[Define Variables]
B[Define Functions]
C[Trap Exit Signal]
end
subgraph Cleanup
D[Cleanup]
end
subgraph Main Loop
E[Get Active Interfaces]
F[Check Changes in Interfaces]
G[Update Virtual Bridge]
H[Set Virtual Bridge as Main Connection]
end
A --> B --> C --> D --> E --> F --> G --> H --> E