使用nftables转发10443端口到某个ip的443端口为例子
开启转发功能
编辑文件
sudo nano /etc/sysctl.conf打开下面的选项
net.ipv4.ip_forward=1使配置生效,运行命令
sudo sysctl -p
进行端口转发
编辑配置文件
sudo nano /etc/nftables.conf加入如下配置,xx.xx.xx.xx是你要转入的ip,回程也同样经过本机
table ip nat {
chain prerouting {
type nat hook prerouting priority -100;
tcp dport 10443 dnat to xx.xx.xx.xx:443
}
chain postrouting {
type nat hook postrouting priority 100;
ip daddr xx.xx.xx.xx tcp dport 443 masquerade
}
}使配置生效
sudo nft -f /etc/nftables.conf查看是否成功
运行下面的命令,即可看到相关转发规则
sudo nft list ruleset