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 大佬有话说 :
可以试试