1IPVSADM(8) Linux Administrator's Guide IPVSADM(8)
2
3
4
6 ipvsadm - Linux Virtual Server administration
7
9 ipvsadm -A|E -t|u|f service-address [-s scheduler]
10 [-p [timeout]] [-M netmask]
11 ipvsadm -D -t|u|f service-address
12 ipvsadm -C
13 ipvsadm -R
14 ipvsadm -S [-n]
15 ipvsadm -a|e -t|u|f service-address -r server-address
16 [-g|i|m] [-w weight] [-x upper] [-y lower]
17 ipvsadm -d -t|u|f service-address -r server-address
18 ipvsadm -L|l [options]
19 ipvsadm -Z [-t|u|f service-address]
20 ipvsadm --set tcp tcpfin udp
21 ipvsadm --start-daemon state [--mcast-interface interface]
22 [--syncid syncid]
23 ipvsadm --stop-daemon state
24 ipvsadm -h
25
27 Ipvsadm(8) is used to set up, maintain or inspect the virtual server
28 table in the Linux kernel. The Linux Virtual Server can be used to
29 build scalable network services based on a cluster of two or more
30 nodes. The active node of the cluster redirects service requests to a
31 collection of server hosts that will actually perform the services.
32 Supported features include two protocols (TCP and UDP), three packet-
33 forwarding methods (NAT, tunneling, and direct routing), and eight load
34 balancing algorithms (round robin, weighted round robin, least-connec‐
35 tion, weighted least-connection, locality-based least-connection,
36 locality-based least-connection with replication, destination-hashing,
37 and source-hashing).
38
39 The command has two basic formats for execution:
40
41 ipvsadm COMMAND [protocol] service-address
42 [scheduling-method] [persistence options]
43
44 ipvsadm command [protocol] service-address
45 server-address [packet-forwarding-method]
46 [weight options]
47
48 The first format manipulates a virtual service and the algorithm for
49 assigning service requests to real servers. Optionally, a persistent
50 timeout and network mask for the granularity of a persistent service
51 may be specified. The second format manipulates a real server that is
52 associated with an existing virtual service. When specifying a real
53 server, the packet-forwarding method and the weight of the real server,
54 relative to other real servers for the virtual service, may be speci‐
55 fied, otherwise defaults will be used.
56
57 COMMANDS
58 ipvsadm(8) recognises the commands described below. Upper-case commands
59 maintain virtual services. Lower-case commands maintain real servers
60 that are associated with a virtual service.
61
62 -A, --add-service
63 Add a virtual service. A service address is uniquely defined by
64 a triplet: IP address, port number, and protocol. Alternatively,
65 a virtual service may be defined by a firewall-mark.
66
67 -E, --edit-service
68 Edit a virtual service.
69
70 -D, --delete-service
71 Delete a virtual service, along with any associated real
72 servers.
73
74 -C, --clear
75 Clear the virtual server table.
76
77 -R, --restore
78 Restore Linux Virtual Server rules from stdin. Each line read
79 from stdin will be treated as the command line options to a sep‐
80 arate invocation of ipvsadm. Lines read from stdin can option‐
81 ally begin with "ipvsadm". This option is useful to avoid exe‐
82 cuting a large number or ipvsadm commands when constructing an
83 extensive routing table.
84
85 -S, --save
86 Dump the Linux Virtual Server rules to stdout in a format that
87 can be read by -R|--restore.
88
89 -a, --add-server
90 Add a real server to a virtual service.
91
92 -e, --edit-server
93 Edit a real server in a virtual service.
94
95 -d, --delete-server
96 Remove a real server from a virtual service.
97
98 -L, -l, --list
99 List the virtual server table if no argument is specified. If a
100 service-address is selected, list this service only. If the -c
101 option is selected, then display the connection table. The exact
102 output is affected by the other arguments given.
103
104 -Z, --zero
105 Zero the packet, byte and rate counters in a service or all ser‐
106 vices.
107
108 --set tcp tcpfin udp
109 Change the timeout values used for IPVS connections. This com‐
110 mand always takes 3 parameters, representing the timeout
111 values (in seconds) for TCP sessions, TCP sessions after receiv‐
112 ing a FIN packet, and UDP packets, respectively. A timeout
113 value 0 means that the current timeout value of the correspond‐
114 ing entry is preserved.
115
116 --start-daemon state
117 Start the connection synchronization daemon. The state is to
118 indicate that the daemon is started as master or backup. The
119 connection synchronization daemon is implemented inside the
120 Linux kernel. The master daemon running at the primary load bal‐
121 ancer multicasts changes of connections periodically, and the
122 backup daemon running at the backup load balancers receives mul‐
123 ticast message and creates corresponding connections. Then, in
124 case the primary load balancer fails, a backup load balancer
125 will takeover, and it has state of almost all connections, so
126 that almost all established connections can continue to access
127 the service.
128
129 The sync daemon currently only supports IPv4 connections.
130
131 --stop-daemon
132 Stop the connection synchronization daemon.
133
134 -h, --help
135 Display a description of the command syntax.
136
137 PARAMETERS
138 The commands above accept or require zero or more of the following
139 parameters.
140
141 -t, --tcp-service service-address
142 Use TCP service. The service-address is of the form host[:port].
143 Host may be one of a plain IP address or a hostname. Port may be
144 either a plain port number or the service name of port. The Port
145 may be omitted, in which case zero will be used. A Port of zero
146 is only valid if the service is persistent as the -p|--persis‐
147 tent option, in which case it is a wild-card port, that is con‐
148 nections will be accepted to any port.
149
150 -u, --udp-service service-address
151 Use UDP service. See the -t|--tcp-service for the description of
152 the service-address.
153
154 -f, --fwmark-service integer
155 Use a firewall-mark, an integer value greater than zero, to
156 denote a virtual service instead of an address, port and proto‐
157 col (UDP or TCP). The marking of packets with a firewall-mark is
158 configured using the -m|--mark option to iptables(8). It can be
159 used to build a virtual service assoicated with the same real
160 servers, covering multiple IP address, port and protocol trip‐
161 plets. If IPv6 addresses are used, the -6 option must be used.
162
163 Using firewall-mark virtual services provides a convenient
164 method of grouping together different IP addresses, ports and
165 protocols into a single virtual service. This is useful for both
166 simplifying configuration if a large number of virtual services
167 are required and grouping persistence across what would other‐
168 wise be multiple virtual services.
169
170 -s, --scheduler scheduling-method
171 scheduling-method Algorithm for allocating TCP connections and
172 UDP datagrams to real servers. Scheduling algorithms are imple‐
173 mented as kernel modules. Ten are shipped with the Linux Virtual
174 Server:
175
176 rr - Robin Robin: distributes jobs equally amongst the available
177 real servers.
178
179 wrr - Weighted Round Robin: assigns jobs to real servers propor‐
180 tionally to there real servers' weight. Servers with higher
181 weights receive new jobs first and get more jobs than servers
182 with lower weights. Servers with equal weights get an equal dis‐
183 tribution of new jobs.
184
185 lc - Least-Connection: assigns more jobs to real servers with
186 fewer active jobs.
187
188 wlc - Weighted Least-Connection: assigns more jobs to servers
189 with fewer jobs and relative to the real servers' weight
190 (Ci/Wi). This is the default.
191
192 lblc - Locality-Based Least-Connection: assigns jobs destined
193 for the same IP address to the same server if the server is not
194 overloaded and available; otherwise assign jobs to servers with
195 fewer jobs, and keep it for future assignment.
196
197 lblcr - Locality-Based Least-Connection with Replication:
198 assigns jobs destined for the same IP address to the least-con‐
199 nection node in the server set for the IP address. If all the
200 node in the server set are over loaded, it picks up a node with
201 fewer jobs in the cluster and adds it in the sever set for the
202 target. If the server set has not been modified for the speci‐
203 fied time, the most loaded node is removed from the server set,
204 in order to avoid high degree of replication.
205
206 dh - Destination Hashing: assigns jobs to servers through look‐
207 ing up a statically assigned hash table by their destination IP
208 addresses.
209
210 sh - Source Hashing: assigns jobs to servers through looking up
211 a statically assigned hash table by their source IP addresses.
212
213 sed - Shortest Expected Delay: assigns an incoming job to the
214 server with the shortest expected delay. The expected delay that
215 the job will experience is (Ci + 1) / Ui if sent to the ith
216 server, in which Ci is the number of jobs on the the ith server
217 and Ui is the fixed service rate (weight) of the ith server.
218
219 nq - Never Queue: assigns an incoming job to an idle server if
220 there is, instead of waiting for a fast one; if all the servers
221 are busy, it adopts the Shortest Expected Delay policy to assign
222 the job.
223
224 -p, --persistent [timeout]
225 Specify that a virtual service is persistent. If this option is
226 specified, multiple requests from a client are redirected to the
227 same real server selected for the first request. Optionally,
228 the timeout of persistent sessions may be specified given in
229 seconds, otherwise the default of 300 seconds will be used. This
230 option may be used in conjunction with protocols such as SSL or
231 FTP where it is important that clients consistently connect with
232 the same real server.
233
234 Note: If a virtual service is to handle FTP connections then
235 persistence must be set for the virtual service if Direct Rout‐
236 ing or Tunnelling is used as the forwarding mechanism. If Mas‐
237 querading is used in conjunction with an FTP service than per‐
238 sistence is not necessary, but the ip_vs_ftp kernel module must
239 be used. This module may be manually inserted into the kernel
240 using insmod(8).
241
242 -M, --netmask netmask
243 Specify the granularity with which clients are grouped for per‐
244 sistent virtual services. The source address of the request is
245 masked with this netmask to direct all clients from a network to
246 the same real server. The default is 255.255.255.255, that is,
247 the persistence granularity is per client host. Less specific
248 netmasks may be used to resolve problems with non-persistent
249 cache clusters on the client side. IPv6 netmasks should be
250 specified as a prefix length between 1 and 128. The default
251 prefix length is 128.
252
253 -r, --real-server server-address
254 Real server that an associated request for service may be
255 assigned to. The server-address is the host address of a real
256 server, and may plus port. Host can be either a plain IP address
257 or a hostname. Port can be either a plain port number or the
258 service name of port. In the case of the masquerading method,
259 the host address is usually an RFC 1918 private IP address, and
260 the port can be different from that of the associated service.
261 With the tunneling and direct routing methods, port must be
262 equal to that of the service address. For normal services, the
263 port specified in the service address will be used if port is
264 not specified. For fwmark services, port may be omitted, in
265 which case the destination port on the real server will be the
266 destination port of the request sent to the virtual service.
267
268 [packet-forwarding-method]
269
270 -g, --gatewaying Use gatewaying (direct routing). This is the
271 default.
272
273 -i, --ipip Use ipip encapsulation (tunneling).
274
275 -m, --masquerading Use masquerading (network access transla‐
276 tion, or NAT).
277
278 Note: Regardless of the packet-forwarding mechanism specified,
279 real servers for addresses for which there are interfaces on the
280 local node will be use the local forwarding method, then packets
281 for the servers will be passed to upper layer on the local node.
282 This cannot be specified by ipvsadm, rather it set by the kernel
283 as real servers are added or modified.
284
285 -w, --weight weight
286 Weight is an integer specifying the capacity of a server rela‐
287 tive to the others in the pool. The valid values of weight are 0
288 through to 65535. The default is 1. Quiescent servers are speci‐
289 fied with a weight of zero. A quiescent server will receive no
290 new jobs but still serve the existing jobs, for all scheduling
291 algorithms distributed with the Linux Virtual Server. Setting a
292 quiescent server may be useful if the server is overloaded or
293 needs to be taken out of service for maintenance.
294
295 -x, --u-threshold uthreshold
296 uthreshold is an integer specifying the upper connection thresh‐
297 old of a server. The valid values of uthreshold are 0 through to
298 65535. The default is 0, which means the upper connection
299 threshold is not set. If uthreshold is set with other values, no
300 new connections will be sent to the server when the number of
301 its connections exceeds its upper connection threshold.
302
303 -y, --l-threshold lthreshold
304 lthreshold is an integer specifying the lower connection thresh‐
305 old of a server. The valid values of lthreshold are 0 through to
306 65535. The default is 0, which means the lower connection
307 threshold is not set. If lthreshold is set with other values,
308 the server will receive new connections when the number of its
309 connections drops below its lower connection threshold. If
310 lthreshold is not set but uthreshold is set, the server will
311 receive new connections when the number of its connections drops
312 below three forth of its upper connection threshold.
313
314 --mcast-interface interface
315 Specify the multicast interface that the sync master daemon
316 sends outgoing multicasts through, or the sync backup daemon
317 listens to for multicasts.
318
319 --syncid syncid
320 Specify the syncid that the sync master daemon fills in the Syn‐
321 cID header while sending multicast messages, or the sync backup
322 daemon uses to filter out multicast messages not matched with
323 the SyncID value. The valid values of syncid are 0 through to
324 255. The default is 0, which means no filtering at all.
325
326 -c, --connection
327 Connection output. The list command with this option will list
328 current IPVS connections.
329
330 --timeout
331 Timeout output. The list command with this option will display
332 the timeout values (in seconds) for TCP sessions, TCP sessions
333 after receiving a FIN packet, and UDP packets.
334
335 --daemon
336 Daemon information output. The list command with this option
337 will display the daemon status and its multicast interface.
338
339 --stats
340 Output of statistics information. The list command with this
341 option will display the statistics information of services and
342 their servers.
343
344 --rate Output of rate information. The list command with this option
345 will display the rate information (such as connections/second,
346 bytes/second and packets/second) of services and their servers.
347
348 --thresholds
349 Output of thresholds information. The list command with this
350 option will display the upper/lower connection threshold infor‐
351 mation of each server in service listing.
352
353 --persistent-conn
354 Output of persistent connection information. The list command
355 with this option will display the persistent connection counter
356 information of each server in service listing. The persistent
357 connection is used to forward the actual connections from the
358 same client/network to the same server.
359
360 --sort Sort the list of virtual services and real servers. The virtual
361 service entries are sorted in ascending order by <protocol,
362 address, port>. The real server entries are sorted in ascending
363 order by <address, port>. (default)
364
365 --nosort
366 Do not sort the list of virtual services and real servers.
367
368 -n, --numeric
369 Numeric output. IP addresses and port numbers will be printed
370 in numeric format rather than as as host names and services
371 respectively, which is the default.
372
373 --exact
374 Expand numbers. Display the exact value of the packet and byte
375 counters, instead of only the rounded number in K's (multiples
376 of 1000) M's (multiples of 1000K) or G's (multiples of 1000M).
377 This option is only relevant for the -L command.
378
379 -6 Use with -f to signify fwmark rule uses IPv6 addresses.
380
382 The following commands configure a Linux Director to distribute incom‐
383 ing requests addressed to port 80 on 207.175.44.110 equally to port 80
384 on five real servers. The forwarding method used in this example is
385 NAT, with each of the real servers being masqueraded by the Linux
386 Director.
387
388 ipvsadm -A -t 207.175.44.110:80 -s rr
389 ipvsadm -a -t 207.175.44.110:80 -r 192.168.10.1:80 -m
390 ipvsadm -a -t 207.175.44.110:80 -r 192.168.10.2:80 -m
391 ipvsadm -a -t 207.175.44.110:80 -r 192.168.10.3:80 -m
392 ipvsadm -a -t 207.175.44.110:80 -r 192.168.10.4:80 -m
393 ipvsadm -a -t 207.175.44.110:80 -r 192.168.10.5:80 -m
394
395 Alternatively, this could be achieved in a single ipvsadm command.
396
397 echo "
398 -A -t 207.175.44.110:80 -s rr
399 -a -t 207.175.44.110:80 -r 192.168.10.1:80 -m
400 -a -t 207.175.44.110:80 -r 192.168.10.2:80 -m
401 -a -t 207.175.44.110:80 -r 192.168.10.3:80 -m
402 -a -t 207.175.44.110:80 -r 192.168.10.4:80 -m
403 -a -t 207.175.44.110:80 -r 192.168.10.5:80 -m
404 " | ipvsadm -R
405
406 As masquerading is used as the forwarding mechanism in this example,
407 the default route of the real servers must be set to the linux direc‐
408 tor, which will need to be configured to forward and masquerade pack‐
409 ets. This can be achieved using the following commands:
410
411 echo "1" > /proc/sys/net/ipv4/ip_forward
412
414 The following commands configure a Linux Director to distribute incom‐
415 ing requests addressed to any port on 207.175.44.110 or 207.175.44.111
416 equally to the corresponding port on five real servers. As per the pre‐
417 vious example, the forwarding method used in this example is NAT, with
418 each of the real servers being masqueraded by the Linux Director.
419
420 ipvsadm -A -f 1 -s rr
421 ipvsadm -a -f 1 -r 192.168.10.1:0 -m
422 ipvsadm -a -f 1 -r 192.168.10.2:0 -m
423 ipvsadm -a -f 1 -r 192.168.10.3:0 -m
424 ipvsadm -a -f 1 -r 192.168.10.4:0 -m
425 ipvsadm -a -f 1 -r 192.168.10.5:0 -m
426
427 As masquerading is used as the forwarding mechanism in this example,
428 the default route of the real servers must be set to the linux direc‐
429 tor, which will need to be configured to forward and masquerade pack‐
430 ets. The real server should also be configured to mark incoming packets
431 addressed to any port on 207.175.44.110 and 207.175.44.111 with fire‐
432 wall-mark 1. If FTP traffic is to be handled by this virtual service,
433 then the ip_vs_ftp kernel module needs to be inserted into the kernel.
434 These operations can be achieved using the following commands:
435
436 echo "1" > /proc/sys/net/ipv4/ip_forward
437 modprobe ip_tables
438 iptables -A PREROUTING -t mangle -d 207.175.44.110/31 -j MARK --set-mark 1
439 modprobe ip_vs_ftp
440
442 IPv6 addresses should be surrounded by square brackets ([ and ]).
443
444 ipvsadm -A -t [2001:db8::80]:80 -s rr
445 ipvsadm -a -t [2001:db8::80]:80 -r [2001:db8::a0a0]:80 -m
446
447 fwmark IPv6 services require the -6 option.
448
450 The Linux Virtual Server implements three defense strategies against
451 some types of denial of service (DoS) attacks. The Linux Director cre‐
452 ates an entry for each connection in order to keep its state, and each
453 entry occupies 128 bytes effective memory. LVS's vulnerability to a DoS
454 attack lies in the potential to increase the number entries as much as
455 possible until the linux director runs out of memory. The three defense
456 strategies against the attack are: Randomly drop some entries in the
457 table. Drop 1/rate packets before forwarding them. And use secure tcp
458 state transition table and short timeouts. The strategies are con‐
459 trolled by sysctl variables and corresponding entries in the /proc
460 filesystem:
461
462 /proc/sys/net/ipv4/vs/drop_entry /proc/sys/net/ipv4/vs/drop_packet
463 /proc/sys/net/ipv4/vs/secure_tcp
464
465 Valid values for each variable are 0 through to 3. The default value is
466 0, which disables the respective defense strategy. 1 and 2 are auto‐
467 matic modes - when there is no enough available memory, the respective
468 strategy will be enabled and the variable is automatically set to 2,
469 otherwise the strategy is disabled and the variable is set to 1. A
470 value of 3 denotes that the respective strategy is always enabled. The
471 available memory threshold and secure TCP timeouts can be tuned using
472 the sysctl variables and corresponding entries in the /proc filesystem:
473
474 /proc/sys/net/ipv4/vs/amemthresh /proc/sys/net/ipv4/vs/timeout_*
475
477 /proc/net/ip_vs
478 /proc/net/ip_vs_app
479 /proc/net/ip_vs_conn
480 /proc/net/ip_vs_stats
481 /proc/sys/net/ipv4/vs/am_droprate
482 /proc/sys/net/ipv4/vs/amemthresh
483 /proc/sys/net/ipv4/vs/drop_entry
484 /proc/sys/net/ipv4/vs/drop_packet
485 /proc/sys/net/ipv4/vs/secure_tcp
486 /proc/sys/net/ipv4/vs/timeout_close
487 /proc/sys/net/ipv4/vs/timeout_closewait
488 /proc/sys/net/ipv4/vs/timeout_established
489 /proc/sys/net/ipv4/vs/timeout_finwait
490 /proc/sys/net/ipv4/vs/timeout_icmp
491 /proc/sys/net/ipv4/vs/timeout_lastack
492 /proc/sys/net/ipv4/vs/timeout_listen
493 /proc/sys/net/ipv4/vs/timeout_synack
494 /proc/sys/net/ipv4/vs/timeout_synrecv
495 /proc/sys/net/ipv4/vs/timeout_synsent
496 /proc/sys/net/ipv4/vs/timeout_timewait
497 /proc/sys/net/ipv4/vs/timeout_udp
498
500 The LVS web site (http://www.linuxvirtualserver.org/) for more documen‐
501 tation about LVS.
502
503 ipvsadm-save(8), ipvsadm-restore(8), iptables(8),
504 insmod(8), modprobe(8)
505
507 ipvsadm - Wensong Zhang <wensong@linuxvirtualserver.org>
508 Peter Kese <peter.kese@ijs.si>
509 man page - Mike Wangsmo <wanger@redhat.com>
510 Wensong Zhang <wensong@linuxvirtualserver.org>
511 Horms <horms@verge.net.au>
512
513
514
5154th Berkeley Distribution 5th July 2003 IPVSADM(8)