This article shows how to quickly set up RouterOS on MikroTik in a simple configuration that suits many small offices and home networks.
For example, we have an Internet connection and a local network of 5 computers, one of which is a server. Ordinary users need access over standard protocols (http, https, icq, jabber, ftp), the system administrator's workstation needs full network access, and the mail, ftp and web servers must work.
LAN IP addresses:
- Mikrotik - 192.168.0.1
- PC 5 - 192.168.0.2
- PC 4 - 192.168.0.10
- PC 1 - 192.168.0.20
- PC 2 - 192.168.0.21
- PC 3 - 192.168.0.22
Your provider may give you a public ("white") or a private ("gray") IP address. In this example it is a private address somewhere in the provider's local network.
Step 1. Connect to the router console locally, create a new user and disable the default “admin” account so it cannot be broken into.
[admin@MikroTik] > use add name=mkt password=P@S#w0Rd group=full [admin@MikroTik] > quit
Log in as the new user and disable admin.
[mkt@MikroTik] > user disable admin [mkt@MikroTik] > user print Flags: X - disabled # NAME GROUP ADDRESS 0 X;;; system default user admin full 0.0.0.0/0 1 mkt full 0.0.0.0/0
Step 2. Interface configuration.
There are two ways: use the setup wizard or configure the interfaces manually.
First, configure the interfaces with the wizard. Enter the command "setup".
[mkt@MikroTik] > setup Setup uses Safe Mode. It means that all changes that are made during setup are reverted in case of error, or if Ctrl-C is used to abort setup. To keep changes exit setup using the 'x' key. [Safe Mode taken] Choose options by pressing one of the letters in the left column, before dash. Pressing 'x' will exit current menu, pressing Enter key will select the entry that is marked by an '*'. You can abort setup at any time by pressing Ctrl-C. Entries marked by '+' are already configured. Entries marked by '-' cannot be used yet. Entries marked by 'X' cannot be used without installing additional packages. r - reset all router configuration + l - load interface driver + a - configure ip address and gateway d - setup dhcp client * s - setup dhcp server p - setup pppoe client t - setup pptp client x - exit menu your choice [press Enter to setup dhcp server]:
Press "a", then "a" again in the submenu, and enter the name of the first interface and its IP address.
+ a - add ip address + g - setup default gateway * x - exit menu your choice: a enable interface: ether1 ip address/netmask: 192.168.1.116/24 #Enabling interface /interface enable ether1 #Adding IP address /ip address add address=192.168.1.116/24 interface=ether1 comment="added by setup"
This will be the provider interface. Then add the second interface for the LAN and its address.
+ a - add ip address + g - setup default gateway * x - exit menu your choice: a enable interface: ether2 ip address/netmask: 192.168.0.1/24 #Enabling interface /interface enable ether2 #Adding IP address /ip address add address=192.168.0.1/24 interface=ether2 comment="added by setup"
Now set the default gateway: press "g" and enter the address.
your choice: g gateway: 192.168.1.249 #Adding default route /ip route add dst-address=0.0.0.0/0 gateway=192.168.1.249 comment="added by setup"
Exit the second-level menu (key "x") and then the first one (key "x"). The IP addresses and the default gateway are saved.
Now the second option: manual configuration.
View the list of available interfaces.
[mkt@MikroTik] > interface print Flags: D - dynamic, X - disabled, R - running, S - slave # NAME TYPE MTU 0 R ether1 ether 1500 1 R ether2 ether 1500
Enable interface 0, which connects to the provider, and assign it an IP address.
[mkt@MikroTik] > interface enable 0 [mkt@MikroTik] > ip address add address=192.168.1.116/24 interface=ether1 [mkt@MikroTik] > ip address print Flags: X - disabled, I - invalid, D - dynamic # ADDRESS NETWORK BROADCAST INTERFACE 0 192.168.1.116/24 192.168.1.0 192.168.1.255 ether1
Do the same for the local interface.
[mkt@MikroTik] > interface enable 1 [mkt@MikroTik] > ip address add address=192.168.0.1/24 interface=ether2 [mkt@MikroTik] > ip address print Flags: X - disabled, I - invalid, D - dynamic # ADDRESS NETWORK BROADCAST INTERFACE 0 192.168.1.116/24 192.168.1.0 192.168.1.255 ether1 1 192.168.0.1/24 192.168.0.0 192.168.0.255 ether2
Finally add the default gateway.
[mkt@MikroTik] > ip route add gateway=192.168.1.249 [mkt@MikroTik] > ip route print Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, B - blackhole, U - unreachable, P - prohibit # DST-ADDRESS PREF-SRC GATEWAY DISTANCE 0 A S 0.0.0.0/0 192.168.1.249 r... 1 1 ADC 192.168.0.0/24 192.168.0.1 ether2 0 2 ADC 192.168.1.0/24 192.168.1.116 ether1 0
You could continue in the graphical tool “winbox”, but since we started in the console, we will finish there and then repeat everything from step 3 onwards in the graphical interface.
Step 3. DNS Configuration.
[mkt@MikroTik] > ip dns set primary-dns=208.67.222.222 secondary-dns=208.67.220.220 allow-remote-requests=yes [mkt@MikroTik] > ip dns print primary-dns: 208.67.222.222 secondary-dns: 208.67.220.220 allow-remote-requests: yes max-udp-packet-size: 512 cache-size: 2048KiB cache-max-ttl: 1w cache-used: 5KiB
Step 4. Setting up access to the Internet.
First, turn on masquerading.
[mkt@MikroTik] > ip firewall nat add chain=srcnat action=masquerade out-interface=!ether2
Add rules for service packets.
[mkt@MikroTik] > ip firewall filter add chain=forward connection-state=invalid action=drop comment="Drop invalid connection packets" [mkt@MikroTik] > ip firewall filter add chain=forward connection-state=established action=accept comment="Allow established connections" [mkt@MikroTik] > ip firewall filter add chain=forward connection-state=related action=accept comment="Allow related connections" [mkt@MikroTik] > ip firewall filter add chain=forward protocol=udp action=accept comment="Allow UDP" [mkt@MikroTik] > ip firewall filter add chain forward protocol=icmp action=accept comment="Allow ICMP Ping"
Then add the rules for machine PC4.
[mkt@MikroTik] > ip firewall filter add chain=forward dst-address=192.168.0.2/32 protocol=tcp src-port=80 action=accept comment="Allow http for server (in)" [mkt@MikroTik] > ip firewall filter add chain=forward src-address=192.168.0.2/32 protocol=tcp dst-port=80 action=accept comment="Allow http for server (out)" [mkt@MikroTik] > ip firewall filter add chain=forward dst-address=192.168.0.2/32 protocol=tcp src-port=25 action=accept comment="Allow smtp for server (in)" [mkt@MikroTik] > ip firewall filter add chain=forward src-address=192.168.0.2/32 protocol=tcp dst-port=25 action=accept comment="Allow smtp for server (out)" [mkt@MikroTik] > ip firewall filter add chain=forward dst-address=192.168.0.2/32 protocol=tcp src-port=110 action=accept comment="Allow pop for server (in)" [mkt@MikroTik] > ip firewall filter add chain=forward src-address=192.168.0.2/32 protocol=tcp dst-port=110 action=accept comment="Allow pop for server (out)"
In the same way we set the rules for other machines, allowing them http, https, ftp, icq, jabber.
[mkt@MikroTik] > ip firewall filter add chain=forward dst-address=192.168.0.20/32 protocol=tcp src-port=80 action=accept comment="Allow http for pc1 (in)" [mkt@MikroTik] > ip firewall filter add chain=forward src-address=192.168.0.20/32 protocol=tcp dst-port=80 action=accept comment="Allow http for pc1 (out)" [mkt@MikroTik] > ip firewall filter add chain=forward dst-address=192.168.0.20/32 protocol=tcp src-port=443 action=accept comment="Allow https for pc1 (in)" [mkt@MikroTik] > ip firewall filter add chain=forward src-address=192.168.0.20/32 protocol=tcp dst-port=443 action=accept comment="Allow https for pc1 (out)" [mkt@MikroTik] > ip firewall filter add chain=forward dst-address=192.168.0.20/32 protocol=tcp src-port=21 action=accept comment="Allow ftp for pc1 (in)" [mkt@MikroTik] > ip firewall filter add chain=forward src-address=192.168.0.20/32 protocol=tcp dst-port=21 action=accept comment="Allow ftp for pc1 (out)" [mkt@MikroTik] > ip firewall filter add chain=forward dst-address=192.168.0.20/32 protocol=tcp src-port=5190 action=accept comment="Allow icq for pc1 (in)" [mkt@MikroTik] > ip firewall filter add chain=forward src-address=192.168.0.20/32 protocol=tcp dst-port=5190 action=accept comment="Allow icq for pc1 (out)" [mkt@MikroTik] > ip firewall filter add chain=forward dst-address=192.168.0.20/32 protocol=tcp src-port=5222 action=accept comment="Allow jabber for pc1 (in)" [mkt@MikroTik] > ip firewall filter add chain=forward src-address=192.168.0.20/32 protocol=tcp dst-port=5222 action=accept comment="Allow jabber for pc1 (out)"
Repeat these rules for each machine, using them as a template.
Finally, block everything that was not allowed above.
[mkt@MikroTik] > ip firewall filter add chain=forward action=drop comment="Drop all"
Step 5. Incoming connections.
Now forward incoming http, smtp and pop connections to the server automatically.
[mkt@MikroTik] > ip firewall nat add chain=dstnat dst-address=192.168.1.116/32 protocol=tcp dst-port=80 action=dst-nat to-addresses=192.168.0.2 to-ports=80 comment="NAT for http" [mkt@MikroTik] > ip firewall nat add chain=dstnat dst-address=192.168.1.116/32 protocol=tcp dst-port=25 action=dst-nat to-addresses=192.168.0.2 to-ports=25 comment="NAT for smtp" [mkt@MikroTik] > ip firewall nat add chain=dstnat dst-address=192.168.1.116/32 protocol=tcp dst-port=110 action=dst-nat to-addresses=192.168.0.2 to-ports=110 comment="NAT for pop"
That is all for a minimal, simple setup. What we did:
- Two interfaces, ether1 and ether2, were enabled.
- IP addresses were assigned to the interfaces.
- Default gateway was set.
- DNS server was specified.
- Rules were added for machines with unlimited access.
- Rules were added for machines with access limited to certain ports.
- NAT rules were added for access from outside to the web and mail servers.
Now let's go back to step 3 and do the same in the graphical tool “winbox”. To download it, open the MikroTik web interface (“webbox”) and download the program from its start page.
Start it and enter the LAN address assigned to the second interface, and the user name and password created at the beginning.
Step 3. DNS configuration.
The GUI is not much harder than the console. In the main menu select “IP”, then the “DNS” submenu.
Here you can add static DNS entries and see what is in the cache now. Click “Settings” and enter the DNS server addresses.
Step 4. Setting up access to the Internet.
Turn on masquerading: main menu “IP”, submenu “Firewall”, tab “NAT”.
Click the plus sign to add a new entry. The rest is the same as in the console: on the “General” tab set chain = srcnat and “Out interface = ether2” with the box ticked, which means "NOT", then on the “Action” tab select “masquerade”.
In the main menu select “IP”, then “Firewall”, and in the window that opens select the “Filter Rules” tab. Click the plus sign to add a new rule.
Allow UDP
Allow outgoing TCP connections from 192.168.0.2 to any address on destination port 25.
Finally, block everything that was not allowed above.
Step 5. Incoming connections.
In the main menu select “IP”, then “Firewall”, and in the window that opens select the “NAT” tab. Click the plus sign to add a new rule.
Redirect all TCP connections that arrive at the external address 192.168.1.116, port 25, to the local address 192.168.0.2, port 25.
All the other rules are built the same way.
As you can see, every action can be done in at least two ways: with text commands in the console or with the mouse in the GUI. Both have their pros and cons.
The console works faster, even over a very slow link. The graphical tool downloads its interface modules before it starts and then generates a lot of traffic while you work.
The console is harder to learn, but once you understand the commands and how they work, it no longer matters much which interface you use.