Community discussions

MikroTik App
 
hernandes
just joined
Topic Author
Posts: 2
Joined: Fri Apr 27, 2018 12:26 am

Define source IP for router traffic generated

Fri Apr 27, 2018 12:32 am

Hello guys.

How can I define a source IP/INTERFACE for traffic generated by router itself? Like DNS search, upgrade, ping, resolve, etc.

Thanks
 
gtpeace
just joined
Posts: 1
Joined: Wed May 25, 2016 5:06 am

Re: Define source IP for router traffic generated

Sun Apr 29, 2018 8:50 pm

Hello,

I also have this question.

Because of IPv4 depletion, and the need for several routers on my network, my ISP gave me RFC1918 addresses for the WAN interface and a single non-RFC1918 address for each router.

I was hopping I could assign the non-RFC1918 to a bridge interface and use it as source address mainly to upgrade the router, although, It will also need the DNS queries to be sourced from the non-RFC1918 address in my scenario.

I've identified a couple options where src-address is available with the following syntax
ping 8.8.4.4 src-address=203.0.113.11
system ssh 198.51.100.11 src-address=203.0.113.11

I was thinking it would be nice to have it for other features like:
system package update check-for-updates src-address 203.0.113.11
system telnet 10.1.1.130 src-address 203.0.113.11

or maybe a system wide option like
ip src-address or system ip src-address

If there is a workaround/solution that "mascarades" traffic generated by router itself, I'm willing to give it a try. I there is currently no way to do this, can it be made a feature request?

Thanks in advance.
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: Define source IP for router traffic generated

Mon Apr 30, 2018 9:28 pm

The router normally chooses a local source address for each route based on the subnet of that route's gateway IP, and you can specify a particular address to use on that route for locally originated traffic.

Where this is not sufficient, like in your case where the public adddress is not assigned to the internet-facing interface, EDIT: you can use src-nat. (was: an ugly way to src-nat a locally originated packet exists).
Last edited by sindy on Tue May 01, 2018 12:36 am, edited 1 time in total.
 
hernandes
just joined
Topic Author
Posts: 2
Joined: Fri Apr 27, 2018 12:26 am

Re: Define source IP for router traffic generated

Mon Apr 30, 2018 9:34 pm

an ugly way to src-nat a locally originated packet exists

Maris sent me an email with this same suggestion: mark a packet on outside and src nat!

Actually I really don't like this, but seems we don't have another way.
Last edited by hernandes on Mon Apr 30, 2018 10:02 pm, edited 1 time in total.
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: Define source IP for router traffic generated

Mon Apr 30, 2018 9:49 pm

mark a packet on outside and src nat!
EDIT: the text below is not true for src-nat.
The problem is that it is not this simple because RouterOS does not allow to src-nat locally originated packets directly, this picture says it all - there is no
output
chain in the
nat
table. That's why the loopback tunnel described on the link above is necessary to dst-nat or src-nat locally originated packets before sending them to the wire.

People used to linux
netfilter
(aka
iptables
) usually forget about the fact that the functionality is not enabled 1:1 in RouterOS. On the other hand, people spoilt by Mikrotik's address lists are usually surprised that this functionality doesn't exist out of the box on many linux distributuions.
Last edited by sindy on Tue May 01, 2018 12:40 am, edited 2 times in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9121
Joined: Mon Apr 20, 2009 9:11 pm

Re: Define source IP for router traffic generated

Tue May 01, 2018 12:16 am

No! :) The ugly linked thing is only for dstnat. Srcnat works for locally originated connections just fine, because srcnat is postrouting thing. And that happens no matter if the packet came from output or forward.
 
sindy
Forum Guru
Forum Guru
Posts: 10206
Joined: Mon Dec 04, 2017 9:19 pm

Re: Define source IP for router traffic generated

Tue May 01, 2018 12:34 am

srcnat is postrouting thing. And that happens no matter if the packet came from output or forward.
Agrrrreed. Apologies, same thing, too late here.
 
User avatar
bcbigb
just joined
Posts: 20
Joined: Sat Dec 28, 2013 5:48 pm

Re: Define source IP for router traffic generated

Wed Aug 04, 2021 11:24 am

In case someone wanders by this thread and needs help, I think I've come up with a good solution that's simple and seems to solve the issue for all internal utilities/methods that generate DNS traffic (and probably all other types as well). My issue stems from the fact that I need it to go over IPSEC tunnels, which are policies, not routes, so it fixed the issue for me, but I'd suspect it's close to, if not dead on, what you need.

Please read what you can and comment in case there are some caveats I haven't explored or thought of yet.

viewtopic.php?f=2&t=177344


>> Quick Update: Since it's a big post with multiple issues encountered and solved, use the last code snippet in my original post, where I set a route to use the main bridge, that scoops up this internal traffic and puts it in the path of the IPSEC policy matchers or at least sets it to go out the main NAT/route if not. The solution mentioned there by pe1chl is useful to fix the IPSEC issues, but this solves other problems for what I'll call "undefined" traffic where a source address is not explicitly defined or selected.

Who is online

Users browsing this forum: almdandi, maigonis, mukkelek, Zan and 105 guests