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

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

iptables配置流量轉發

2024-04-30 09:17:41
41
0

iptables可(ke)以認為是(shi)一種防(fang)火墻,可(ke)以攔截(jie)、轉發特定包

*:它和firewall是同一(yi)角色,都是操作內核對網絡的配(pei)置(zhi)。所以(yi)在iptables和firewall同時配(pei)置(zhi)時,配(pei)置(zhi)均生效

 

iptables內(nei)的“四(si)表五鏈”邏輯

 

我們可以在 FORWARD chain中配置轉發

1、配置UDP轉(zhuan)發

轉發10000端口的(de)udp包(bao)至172.16.0.1機(ji)器

sudo iptables -t nat -A PREROUTING -p udp --dport 10000 -j DNAT --to-destination 172.16.0.1:10000   
sudo iptables -t nat -A POSTROUTING -p udp --dport 10000 -d 172.16.0.1 -j MASQUERADE   
sudo iptables -I FORWARD -p udp --dport 10000 -d 172.16.0.1 -j ACCEPT     # 允許本機轉至172.16.0.1的規則
sudo iptables -I FORWARD -p udp --sport 10000 -s 172.16.0.1 -j ACCEPT      # 允許源ip為172.16.0.1的轉發

參數解析:

-t 表nat

-A 添加(jia)規則,添加(jia)至表尾(wei)

-I 插入(ru)規則,插入(ru)至(zhi)表(biao)頭

-p 協議

--dport 目標端(duan)口

--sport 源端(duan)口

-j 操作

-d 目標ip

-s 源ip

 

2、配置TCP轉發

與udp類似,將(jiang)-p參數(shu)改為tcp即可

sudo iptables -t nat -A PREROUTING -p tcp --dport 1555 -j DNAT --to-destination 172.16.0.1:1555
sudo iptables -t nat -A POSTROUTING -p tcp --dport 1555 -d 172.16.0.1 -j MASQUERADE
sudo iptables -I FORWARD -p tcp --dport 1555 -d 172.16.0.1 -j ACCEPT
sudo iptables -I FORWARD -p tcp --sport 1555 -s 172.16.0.1 -j ACCEPT

 

3、iptables配置持久化

sudo systemctl status iptables   #查看服務是否已安裝
sudo yum install iptables-services   #安裝服務

#開啟iptables服務前,用命令sudo service iptables save保存一下當前配置,否則可能會被覆蓋
sudo service iptables save
sudo systemctl start iptables
sudo service iptables save
sudo cat /etc/sysconfig/iptables

至此,iptables配(pei)置(zhi)全部持久化(hua),每(mei)次重啟機器,iptables service會讀(du)取 /etc/sysconfig/iptables 下的配(pei)置(zhi)并加載

0條評論
0 / 1000
z****n
5文(wen)章(zhang)數
0粉絲數
z****n
5 文章 | 0 粉絲
原創(chuang)

iptables配置流量轉發

2024-04-30 09:17:41
41
0

iptables可(ke)以認為是一種防火墻,可(ke)以攔截、轉(zhuan)發特定包

*:它和firewall是(shi)同(tong)一角色(se),都是(shi)操作(zuo)內核對網絡的配(pei)(pei)置。所以在iptables和firewall同(tong)時配(pei)(pei)置時,配(pei)(pei)置均生效

 

iptables內的“四表五(wu)鏈”邏輯

 

我們可以在 FORWARD chain中配置轉發

1、配(pei)置UDP轉(zhuan)發

轉發10000端(duan)口的udp包至172.16.0.1機器

sudo iptables -t nat -A PREROUTING -p udp --dport 10000 -j DNAT --to-destination 172.16.0.1:10000   
sudo iptables -t nat -A POSTROUTING -p udp --dport 10000 -d 172.16.0.1 -j MASQUERADE   
sudo iptables -I FORWARD -p udp --dport 10000 -d 172.16.0.1 -j ACCEPT     # 允許本機轉至172.16.0.1的規則
sudo iptables -I FORWARD -p udp --sport 10000 -s 172.16.0.1 -j ACCEPT      # 允許源ip為172.16.0.1的轉發

參數解析:

-t 表nat

-A 添(tian)加(jia)規則,添(tian)加(jia)至表尾

-I 插入(ru)規則,插入(ru)至表頭

-p 協議

--dport 目(mu)標端口

--sport 源端口

-j 操作

-d 目標ip

-s 源ip

 

2、配置TCP轉發

與udp類(lei)似,將-p參數(shu)改為tcp即可

sudo iptables -t nat -A PREROUTING -p tcp --dport 1555 -j DNAT --to-destination 172.16.0.1:1555
sudo iptables -t nat -A POSTROUTING -p tcp --dport 1555 -d 172.16.0.1 -j MASQUERADE
sudo iptables -I FORWARD -p tcp --dport 1555 -d 172.16.0.1 -j ACCEPT
sudo iptables -I FORWARD -p tcp --sport 1555 -s 172.16.0.1 -j ACCEPT

 

3、iptables配置持久化

sudo systemctl status iptables   #查看服務是否已安裝
sudo yum install iptables-services   #安裝服務

#開啟iptables服務前,用命令sudo service iptables save保存一下當前配置,否則可能會被覆蓋
sudo service iptables save
sudo systemctl start iptables
sudo service iptables save
sudo cat /etc/sysconfig/iptables

至(zhi)此(ci),iptables配置全(quan)部持久化,每次重啟機器,iptables service會讀取(qu) /etc/sysconfig/iptables 下的配置并(bing)加載

文章來自個人專欄
文章 | 訂閱
0條評論
0 / 1000
請輸入你的評論
0
0