Created
July 30, 2018 12:42
-
-
Save penglei/3216805a5df1b2f2374c3a17d1459aa0 to your computer and use it in GitHub Desktop.
vip-by-iptables-demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
iptables -t nat -N VIP-SERVICES | |
iptables -t nat -N VIP-DISTRIBUTION-NGINX | |
iptables -t nat -N VIP-DISTRIBUTION-NGINX-1 | |
iptables -t nat -N VIP-DISTRIBUTION-NGINX-2 | |
iptables -t nat -N VIP-POSTROUTING | |
iptables -t nat -I PREROUTING -j VIP-SERVICES | |
iptables -t nat -I OUTPUT -j VIP-SERVICES | |
iptables -t nat -A VIP-SERVICES -p tcp -m tcp --dport 443 -j VIP-DISTRIBUTION-NGINX | |
iptables -t nat -A VIP-DISTRIBUTION-NGINX -m statistic --mode random --probability 0.50000000000 -j VIP-DISTRIBUTION-NGINX-1 | |
iptables -t nat -A VIP-DISTRIBUTION-NGINX -j VIP-DISTRIBUTION-NGINX-2 | |
iptables -t nat -A VIP-DISTRIBUTION-NGINX-1 -p tcp -m tcp -j DNAT --to-destination "100.125.120.34:443" | |
iptables -t nat -A VIP-DISTRIBUTION-NGINX-2 -p tcp -m tcp -j DNAT --to-destination "100.125.120.35:443" | |
iptables -t nat -A POSTROUTING -o eth0 -j VIP-POSTROUTING | |
iptables -t nat -A VIP-POSTROUTING -d "100.125.120.0/24" -p tcp -m tcp -j MASQUERADE | |
output_iface=eth0 | |
echo 1 > /proc/sys/net/ipv4/conf/$output_iface/route_localnet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
访问本机
443
端口全部转发到100.125.120.34
、100.125.120.35