为了将访问外网端口(假设是 1688)的所有请求都重定向到内网的某台机器,今天足足折腾了一整天。所幸终于搞定了。
假设外网有多个服务,都运行在端口 1688 上,而我内网能够模拟这个服务,运行在 192.168.0.14 上,端口也是 1688,那么我希望所有访问外网服务的请求都重定向回内网,提高访问速度,应该怎么做呢?

/ip firewall nat
add chain=dstnat dst-address=!192.168.0.0/24 protocol=tcp dst-port=1688 \
action=dst-nat to-address=192.168.0.14
包改变情况如下:
192.168.0.2 > 8.8.8.8 ---> 192.168.0.2 > 192.168.0.14
8.8.8.8 的目标地址信息丢失了。 (并没有丢失,信息还保存在路由器中,这是之前的误解。)
192.168.0.14 > 192.168.0.2 ---> 废弃 #此路不通
/ip firewall nat
add chain=srcnat src-address=192.168.0.0/24 \
dst-address=192.168.0.14 protocol=tcp dst-port=1688 \
out-interface=lan action=masquerade
包改变情况如下:
192.168.0.2 > 8.8.8.8 ---> 192.168.0.1 > 192.168.0.14
192.168.0.14 > 192.168.0.1 ---> 8.8.8.8 > 192.168.0.2
这样包就能够顺利来回了。