Need advice how to setup 2 public IP addresses on mikrotik RB951G.
One address is for NAT on all local ip addresses and a web server.
The second one is only for an email server which also has web server. Email server is on private IP address.
Do I need switch before mikrotik to separate these two ip addresses in two mikrotik ports ether1 and ether2 or have to assign two public ip address on ether1?
Wanna do a NAT from local IP pool 192.168.88.0/24 to one public IP 181.x.x.79 and forward port 80 and 443 to a local web server 192.168.88.11 and I am clear how to do that.
But also wanna forward all email transfer ports (25,80,143,443,465,587,993) on public IP 181.x.x.80 to a mail server with local IP address 192.168.88.10
The email server has to use only 181.x.x.80 as public IP
Also doesn’t want a scenario were local LAN users use a internet to access email sever and waste traffic.
The mail server needs to be connected to a router or via switch?
Accessing mail server on public address from the rest of LAN won’t really waste traffic (only in LAN, where connections will bounce via router, but it shouldn’t be a problem). But if you want to avoid it, you can set static DNS for mail server in “/ip dns” (clients have to use your router as their DNS resolver for it to work).
Mail server can be connected to switch or switched/bridged LAN port on router, it doesn’t matter much.
Why I am getting public IP instead of local IP address when I am looking for router in winbox neighbors?
edit: when I set out interface public on src nat line, I cannot access email server.. Do I need hairpin or static DNS entry for local IP of the mail server
To get rid of public address in neighbors, add src-address-type=!local to second src-nat rule.
Hairpin NAT is built-in in this solution. If you access mail server using public address from anywhere in LAN, mail server will see client’s source address as 181.x.x.79 and it will work. The usual hairpin NAT with masquerade would use router’s internal address, but it doesn’t really matter, both work fine. I even like the first better, because it at least allows you to tell connections made by router itself from connection made by other clients.
You can also add DNS record pointing to mail server’s internal address directly, it can’t hurt. In fact, in a way it’s even better, but it’s extra work. Not that it’s too hard to add one record. But if you e.g. had more hostnames and later moved one to external server, you must remember to remove it from here.
so, you prefer not adding out interface like it says in wiki primer:
e.g. add chain=srcnat src-address=192.168.1.0/24 action=src-nat to-addresses=1.1.1.1 out-interface=Public ?
not using hairpin nat ?
adding src-address-type=!local to second src-nat to address to address nat rule
Because this (“block everything from WAN, unless it’s forwarded port”) protects you from unwanted connections from WAN, but allows forwarded ports:
add action=drop chain=forward comment="defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat connection-state=new in-interface=ether1
And port forwarding from local LAN is allowed by default.
Regarding your blocklist, rules are processes in order, so if you want to prevent some external addresses from accessing your internal servers, it can’t work with this rule being #2, because all forwarded ports were allowed by rule #1 and rule #2 didn’t have a chance to do anything.