Basic IPVS Commands for Linux Networking
IPVS (IP Virtual Server) is a powerful load balancing solution integrated into the Linux kernel. It is often used in Kubernetes environments as an alternative to iptables
for service routing when kube-proxy is in IPVS mode.
This guide covers the most useful IPVS commands using ipvsadm
.
What is IPVS?
IPVS operates at the transport layer and allows you to load balance TCP and UDP traffic using multiple algorithms like round-robin, least connections, and more.
Install ipvsadm
# Ubuntu/Debian
sudo apt install ipvsadm
# CentOS/RHEL
sudo yum install ipvsadm
Common IPVS Commands
View Current IPVS Rules
sudo ipvsadm -L -n
Add a Virtual Service
sudo ipvsadm -A -t 192.168.0.100:80 -s rr
This adds a virtual service that listens on IP 192.168.0.100
and port 80
, using round-robin (rr
) scheduling.
Add Real Servers
sudo ipvsadm -a -t 192.168.0.100:80 -r 192.168.0.101:80 -g
sudo ipvsadm -a -t 192.168.0.100:80 -r 192.168.0.102:80 -g
Remove Real Server
sudo ipvsadm -d -t 192.168.0.100:80 -r 192.168.0.102:80
Delete Virtual Service
sudo ipvsadm -D -t 192.168.0.100:80
Useful Tips
-s rr
— Round-robin scheduling-g
— Direct routing (default)- Use
ipvsadm-save
andipvsadm-restore
to persist rules across reboots.
Conclusion
IPVS is a robust and efficient load balancing tool for Linux and Kubernetes. Mastering ipvsadm
helps DevOps engineers manage traffic efficiently in scalable environments.