DNAT not working

Hi ALL,

I configurated a RB1100 and the dnat is not working (source nat works ok).

Each interface is working properly and I can use it normally (actually source nat uses both interfaces).

So I’m using the following rules:

/ip firewall filter
add action=accept chain=lp comment="Accept icmp from internet" disabled=no \
    protocol=icmp
add action=log chain=lp comment="" disabled=no log-prefix=Blocked
add action=drop chain=lp comment="Block any packet from internet" \
    disabled=no
add action=accept chain=speedy comment="Accept icmp from internet" disabled=no \
    protocol=icmp
add action=accept chain=speedy comment="" disabled=no port=80 protocol=tcp
add action=log chain=speedy comment="" disabled=no log-prefix=Blocked
add action=drop chain=speedy comment="Block any packet from internet" \
    disabled=no
add action=jump chain=input comment="" disabled=no dst-address-list=gw \
    in-interface=ether2 jump-target=speedy
add action=jump chain=input comment="" disabled=no dst-address-list=gw \
    in-interface=ether1 jump-target=lp
/ip firewall nat
add action=masquerade chain=srcnat comment="" disabled=no out-interface=\
    ether1 src-address-list=lan
add action=dst-nat chain=dstnat comment="" disabled=no dst-address=\
    MY_EXTERNAL_IP dst-port=80 protocol=tcp to-addresses=192.168.120.9
add action=src-nat chain=srcnat comment="" disabled=no dst-port=80 protocol=\
    tcp src-address=192.168.120.9 to-addresses=MY_EXTERNAL_IP

I’m following the documentation in http://wiki.mikrotik.com/wiki/Manual:IP/Firewall/NAT.

So I’m trying to make anything that came from my external interface on port 80 to be sent to my internal machine.
I tried to remove all filter rules and it didn’t work either (second the documentation in http://wiki.mikrotik.com/wiki/Manual:Packet_Flow#Routing_-_from_Ethernet_to_Ethernet_interface the input table is not used in the nat).

I think I’m missing something pretty basic, but I followed the NAT documentation and I still not discovering the problem. Can anyone help me here?

Cheers,

Jonas

Disable “www” service in “/ip service”

This could be part of it. The port should be src-port=80, not dst-port=80. That would be the dstnat port. Clients normally do not use port 80 outbound for requests.

add action=src-nat chain=srcnat comment=“” disabled=no > dst-port=80 > protocol=
tcp src-address=192.168.120.9 to-addresses=MY_EXTERNAL_IP

And move the masquerade rule below the srcnat/dsnat rules, if it isn’t already.

ADD: If you have more than one ip assigned to ether1, I recommend replacing the masquerade with a srcnat rule.

It is already disabled:

[admin@MikroTik] /ip firewall filter> /ip service print 
Flags: X - disabled, I - invalid 
 #   NAME                                                              PORT  ADDRESS            CERTIFICATE                                                            
 0 X telnet                                                            23    0.0.0.0/0         
 1   ftp                                                               21    0.0.0.0/0         
 2 X www                                                               80    0.0.0.0/0         
 3   ssh                                                               22    0.0.0.0/0         
 4 X www-ssl                                                           443   0.0.0.0/0          none                                                                   
 5 X api                                                               8728  0.0.0.0/0         
 6   winbox                                                            8291  0.0.0.0/0         
[admin@MikroTik] /ip firewall filter>

Cheers,

Jonas

…and you changed the port and moved the masquerade?

Hi SurferTim,

Thank you for your reply.

The port 80 is not their destination port? (I got a little bit confused with this information).

I tried replacing the dst-port w/src-port and I got the same result.


And move the masquerade rule below the srcnat/dsnat rules, if it isn’t already.

I changed the order but it made no difference.

ADD: If you have more than one ip assigned to ether1, I recommend replacing the masquerade with a srcnat rule.

I have just one ip assigned to ether1, I do have more than one link with link with internet but each one is in a separate interface.


So my router still not making the dnat :frowning:

I think that I’m probably missing something really basic :frowning:, can someone help me finding what I’m missing?

Cheers,

Jonas

Hi jonas! I know some of this is a little confusing at first.

When a remote client makes a port 80 request, the client is not using port 80 to make the request. Only the destination port is 80. That is why you nat the destination port on the request (dstnat).

When your internal server responds (srcnat), the destination port will be the port the client was assigned on his router. The source port on these packets will now be 80, not the destination port.

And that is why I said that could be part of it. Let me look at your firewall rules for a bit. Maybe something there. I only brought up the stuff I saw right away.

ADD: I have found everything depends on the order of entries in these lists. I would try moving all the action=jump rules to the top of that list, so the chain=speedy rules are after (below) those.

Hi SurferTim,

Thank you again for your reply.

I already made this configuration with iptables (and ipchains hehe) for other clients but this is the first time I’m using RouterOS.

I’m redirecting all traffic in the input chain to a chain specific to that interface (lp or speedy), this way I think the rules became more manageable.

Let me know if you need more information from my setup.

Thank you again!

Cheers,

Jonas

Did you see my edit above? Try moving those action=jump to the top, above the chain=speedy

Hi SurferTim,

But the rules are in different chains! The chains in the RouterOS work differently the way the tables work in iptables? (I create the chains to make the rules more manageble but if they are problematic to use in the RouterOS I can remove them).

I change the order but it made no difference.

Do you need any other information from my setup?

Cheers,

Jonas

Just to consolidate the changes we made, this is the current setup:

[admin@MikroTik] /ip firewall nat> /ip firewall filter print
Flags: X - disabled, I - invalid, D - dynamic
0 chain=input action=jump jump-target=speedy dst-address-list=gw in-interface=ether2

1 chain=input action=jump jump-target=lp dst-address-list=gw in-interface=ether1

2 ;;; Accept icmp from internet
chain=lp action=accept protocol=icmp

3 chain=lp action=accept protocol=tcp port=80

4 chain=lp action=log log-prefix=“Blocked”

5 ;;; Drop all packages from internet
chain=lp action=drop

6 ;;; Accept icmp from internet
chain=speedy action=accept protocol=icmp

7 chain=speedy action=accept protocol=tcp port=80

8 chain=speedy action=log log-prefix=“Blocked”

9 ;;; Drop all packages from internet
chain=speedy action=drop
[admin@MikroTik] /ip firewall nat> /ip firewall nat print
Flags: X - disabled, I - invalid, D - dynamic
0 chain=dstnat action=dst-nat to-addresses=192.168.120.9 protocol=tcp dst-address=MY_EXTERNAL_IP src-port=80

1 chain=srcnat action=src-nat to-addresses=MY_EXTERNAL_IP protocol=tcp dst-address=192.168.120.9 src-port=80

2 chain=srcnat action=masquerade src-address-list=lan out-interface=ether1
[admin@MikroTik] /ip firewall nat>

Cheers,

Jonas

You are showing chain=speedy as a chain=input subset. I think it needs to be a chain=forward subset, unless it is restricting access to the router OS, not the localnet behind the interface.

And the dstnat rule. It needs to be dst-port=80. The client’s port is the src-port.
The srcnat rule is src-port=80. The client’s port is the dst-port.

Ok, I didn’t understand what you mean. For a internet user he is accessing the router, the server is my internal network with a non-routable ip. This is a standard dnat operation on iptables. Is the input chain the wrong table to put these rules? (I will drop everything except the ports I explicit accept in the input table).

I don’t know what you mean by a chain is a subset of other. I created them just to make the rules more manageable. If they have a different meaning in RouterOS I can remove them (ok, I will miss them a lot).

Is it possible to have access to default iptables command? (I think my life would be a lot easier)

Ok, I will change back these rules.

Thank you again for your reply!

Cheers,

Jonas

As long as you are not blocking any forward chains, you should be ok.

Are you trying the access from outside the router? Like a non-localnet ip?

If you are trying to access the sever from a localnet address using the public address, you will need to use a Hairpin NAT.
http://wiki.mikrotik.com/wiki/Hairpin_NAT

On input I’m blocking everthing but icmp and tcp/80 (other ports I will include later).
On nat I’m trying to redirect all incame traffic in the tcp/80 to my internal server.

At least this is what I’m trying to do but it is not working (as you can see this is a simple port forwarding). I followed the NAT documentation and it didn’t worked. Maybe I’m missing something pretty basic in the RouterOS environment :frowning: (Remember both interfaces work fine and I can source nat through the router fine).

It is not necessary :slight_smile: , I’m outside the company. They have three links and I’m getting in through the other router that I have to disable by the weekend.

Any other ideas?

Thank you for your reply.

Cheers,

Jonas

Can you post “/ip firewall nat print”? I can see better that way.
Can you ping the router public address from a remote ip?
Maybe starting basic will help. When you had the www service enabled and no dstnat/srcnat rules (or disabled if you want to try again), could you get the MikroTik Webbox login page with your browser from a remote ip?

Hi SuferTim,

Sure, I already put the output in the previous message :slight_smile: (when I consolidated the changes we made). The only difference is that I change back to dst-port. There I printed /ip firewall filter print and /ip firewall nat print. Let me know if you need more information about my setup.

Yes, I can ping to it fine, I can see the router in the tracerouter and when I do a tcptracerouter on port 80 I see that the packet get there but it didn’t get any answer in the port 80.

I didn’t tried to access the router login page through internet, I’m definitely not that brave :slight_smile:
But if change the cable from the new router to the old I can access the my internal server fine (so it is not something blocking in the way).

Cheers,

Jonas

I see the entries in the previous post, and the dstnat is not correct. It is showing src-port=80. It needs to be dst-port=80.

Once more:
dstnat with dst-port=80
srcnat with src-port=80

:slight_smile:

You asked me to change to src-port and as I told you in the previous message I already changed back to dst-port :slight_smile: I was been lazy to reposting the output again here :slight_smile:

Any way I will consolidate it again here:

[admin@MikroTik] /ip firewall nat> /ip firewall filter print 
Flags: X - disabled, I - invalid, D - dynamic 
 0   chain=input action=jump jump-target=speedy dst-address-list=gw in-interface=ether2 

 1   chain=input action=jump jump-target=lp dst-address-list=gw in-interface=ether1 

 2   ;;; Accept icmp from internet
     chain=lp action=accept protocol=icmp 

 3   chain=lp action=accept protocol=tcp port=80 

 4   chain=lp action=log log-prefix="Blocked" 

 5   ;;; Drop everything from internet
     chain=lp action=drop 

 6   ;;; Accept icmp from internet
     chain=speedy action=accept protocol=icmp 

 7   chain=speedy action=accept protocol=tcp port=80 

 8   chain=speedy action=log log-prefix="Blocked" 

 9   ;;; Drop everything from internet
     chain=speedy action=drop 
[admin@MikroTik] /ip firewall nat> /ip firewall nat print 
Flags: X - disabled, I - invalid, D - dynamic 
 0   chain=dstnat action=dst-nat to-addresses=192.168.120.9 protocol=tcp dst-address=MY_EXTERNAL_IP dst-port=80 

 1   chain=srcnat action=src-nat to-addresses=MY_EXTERNAL_IP protocol=tcp dst-address=192.168.120.9 dst-port=80 

 2   chain=srcnat action=masquerade src-address-list=lan out-interface=ether1 
[admin@MikroTik] /ip firewall nat>

Let me know if you need more information from my setup.

Thank again for your reply!

Cheers,

Jonas

Ok, now I put this way. It made no difference :frowning:

Cheers,

Jonas