To check which **Keepalived route is master** and how to **switch the master role**, follow these steps:
 
---
 
## **1. Check the Current Master**
Keepalived uses **VRRP (Virtual Router Redundancy Protocol)** to manage failover. To check the current master:
 
### **Check VRRP State**
```sh
sudo ip route | grep vrrp
```
or
```sh
sudo ip addr show vrrp+
```
 
### **Check Keepalived Logs**
```sh
sudo tail -f /var/log/syslog | grep keepalived
```
or
```sh
sudo journalctl -u keepalived -f
```
 
### **Check VRRP Instance Status**
```sh
sudo systemctl status keepalived
```
or
```sh
sudo keepalived -v
```
 
---
 
## **2. Manually Switch the Master**
If you need to **force a failover** (e.g., for maintenance), you can manually switch the master.
 
### **Method 1: Restart Keepalived on the Current Master**
```sh
sudo systemctl restart keepalived
```
- This will trigger a failover to the **backup node**.
 
### **Method 2: Change Priority in Keepalived Config**
Edit the Keepalived config (`/etc/keepalived/keepalived.conf`) and adjust the `priority` value:
```conf
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100  # Higher priority = master
    ...
}
```
- Decrease the priority on the current master to force a failover.
- Restart Keepalived:
  ```sh
  sudo systemctl restart keepalived
  ```
 
### **Method 3: Use `kill` to Force Failover**
```sh
sudo kill -9 $(pidof keepalived)
```
- This will force Keepalived to restart and re-evaluate the master role.
 
---
 
## **3. Verify the New Master**
After switching, check the new master:
```sh
sudo ip route | grep vrrp
```
or
```sh
sudo keepalived -v
```
 
---
 
## **Conclusion**
- Use `ip route` or `keepalived -v` to check the current master.
- Restart Keepalived, adjust priority, or kill the process to force a failover.
- Verify the new master after switching.