我们刚刚设置了Mikrotik路由器,并拥有服务器的公共IP地址和我们的本地IP地址。
我们创建了一个dst-nat
规则,任何访问
public_ip:80
被dst_nat
应用于local_ip:8082
端口
但是,从我们的本地IP地址,我们无法访问此公共IP地址。
如果在主机文件中我们写入local_ip
public_dns_name
,它将起作用。
为什么mikrotik不发送到public_ip地址,即不应用dst-nat规则?
答案 0 :(得分:0)
通过添加srcnat规则解决了该问题,该规则伪装了来自本地网络的所有流量
Chain
srcnat
Src. Address -> our local network
192.168.88.0/24
Dst. Address -> our server
192.168.88.249
Protocol
6 (tcp)
Action
masquerade
答案 1 :(得分:0)
此问题及其解决方案在microtik的文档中进行了说明:https://wiki.mikrotik.com/wiki/Hairpin_NAT
基本上,路由器在答复网络内部的计算机时会将所有内容转换为本地IP地址。您的客户向某个公共IP发送了一个请求,因此它正在等待来自同一公共IP的答复。 microtik将请求转换为本地IP,因此它发送了带有错误“发件人”地址的回复,而您的客户则忽略了它。您可以通过设置伪装规则或添加绕过公共IP需求的静态DNS条目来解决此问题。
在我的情况下,问题在于该规则设置为仅适用于来自WAN(而非LAN)的流量。我将其更改为从任何地方路由流量,只要它请求我的公共IP。
chain: dstnat
dst address: <public ip>
protocol: 6 (tcp)
dst port: 80
in. interface list: all
action: dst-nat
to addresses: <server local ip>
to ports: <server port>