1vip = "10.10.0.1" 2ss = [ 3 "172.18.1.3", 4 "172.18.1.4", 5 "172.18.1.5", 6] 7 8print "*nat" 9print ":myservice - [0:0]" 10 11# iptables -t nat -A myservice -d 10.10.0.1 -m statistic --mode random --probability 0.3333 -j DNAT --to-destination 172.18.1.3 12x, n = 0, 10000 13m = n 14for _ in range(n-1): 15 p = 1.0/m 16 print "-A myservice -d %s -m statistic --mode random --probability %.16f -j DNAT --to-destination %s" % (vip, p, ss[x]) 17 m-=1 18 x+=1 19 x%=len(ss) 20print "-A myservice -d %s -j DNAT --to-destination %s" % (vip, ss[x]) 21 22print "COMMIT" 23