亚欧色一区w666天堂,色情一区二区三区免费看,少妇特黄A片一区二区三区,亚洲人成网站999久久久综合,国产av熟女一区二区三区

  • 發布文章
  • 消息中心
點贊
收藏
評論
分享
原創

iptables -m statistic --mode nth 實現流量分擔

2023-10-07 09:35:59
92
0

有這么一種情況了,使用linux作為一個(ge)網關,假如(ru)有多個(ge)彈性(xing)ip,那么如(ru)何(he)使得經過(guo)網關的流(liu)量從幾(ji)個(ge)彈性(xing)ip分流(liu)出(chu)去呢(ni)

有一種辦法就是解(jie)決使(shi)用(yong)Linux系統自帶的(de)的(de)iptables的(de)statistic match,而(er)不用(yong)引入其他組件


假設有2個彈性ip
必須嚴格按照順序來(否則達不到要的效果)  --every 2 --packet 0 在前,--every 1 --packet 0在后面
添加規則
sudo iptables -t nat -A PREROUTING -m state --state NEW -m statistic --mode nth --every 2 --packet 0 -j SNAT --to-destination 10.50.208.92
sudo iptables -t nat -A PREROUTING -m state --state NEW -m statistic --mode nth --every 1 --packet 0 -j SNAT --to-destination 10.50.208.93


刪除規則
sudo iptables -t nat -D PREROUTING -m state --state NEW -m statistic --mode nth --every 2 --packet 0 -j SNAT --to-destination 10.50.208.92
sudo iptables -t nat -D PREROUTING -m state --state NEW -m statistic --mode nth --every 1 --packet 0 -j SNAT --to-destination 10.50.208.93

 


假設有3個彈性ip
注意規則的順序,由先到后的順序是
--mode nth --every 3 --packet 0
--mode nth --every 2 --packet 0
--mode nth --every 1 --packet 0

sudo iptables -t nat -A PREROUTING -m state --state NEW -m statistic --mode nth --every 3 --packet 0 -j SNAT --to-destination 10.50.208.92
sudo iptables -t nat -A PREROUTING -m state --state NEW -m statistic --mode nth --every 2 --packet 0 -j SNAT --to-destination 10.50.208.93
sudo iptables -t nat -A PREROUTING -m state --state NEW -m statistic --mode nth --every 1 --packet 0 -j SNAT --to-destination 10.50.208.94

刪除規則
sudo iptables -t nat -D PREROUTING -m state --state NEW -m statistic --mode nth --every 3 --packet 0 -j SNAT --to-destination 10.50.208.92
sudo iptables -t nat -D PREROUTING -m state --state NEW -m statistic --mode nth --every 2 --packet 0 -j SNAT --to-destination 10.50.208.93
sudo iptables -t nat -D PREROUTING -m state --state NEW -m statistic --mode nth --every 1 --packet 0 -j SNAT --to-destination 10.50.208.94

0條評論
作者已關閉評論
阿莫西林的雜貨鋪
12文章數
0粉絲數
阿莫西林的雜貨鋪
12 文(wen)章 | 0 粉(fen)絲
原(yuan)創

iptables -m statistic --mode nth 實現流量分擔

2023-10-07 09:35:59
92
0

有(you)這么(me)一種情況了(le),使(shi)用(yong)linux作為一個(ge)網關(guan),假如(ru)有(you)多個(ge)彈性(xing)ip,那(nei)么(me)如(ru)何使(shi)得(de)經(jing)過網關(guan)的流(liu)量從幾(ji)個(ge)彈性(xing)ip分流(liu)出(chu)去呢

有一種辦法就是解決使用Linux系(xi)統(tong)自帶的的iptables的statistic match,而不用引入其他(ta)組件


假設有2個彈性ip
必須嚴格按照順序來(否則達不到要的效果)  --every 2 --packet 0 在前,--every 1 --packet 0在后面
添加規則
sudo iptables -t nat -A PREROUTING -m state --state NEW -m statistic --mode nth --every 2 --packet 0 -j SNAT --to-destination 10.50.208.92
sudo iptables -t nat -A PREROUTING -m state --state NEW -m statistic --mode nth --every 1 --packet 0 -j SNAT --to-destination 10.50.208.93


刪除規則
sudo iptables -t nat -D PREROUTING -m state --state NEW -m statistic --mode nth --every 2 --packet 0 -j SNAT --to-destination 10.50.208.92
sudo iptables -t nat -D PREROUTING -m state --state NEW -m statistic --mode nth --every 1 --packet 0 -j SNAT --to-destination 10.50.208.93

 


假設有3個彈性ip
注意規則的順序,由先到后的順序是
--mode nth --every 3 --packet 0
--mode nth --every 2 --packet 0
--mode nth --every 1 --packet 0

sudo iptables -t nat -A PREROUTING -m state --state NEW -m statistic --mode nth --every 3 --packet 0 -j SNAT --to-destination 10.50.208.92
sudo iptables -t nat -A PREROUTING -m state --state NEW -m statistic --mode nth --every 2 --packet 0 -j SNAT --to-destination 10.50.208.93
sudo iptables -t nat -A PREROUTING -m state --state NEW -m statistic --mode nth --every 1 --packet 0 -j SNAT --to-destination 10.50.208.94

刪除規則
sudo iptables -t nat -D PREROUTING -m state --state NEW -m statistic --mode nth --every 3 --packet 0 -j SNAT --to-destination 10.50.208.92
sudo iptables -t nat -D PREROUTING -m state --state NEW -m statistic --mode nth --every 2 --packet 0 -j SNAT --to-destination 10.50.208.93
sudo iptables -t nat -D PREROUTING -m state --state NEW -m statistic --mode nth --every 1 --packet 0 -j SNAT --to-destination 10.50.208.94

文章來自個人專欄
文章 | 訂(ding)閱
0條評論
作者已關閉評論
作者已關閉評論
0
0