大网数据广告活动
服务器运维问答

Routing from mikrotik two IP addresses to same gateway

· 52CE 我爱测

I have 2 static addreses ( a.b.c.72/24 and a.b.c.128/24 ) on gateway1 and gateway2 interfaces. ISP have one gateway a.b.c.1 . I can use a.b.c.72 only on gateway1 , a.b.c.128 only on gateway2 . How to get a.b.c.128 working? I want…

问题原文

原帖链接 · eri · CC BY-SA 3.0

I have 2 static addreses (a.b.c.72/24 and a.b.c.128/24) on gateway1 and gateway2 interfaces. ISP have one gateway a.b.c.1 . I can use a.b.c.72 only on gateway1, a.b.c.128 only on gateway2.

How to get a.b.c.128 working? I want route some local machines via second interface. I know some ways to route via different gateways in mikrotik. In linux i can specify dev parameter to route.

I added routing tables and rules, but it still routed via gateway2.

 /ip dhcp-client print
Flags: X - disabled, I - invalid 
 #   INTERFACE           USE ADD-DEFAULT-ROUTE STATUS        ADDRESS           
 0   gateway1            yes no                bound         X.Y.164.72/24  
 1   gateway2            yes no                bound         X.Y.164.128/24 



/ip route
add distance=51 gateway=X.Y.164.1 pref-src=X.Y.164.128 routing-mark=gate2
add distance=1 dst-address=X.Y.164.0/24 gateway=gateway2 pref-src=X.Y.164.128 routing-mark=gate2
add distance=52 gateway=X.Y.164.1 pref-src=X.Y.164.72 routing-mark=gate1
add distance=1 dst-address=X.Y.164.0/24 gateway=gateway1 pref-src=X.Y.164.72 routing-mark=gate1
add distance=52 gateway=X.Y.164.1
add distance=10 dst-address=10.0.0.0/8 gateway=center

On selected line i need to have iproute equivalent to ip route add default via 109.60.164.1 dev gateway2 table gate2 but it routes via gateway1 interface

NAT

/ip firewall nat
add action=masquerade chain=srcnat out-interface=gateway1
add action=masquerade chain=srcnat out-interface=gateway2

Mangle is clean now. It had marks connections from and routes for selected clients. It is not a problem and workswith different gateways.

已采纳解答

原帖链接 · ma.tome · CC BY-SA 3.0

Due to the fact that both links have the same IP gateway, you must set in some way the interface you want to use in your routing tables. The syntax is the following: gateway=[ip]%[interface] + specific preferred source; given this fact, in your router these routes should look like the following:

/ip route gateway=109.60.164.1%gateway1 pref-src 109.60.164.72 distance=1 
/ip route gateway=109.60.164.1%gateway2 pref-src 109.60.164.128 distance=2 

/ip route gateway=109.60.164.1%gateway1 pref-src 109.60.164.72 routing-mark=gate1 distance=1 
/ip route gateway=109.60.164.1%gateway2 pref-src 109.60.164.128 routing-mark=gate1 distance=2 

/ip route gateway=109.60.164.1%gateway2 pref-src 109.60.164.128 routing-mark=gate2 distance=1 
/ip route gateway=109.60.164.1%gateway1 pref-src 109.60.164.72 routing-mark=gate2 distance=2

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-02-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。