Port forwarding partially working on ports 80, 22, 443

Hello,

I am trying to forward the usual http and https ports to a webserver inside my network from the WAN interface.
I am getting the SYN packet to arrive on the webserver and the SYN/ACK to be sent but the router will block the response.

I have created the NAT rule using the following fields:

  • Chain: dstnat
  • protocol: tcp
  • dst port: 80,443
  • in-interface: pppoe-wan
  • action: dst-nat
  • to addresses: 10.0.2.251 (my webserver LAN ip address)

However if I try to forward port 90 (WAN) to port 80 (on my webserver) for example, it works.
As if there was already a rule regarding ports 80, 443 and 22 (I’ve also tried to forward the ssh port and same thing happened)
I only have 2 dst-nat rules, one for this webserver on ports 80,443 and one on my unifi NVR on port 7443 (which works)
Regarding the firewall rules, I have the debconf rules automatically added + my L2TP IPSec rules (for ipsec protocol + UDP port 500, 1701, 4500) and that’s it.

I have even created the forward rule in the firewall section to accept packed arriving on the WAN interface on ports 80, 443 to be forwarded to address 10.0.2.251 with no difference.
I am aware that the NAT rule should automatically set that rule but I did that just in case…

Last, I’ve tried disabling temporarily the rules which were dropping connections to see if it would make any difference but none.

Anyone has seen this?

Post your config.

/export  hide-sensitive

apr/21/2020 17:36:20 by RouterOS 6.46.4

software id = TVAR-V6D9

model = 960PGS

serial number = AD8A0B5A003B

/interface bridge
add admin-mac=C4:AD:34:49:5F:81 arp=proxy-arp auto-mac=no comment=defconf name=bridge
/interface ethernet
set [ find default-name=ether4 ] poe-out=forced-on
/interface pppoe-client
add add-default-route=yes disabled=no interface=ether1 name=pppoe-3bb use-peer-dns=yes user=yh21r84651@3bb
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/ip hotspot profile
set [ find default=yes ] html-directory=flash/hotspot
/ip ipsec profile
add enc-algorithm=aes-256,aes-192,aes-128,3des name=l2tp
/ip ipsec proposal
add enc-algorithms=aes-256-cbc,aes-192-cbc,aes-128-cbc,3des name=l2tp-ipsec pfs-group=modp2048
/ip pool
add name=dhcp ranges=10.0.2.100-10.0.2.199
add name=l2tp-pool ranges=10.0.2.90-10.0.2.95
/ip dhcp-server
add address-pool=dhcp disabled=no interface=bridge name=defconf
/ppp profile
add local-address=10.0.2.89 name=l2tp-profile remote-address=l2tp-pool
/interface bridge port
add bridge=bridge comment=defconf interface=ether2
add bridge=bridge comment=defconf interface=ether3
add bridge=bridge comment=defconf interface=ether4
add bridge=bridge comment=defconf interface=ether5
add bridge=bridge comment=defconf interface=sfp1
/ip neighbor discovery-settings
set discover-interface-list=LAN
/interface l2tp-server server
set default-profile=l2tp-profile enabled=yes use-ipsec=yes
/interface list member
add comment=defconf interface=bridge list=LAN
add comment=defconf interface=ether1 list=WAN
add interface=pppoe-3bb list=WAN
/ip address
add address=10.0.2.1/24 comment=defconf interface=ether2 network=10.0.2.0
/ip cloud
set ddns-enabled=yes
/ip dhcp-client
add comment=defconf interface=ether1
/ip dhcp-server network
add address=10.0.2.0/24 comment=defconf gateway=10.0.2.1 netmask=24
/ip dns
set allow-remote-requests=yes servers=1.1.1.1,8.8.8.8
/ip dns static
add address=10.0.2.1 name=router.lan
/ip firewall filter
add action=accept chain=input comment=“defconf: accept established,related,untracked” connection-state=established,related,untracked
add action=accept chain=forward dst-address=10.0.2.251 dst-port=443,80 in-interface=pppoe-3bb protocol=tcp
add action=accept chain=input dst-port=80,2222 protocol=tcp src-address=10.0.2.0/24
add action=accept chain=input in-interface=pppoe-3bb protocol=ipsec-esp
add action=accept chain=input dst-port=500,1701,4500 in-interface=pppoe-3bb protocol=udp
add action=accept chain=forward connection-nat-state=dstnat
add action=drop chain=input comment=“defconf: drop invalid” connection-state=invalid
add action=accept chain=input comment=“defconf: accept ICMP” protocol=icmp
add action=drop chain=input comment=“defconf: drop all not coming from LAN” in-interface-list=!LAN
add action=accept chain=forward comment=“defconf: accept in ipsec policy” ipsec-policy=in,ipsec
add action=accept chain=forward comment=“defconf: accept out ipsec policy” ipsec-policy=out,ipsec
add action=fasttrack-connection chain=forward comment=“defconf: fasttrack” connection-state=established,related
add action=accept chain=forward comment=“defconf: accept established,related, untracked” connection-state=established,related,untracked
add action=drop chain=forward comment=“defconf: drop invalid” connection-state=invalid
add action=drop chain=forward comment=“defconf: drop all from WAN not DSTNATed” connection-nat-state=!dstnat connection-state=new in-interface-list=WAN
/ip firewall nat
add action=masquerade chain=srcnat comment=“defconf: masquerade” ipsec-policy=out,none out-interface=pppoe-3bb src-address=10.0.2.0/24
add action=dst-nat chain=dstnat dst-port=7443 in-interface=pppoe-3bb protocol=tcp to-addresses=10.0.2.252
add action=dst-nat chain=dstnat dst-port=80,443 in-interface=pppoe-3bb protocol=tcp to-addresses=10.0.2.251
add action=dst-nat chain=dstnat disabled=yes dst-port=5060-5061 in-interface=pppoe-3bb protocol=udp src-address=61.19.18.180 to-addresses=10.0.2.251
add action=dst-nat chain=dstnat disabled=yes dst-port=10000-20000 in-interface=pppoe-3bb protocol=udp src-address=61.19.18.180 to-addresses=10.0.2.251
/ip firewall service-port
set sip disabled=yes
/ip service
set telnet disabled=yes
set ftp disabled=yes
set ssh port=2222
set api disabled=yes
set api-ssl disabled=yes
/ppp secret
add name=phuketmymac profile=l2tp-profile service=l2tp
/system clock
set time-zone-name=Asia/Bangkok
/system identity
set name=Kathu-Router
/tool mac-server
set allowed-interface-list=LAN
/tool mac-server mac-winbox
set allowed-interface-list=LAN

Just a quick look and can not see anything wrong.
You do not need filter rules for NAT, but can be nice to have to limit things:

add action=accept chain=forward dst-address=10.0.2.251 dst-port=443,80 in-interface=pppoe-3bb protocol=tcp

Yeah, I am aware of that. But I wanted to add it just to see if it would make any difference.

Thanks anyway.

Are you trying to reach the server from users/devices within the same subnet or getting friends to try from outside connections?

I am trying myself to access my Server from home.
I have a VPN access to my office network.

Within the internal network, it works, webserver is accessible.
From the internet, it won’t work.

Using tshark on my webserver which is BTW a Proxmox Debian 10 VM, I can see the packets coming in, and being acknowledged but it seems the router is dropping the SYN/ACK somehow.
If I forward port 90 to port 80 on my VM, it then works.

It’s quite confusing.

If you are at work where the server is, try to use this web page:

https://www.canyouseeme.org/

Test if port 80 and 443 get success.

I don’t have any machine with a graphical interface turned on to access that webpage in my office network.
I am not there, I can only access it through IPSec VPN.

However I have an amazon VPS on which I did remote connect and try to telnet the 2 ports with the same issue.

Using tshark again, I am seeing loads of TCP Retransmission packets initiated from my webserver.

Here is the output of tshark on my webserver

281 3402.996293289 XXX.XXX.XXX.XXX? 10.0.2.251 TCP 74 38694 ? 443 [SYN] Seq=0 Win=62727 Len=0 MSS=1440 SACK_PERM=1 TSval=1555072909 TSecr=0 WS=128
282 3402.996341159 10.0.2.251 ? XXX.XXX.XXX.XXX TCP 74 443 ? 38694 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM=1 TSval=40080195 TSecr=1555072909 WS=128
283 3404.000593151 10.0.2.251 ? XXX.XXX.XXX.XXX TCP 74 [TCP Retransmission] 443 ? 38694 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM=1 TSval=40081199 TSecr=1555072909 WS=128
284 3404.010957846 XXX.XXX.XXX.XXX ? 10.0.2.251 TCP 74 [TCP Retransmission] 38694 ? 443 [SYN] Seq=0 Win=62727 Len=0 MSS=1440 SACK_PERM=1 TSval=1555073923 TSecr=0 WS=128
285 3404.010986776 10.0.2.251 ? XXX.XXX.XXX.XXX TCP 74 [TCP Retransmission] 443 ? 38694 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM=1 TSval=40081210 TSecr=1555072909 WS=128
286 3406.016585157 10.0.2.251 ? XXX.XXX.XXX.XXX TCP 74 [TCP Retransmission] 443 ? 38694 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM=1 TSval=40083215 TSecr=1555072909 WS=128
287 3406.026966173 XXX.XXX.XXX.XXX ? 10.0.2.251 TCP 74 [TCP Retransmission] 38694 ? 443 [SYN] Seq=0 Win=62727 Len=0 MSS=1440 SACK_PERM=1 TSval=1555075939 TSecr=0 WS=128
288 3406.026995753 10.0.2.251 ? XXX.XXX.XXX.XXX TCP 74 [TCP Retransmission] 443 ? 38694 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM=1 TSval=40083226 TSecr=1555072909 WS=128
289 3410.144574907 10.0.2.251 ? XXX.XXX.XXX.XXX TCP 74 [TCP Retransmission] 443 ? 38694 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM=1 TSval=40087343 TSecr=1555072909 WS=128
290 3410.283014475 XXX.XXX.XXX.XXX ? 10.0.2.251 TCP 74 [TCP Retransmission] 38694 ? 443 [SYN] Seq=0 Win=62727 Len=0 MSS=1440 SACK_PERM=1 TSval=1555080196 TSecr=0 WS=128
291 3410.283050402 10.0.2.251 ? XXX.XXX.XXX.XXX TCP 74 [TCP Retransmission] 443 ? 38694 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM=1 TSval=40087482 TSecr=1555072909 WS=128

First of all you should probably not be using work vpn for personal business.
Secondly one has no clue of the security setup of the business connectivity in or out is a crapshoot.

SO instead of wasting our time, get a friend to connect from a NORMAL connection on the outside, and let us know if that works first.

First of all, you seem to be an expert and I am not, so pleas en-light me on why I should not be using a work VPN for a personal business if I want to?

Secondly, I gave you the entire config of my router and told you that it was directly connecting to a Debian VM on a Proxmox Server.
If someone friendly enough (which is definitely not your case) is willing to ask me some other questions on the topology on my network, I am very happy to answer those questions.

SO, if you are irritated by my post, I just encourage you to GTFO and let me be.
Oh and I forgot, I already said I was trying from a VPS which is not on the same network, not to mention I also tried accessing my Server with the VPN connection disabled (yeah we can turn on/off Road warriors connections to test, don’t you know the EXPERT?!)

Go out and have a walk, you seem to be needing it.

If you like help you should not reply in this way.

He was saying that both VPS (using Telent) and VPN are not normal use to access website and makes tings more complicate.
Your config looks Ok. Try to set router to 100% default config and just add the dst-nat for port 80.
Then someone on the outside, not VPS, not VPN should try to open the website using a normal PC with a normal browser.

Does this mean the HTTP/HTTPS service “ports” are still active ? Did you also added that only internal IP’s are allowed to call these www & www-ssl services?
(www & www-ssl services)

I wonder if they muck up somehow?
Dunno, just guessing.
In my config anyway, any of these ports are strictly limited to my internal LAN-range.

In your config below service “www” and “www-ssl” are missing, so I assume they are just enabled? And not limited from where you can consult them ?

/ip service
set telnet disabled=yes
set ftp disabled=yes
set ssh port=2222
set api disabled=yes
set api-ssl disabled=yes

I am really not willing to reply in this way, but having someone telling me that I am wasting his time is not pleasant to hear.
People should learn to be polite. If I am wasting people’s time, then just don’t answer me, no big deal.

I have tried using my mobile phone which is on a 4G network (Wi-Fi off) and the same thing was happening.

A telnet should be good enough to test a connection I believe (at least the TCP handshake).
Also having the VPN disconnected act as if I was a stranger to the network and it should execute the NAT rule normally.

Here is a screenshot of the connections state and it seems that the router never sees the SYN/ACK coming, isn’t it?
https://postimg.cc/ZWhXBdZz

That was my thought. Since the router use them, I was wondering if the rules related to them were overriding the NAT rules, especially since my test on port 90 (WAN interface) redirected to port 80 (on my Webserver) was working.
EDIT: http is enabled on the router but https isn’t. ssh port was changed to 2222, though when I did try forwarding port 22 to my webserver, same thing happened.
Trying port 443 from the outside does not work either with the same TCP Retransmission happening,

It could still be the proxmox server which is acting up but I’ve checked the firewall rules and everything is off, on both the host and the VM.

Did you add some logging to all drop rules so at least in the RouterOS logs you see when & why packets are dropped ??
What about the “counters” you can which counter is “going up” when you try ???
Perhaps one of these default rules you have drop packets marked “invalid” ? and for some reason you hit that rule ?
After all, it’s a firewall right?

I can see the NAT rule counter going up but I haven’t set on the logs for drop rules.
Reason being is that I have temporarily disabled all of these and tried and it didn’t make any difference.

Can I log all the packets coming from an IP/HW Addr on the Mikrotik?
I would like to know if the SYN/ACK reaches the router or is never leaving my Server.

Otherwise, I guess I’ll have reset completely the router and set it up from scratch.
Though we are in lockdown at the moment so I can’t reach my office for a week or more.

There is full blown packet capture in there under tools, so I guess you can simple capture anything on all ports of you device and filter against the MAC of your server for example. Then you can see something SYNACK-alike arrives…
Or use “Torch” and filter the MAC of the server.

Your server is directly connected to the Mikrotik or is there some other switch/device in between ?

Why do you have following ??

add admin-mac=C4:AD:34:49:5F:81 arp=proxy-arp auto-mac=no comment=defconf name=bridge

My Bridge-interface is just using “arp” :wink: