Linux Can';t获取nftables以将端口80重定向到8080
我尝试设置服务器,使其将端口80的流量重定向到端口8080,但不起作用。(如果我将telnet连接到端口80,则会出现“连接被拒绝”错误,并且使用firefox时会出现“无法连接”错误。) 我已经能够使用iptables让它工作,但更喜欢使用nftables。有人知道问题出在哪里吗?(如果相关,服务器运行在linode.com上,内核由linode提供。) 我在/etc/nftables.conf中有以下内容:Linux Can';t获取nftables以将端口80重定向到8080,linux,redirect,iptables,nat,netfilter,Linux,Redirect,Iptables,Nat,Netfilter,我尝试设置服务器,使其将端口80的流量重定向到端口8080,但不起作用。(如果我将telnet连接到端口80,则会出现“连接被拒绝”错误,并且使用firefox时会出现“无法连接”错误。) 我已经能够使用iptables让它工作,但更喜欢使用nftables。有人知道问题出在哪里吗?(如果相关,服务器运行在linode.com上,内核由linode提供。) 我在/etc/nftables.conf中有以下内容: #!/usr/sbin/nft -f flush ruleset table i
#!/usr/sbin/nft -f
flush ruleset
table ip fw {
chain in {
type filter hook input priority 0;
# accept any localhost traffic
iif lo accept
# accept traffic originated from us
ct state established,related accept
# accept ssh, alternative http
tcp dport { ssh, http, http-alt } ct state new counter accept
counter drop
}
}
table ip nat {
chain prerouting {
type nat hook prerouting priority 0;
tcp dport http redirect to http-alt
}
chain postrouting {
type nat hook postrouting priority 0;
}
}
您是指
表inet过滤器
而不是表ip fw
如果是这样,我也有类似的问题。将ip nat预路由
优先级更改为-101使其工作,但我不确定原因。它可能与的默认优先级有关。唯一有效的范围是-101到-200
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0;
counter
# accept any localhost traffic
iif lo accept
# accept traffic originated from us
ct state {established,related} accept
# activate the following line to accept common local services
tcp dport { 22, 80, 443, 9443 } ct state new accept
# accept neighbour discovery otherwise IPv6 connectivity breaks.
ip6 nexthdr icmpv6 icmpv6 type { nd-neighbor-solicit, nd-router-advert, nd-neighbor-advert } accept
# count and drop any other traffic
counter drop
}
}
table ip nat {
chain input {
type nat hook input priority 0;
counter
}
chain prerouting {
type nat hook prerouting priority -101;
counter
tcp dport 443 counter redirect to 9443
}
chain postrouting {
type nat hook postrouting priority 0;
counter
}
}
计数器
规则可以轻松查看链是否正在处理;计数器值可以通过nft列表规则集查看,如果您仅在本地主机上路由,请尝试使用
table ip nat {
chain output {
type nat hook output priority 0;
tcp dport http redirect to http-alt
}
}
几年前,我读过iptables,循环设备上的数据包不会穿过预路由链,而是通过输出链。那是我的问题 最后一行将变为
ip daddr 127.0.0.1 tcp dport http redirect to http alt
,例如,如果您只想重定向指向127.0.0.1的数据包,这将允许使用http://localhost/
而不是http://localhost:8080/