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