-
Install
ipvsadm
andnetfilter-persistent
packagesapt install ipvsadm netfilter-persistent # make sure netfilter-persistent is enabled systemctl is-enabled netfilter-persistent
-
Setup
ipvs
pluginmkdir -p /etc/ipvs/ curl -L https://github.com/dungdm93/ipvs-persistent/raw/master/plugins.d/32-ipvsadm \ -o /usr/share/netfilter-persistent/plugins.d/32-ipvsadm chmod +x /usr/share/netfilter-persistent/plugins.d/32-ipvsadm
-
Save current IPVS rules
ipvsadm --save --numeric > /etc/ipvs/rules
/etc/ipvs/rules
will look like:-A -t 123.45.67.89:80 -s rr -a -t 123.45.67.89:80 -r 192.168.10.1:80 -m -a -t 123.45.67.89:80 -r 192.168.10.2:80 -m -a -t 123.45.67.89:80 -r 192.168.10.3:80 -m -a -t 123.45.67.89:80 -r 192.168.10.4:80 -m -a -t 123.45.67.89:80 -r 192.168.10.5:80 -m
as you can see, each line actually a
ipvsadm
command without the entrypoint. -
Your IPVS rules are now persisted, and automatically load on boot.
If you'd like to manual load/reset IPVS rules, run this command:service netfilter-persistent reload # --or-- systemctl restart netfilter-persistent # --or-- ipvsadm --restore < /etc/ipvs/rules
-
BONUS: some others helpful commands
# List the virtual server table ipvsadm -l -n # Clear the virtual server table. ipvsadm --clear