วันศุกร์ที่ 31 พฤษภาคม พ.ศ. 2562

[MikroTik] เข้าทางไหน ออกทางนั้น

redirect incoming traffic in wan1 and wan2 to the local server
/ip firewall nat add chain=dstnat protocol=tcp dst-port=22 in-interface=wan1 action=dst-nat to-addresses=192.168.0.1 to-ports=22
/ip firewall nat add chain=dstnat protocol=tcp dst-port=22 in-interface=wan2 action=dst-nat to-addresses=192.168.0.1 to-ports=22
what comes from wan1, gets out from wan1
/ip firewall mangle add action=mark-connection chain=input in-interface=wan1 new-connection-mark=wan1_conn passthrough=yes disabled=no comment="in wan1,out wan1"
/ip firewall mangle add action=mark-routing chain=output connection-mark=wan1_conn new-routing-mark=wan1_traffic passthrough=no disabled=no comment="in wan1,out wan1"
what comes from wan2, gets out from wan2
/ip firewall mangle add action=mark-connection chain=input in-interface=wan2 new-connection-mark=wan2_conn passthrough=yes disabled=no comment="in wan2,out wan2"
/ip firewall mangle add action=mark-routing chain=output connection-mark=wan2_conn new-routing-mark=wan2_traffic passthrough=no disabled=no comment="in wan2,out wan2"
port forwards from wan1, gets out from wan1
/ip firewall mangle add action=mark-connection chain=forward in-interface=wan1 connection-state=new new-connection-mark=wan1_pfw passthrough=no disabled=no comment="pfw wan1, out wan1"
/ip firewall mangle add action=mark-routing chain=prerouting in-interface=lan connection-mark=wan1_pfw new-routing-mark=wan1_traffic passthrough=no disabled=no comment="pfw wan1, out wan1"
port forwards from wan2, gets out from wan2
/ip firewall mangle add action=mark-connection chain=forward in-interface=wan2 connection-state=new new-connection-mark=wan2_pfw passthrough=no disabled=no comment="pfw wan2, out wan2"
/ip firewall mangle add action=mark-routing chain=prerouting in-interface=lan connection-mark=wan2_pfw new-routing-mark=wan2_traffic passthrough=no disabled=no comment="pfw wan2, out wan2"
routing rules for wan1_traffic and wan2_traffic
/ip route add dst-address=0.0.0.0/0 gateway=wan1 distance=1 routing-mark=wan1_traffic disabled=no
/ip route add dst-address=0.0.0.0/0 gateway=wan2 distance=1 routing-mark=wan2_traffic disabled=no
Credit: MikroTik Tutoroial.