跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 使用Nftables 低成本高效率转发
未分類
11 2 月 2020

使用Nftables 低成本高效率转发

airski 大佬有话说 :

使用Nftables 低成本高效率转发

看到好几次流量转发的帖子, 2020年了, 闲着学习了一下Nftables,基于包的策略, 理论转发效率要比应用层的软件 haproxy socat 之类的好N倍.

#!/usr/sbin/nft -f

delete table ip nat

table ip nat {
   
        map port_to_ip {
                type inet_service : ipv4_addr
                elements = {
                      1000: 192.168.1.1
           }
        }

        map port_to_port {
                type inet_service : inet_service
                elements = {
                      1000: 1000
           }
        }

        chain prerouting {
                type nat hook prerouting priority 100; policy accept;
                dnat to tcp dport map @port_to_ip:tcp dport map @port_to_port
                dnat to udp dport map @port_to_ip:udp dport map @port_to_port
        }

        chain postrouting {
                type nat hook postrouting priority 100; policy accept;
                masquerade random,persistent
        }

}

使用方法:

1. 安装nftables
2. 保存以上的code, 记得编辑 port_to_ip, port_to_port. 2个数据表为 转发端口对应目标节点, 转发端口对应目标端口.
3. 加载 `nft -f xxx`

特别提醒, 安装了docker机器慎用

guonning2000 大佬有话说 :

可以试试

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具