Mikrotik CLI
Mikrotik CLI
Mikrotik command actually almost the same as the existing command linux, mikrotik
because basically this is a Linux kernel, the result of processing back from the Debian
distribution of Linux. Use the same command shell, such as saving the command, simply use
the TAB key on the keyboard then a long command, no longer need to be typed, simply type
the beginning of the command is called, will automatically display the Shell will own
commands respect. For example IP ADDRESS command in mikrotik. Enough just type in
the IP ADD spaced press the TAB key, then the automatic shell will recognize and translate
the IP ADDRESS command.
Let us continue with the introduction of this command.
untuk melihat semua list perintah anda bisa ketik ? dan hasil nya akan muncul seperti di
bawah ini
[admin@MikroTik] > ?
beep -blink -certificate -- Certificate management
delay -- does nothing for a while
do -- executes command
driver -- Driver management
environment -- list of all variables
error -- make error value
execute -- run script as separate console job
file -- Local router file storage.
find -- Find items by value
for -- executes command for a range of integer values
foreach -- executes command for every element in a list
global -- set value global variable
if -- executes command if condition is true
import -interface -ip -- IP options
a. Renaming interface
[Admin @ MikroTik]> interface (enter)
b. To rename a Public Interface ether1 (or whatever his name), then
[Admin @ MikroTik] interface> set 0 name = Public
c. Likewise for ether2, say his name changed to Local, then
[Admin @ MikroTik] interface> set 1 name = Local
d. or just from the position of the root directory, use the sign "/", without quotes
[Admin @ MikroTik]> / interface set 0 name = Public
e. Check again if the interface name had been changed.
[Admin @ MikroTik]> / interface print
Flags: X - disabled, D - dynamic, R - running
# NAME TYPE RX-RATE TX-RATE MTU
0 R Local ether 0 0 1500
1 R Public ether 0 0 1500
2. - Change the default password
To change the default password security
[Admin @ Mikrotik]> password
old password: *****
New password: *****
Retype new password: *****
[Admin @ Mikrotik]]>
3. - Renaming hostname
Renaming Mikrotik Router for easy configuration, in this step
server name will be changed to "myrouter"
[Admin @ MikroTik]> system identity set name = myrouter
[Admin @ myrouter]>
4. - Setting the IP Address, Gateway, and Name Server Masqureade
- [4.1] - IP Address
Order form configuration
ip address add address = {ip address / netmask} interfaces = {interface name}
a. Provides the IP address on the interface Mikrotik. Public suppose we will use to
connection to the Internet with IP 192.168.1.2 and the Local will be used for the LAN network
us with the IP 192.168.0.30 (See topology)
[Admin @ myrouter]> ip address add address = 192.168.1.2 \
netmask = 255.255.255.0 interface = Public comment = "IP to the Internet"
[Admin @ myrouter]> ip address add address = 192.168.0.30 \
netmask = 255 255 255 224 interface = Local comment = "IP to the LAN"
b. Viewing the IP address configuration we have given
[Admin @ myrouter]> ip address print
Flags: X - disabled, I - invalid, D - dynamic
# ADDRESS NETWORK BROADCAST INTERFACE
Command
/ Ip web-proxy print {to see the results of a web-proxy configuration}
/ Ip web-proxy monitor for monitoring the work {web-proxy}
7. - Bandwidth Management
QoS plays an important role in terms of providing services good on the client. For that we
need the bandwidth management for each data set is passed, so the division of bandwidth
into fair. In this case also includes a packet RouterOS software for memanagement
bandwidth.
Form of configuration commands:
queue simple add name = {name}
target-addresses = {ip address of the destination}
interfaces = {interface used to pass data}
max-limit = {out / in}
Below there is a configuration of traffic shaping or bandwidth management with Simple
Queue method, as the name implies, this type of queue is simple, but has a weakness,
sometimes leak bandwidth or bandwidth is not real in the monitor. Usage for 10 clients,
Queue type is not a problem.
Client is assumed there are as many as 15 clients, and each client was given ration of 8kbps
minimum bandwidth, and a maximum of 48kbps. Whereas Total bandwidth of 192Kbps. For
the upstream is not given a rule, means each client can use the bandwidth uptream
maximum. Note the priority command, the range of priority in Mikrotik eight. Means from 1
to 8, priority 1 is highest priority, while priority 8 is the lowest priority.
The following example kongirufasinya.
--------------------------/ Queue simple
add name = "trafikshaping" target-addresses = 192.168.0.0/27 dst-address = 0.0.0.0 / 0 \
interface = all parent = none priority = 1 queue = default / default \
limit-at = 0 / 64 000 max-limit = 0 / 192 000 total-queue = default disabled = no
add name = "01" target-addresses = 192.168.0.1/32 dst-address = 0.0.0.0 / 0 \
interface = all parent = trafikshaping priority = 1 queue = default / default \
limit-at = 0 / 8000 max-limit = 0 / 48000 total-queue = default disabled = no
add name = "02" target-addresses = 192.168.0.2/32 dst-address = 0.0.0.0 / 0 \
interface = all parent = trafikshaping priority = 1 queue = default / default \
limit-at = 0 / 8000 max-limit = 0 / 48000 total-queue = default disabled = no
add name = "03" target-addresses = 192.168.0.3/32 dst-address = 0.0.0.0 / 0 \
interface = all parent = trafikshaping priority = 1 queue = default / default \
limit-at = 0 / 8000 max-limit = 0 / 48000 total-queue = default disabled = no
add name = "04" target-addresses = 192.168.0.4/32 dst-address = 0.0.0.0 / 0 \
interface = all parent = trafikshaping priority = 1 queue = default / default \
limit-at = 0 / 8000 max-limit = 0 / 48000 total-queue = default disabled = no
add name = "10" target-addresses = 192.168.0.25/32 dst-address = 0.0.0.0 / 0 \
interface = all parent = trafikshaping priority = 1 queue = default / default \
limit-at = 0 / 8000 max-limit = 0 / 48000 total-queue = default disabled = no
add name = "05" target-addresses = 192.168.0.5/32 dst-address = 0.0.0.0 / 0 \
interface = all parent = trafikshaping priority = 1 queue = default / default \
limit-at = 0 / 8000 max-limit = 0 / 48000 total-queue = default disabled = no
add name = "06" target-addresses = 192.168.0.6/32 dst-address = 0.0.0.0 / 0 \
interface = all parent = trafikshaping priority = 1 queue = default / default \
limit-at = 0 / 8000 max-limit = 0 / 48000 total-queue = default disabled = no
add name = "07" target-addresses = 192.168.0.7/32 dst-address = 0.0.0.0 / 0 \
The command above because in the form of the command line, can also copy paste, then
paste it into the consol mikrotiknya. remember see first path or active directory. Please
dipaste course, if the position
direktorynya in Root.
----------------------Terminal vt102 detected, using multiline input mode
[Admin @ MikroTik]>
---------------------Another option is the method of bandwidth management, if if wanted bandwidth is shared
equally by Mikrotik, such as bandwidth 256kbps downstream and 256kbps upstream. While
the client will
access as many as 10 clients, each client automatically gets a small upstream and
downstream bandwidth of 256kbps divided by 10. So each one can be 25.6 kbps. If only 2
Client who access it each can be 128kbps.
For that type used PCQ (Per Connection Queue), which can be automatically divide the traffic
per client. About the type of queue in mikrotik This can be read on the manual in
http://www.mikrotik.com/testdocs/
ros/2.9/root/queue.php.
Previously need to be made a rule in the mangle. Such as:
----------------------/ Ip firewall mangle add chain = forward src-address = 192.168.0.0/27 \
action = mark-connection new-connection-mark = users-con
/ Ip firewall mangle add connection-mark = users-con action = mark-packet \
new-packet-mark = users chain = forward
------------------------
Because type PCQ does not exist, then it needs to be added, there are two types of this PCQ.
First named pcq-download, which will regulate all traffic through the destination address /
destination address. Traffic is passing Local interface. So that all traffic download /
downstream coming from the network 192.168.0.0/27 will be shared automatically.
PCQ second type, called pcq-upload, to regulate all upstream traffic derived from the source
address / source address. Traffic is passing public interface. So that all traffic upload /
upstream originating from the network 192.168.0.0/27 will be shared automatically.
Command:
------------------------/ Queue type add name = pcq-download kind = pcq pcq-classifier = dst-address
/ Queue type add name = pcq-upload kind = pcq pcq-classifier = src-address
------------------------Once the rules for the PCQ and Mangle added, now for the rules traffic division. Queue
Queue Tree is used, ie:
------------------------/ Queue tree add parent = Local queue = pcq-download packet-mark = users
/ Queue tree add parent = Public queue = pcq-upload packet-mark = users
------------------------The command above assumes that if the bandwidth received from the provider Internet
berflukstuasi or changing. If we believe that the bandwidth received, for example can
256kbs downstream, and 256kbps upstream, then No more rules, such as:
For downstream traffic:
-----------------------/ Queue tree add name = Download parent = Local max-limit = 256k
/ Queue tree add parent = Download queue = pcq-download packet-mark = users
------------------------And upstream traffic:
------------------------/ Queue tree add name = Upload parent = Public max-limit = 256k
/ Queue tree add parent = Upload queue = pcq-upload packet-mark = users
------------------------8. - MRTG Monitor via Web
This facility is necessary for monitoring traffic in the form of graphs, can viewed using a
browser. MRTG (The Multi Router Traffic Grapher) has dibuild such a way that allows us to
use it. Already available packaged basically.
Example configuration
------------------------/ Tool graphing
set store-every = 5min
/ Tool graphing interface
add interface = all allow-address = 0.0.0.0 / 0 store-on-disk = yes disabled = no
------------------------The above command will display a graph of the traffic that passes through the interface
good network of Public Interface and Local Interface, which rendered every 5 minutes.
Addresses can also be set anything that can access MRTG is, the allow-address parameter.
9. - Security in Mikrotik
After some configuration above has been prepared, of course not forgetting our consider the
security of this mikrotik gateway machine, there are few facilities used. In this case will be
discussed on the firewall. Facilities
The underlying this firewall is similar to IP TABLES on Gnu / Linux only some commands have
been simplified but efficient.
In Mikrotik firewall command is contained in IP mode, ie
[Admin @ myrouter]> / ip firewall
There are several packet filters like mangle, nat, and filters.
------------------------[Admin @ myrouter] ip firewall>?
Firewall allows IP packet filtering on per packet basis.
.. - Go up to the ip
mangle / - The packet marking management
nat / - Network Address Translation
connection / - Active Connections
filter / - Firewall filters
address-list / service-port / - Service port management
export ------------------------For this time we will see the ip firewall filter configuration.
Because the breadth of the firewall filter parameters for the discussion of Firewall Filters can
be seen in the manual mikrotik, in http://www.mikrotik.com/testdocs/ros/2.9/ip/filter.php
Configuration below can block some of the Trojan, Virus, Backdoor which have been
identified previously used either Port Numbers and Protocols. It has also been configured to
withstand the flooding of the Network and Public Local network. As well as providing rules for
access control in order, Range only certain tissues that can perform remote or access the
service Mikrotik specific to our machine.
Sample Application filter
-------------------------/ Ip firewall filter
add chain = input connection-state = invalid action = drop comment = "Drop Invalid \
connections "disabled = no
add chain = input src-address =! 192.168.0.0/27 protocol = tcp src-port = 1024-65535 \
dst-port = 8080 action = drop comment = "Block to Proxy" disabled = no
add chain = input protocol = udp dst-port = 12667 action = drop comment = "trinoo" \
disabled = no
add chain = input protocol = udp dst-port = 27665 action = drop comment = "trinoo" \
disabled = no
add chain = input protocol = udp dst-port = 31335 action = drop comment = "trinoo" \
disabled = no
add chain = input protocol = udp dst-port = 27444 action = drop comment = "trinoo" \
disabled = no
add chain = input protocol = udp dst-port = 34555 action = drop comment = "trinoo" \
disabled = no
add chain = input protocol = udp dst-port = 35555 action = drop comment = "trinoo" \
disabled = no
add chain = input protocol = tcp dst-port = 27444 action = drop comment = "trinoo" \
disabled = no
add chain = input protocol = tcp dst-port = 27665 action = drop comment = "trinoo" \
disabled = no
add chain = input protocol = tcp dst-port = 31335 action = drop comment = "trinoo" \
disabled = no
add chain = input protocol = tcp dst-port = 31846 action = drop comment = "trinoo" \
disabled = no
add chain = input protocol = tcp dst-port = 34555 action = drop comment = "trinoo" \
disabled = no
add chain = input protocol = tcp dst-port = 35555 action = drop comment = "trinoo" \
disabled = no
add chain = input connection-state = established action = accept comment = "Allow \
Established connections "disabled = no
add chain = input protocol = udp action = accept comment = "Allow UDP" disabled = no
add chain = input protocol = icmp action = accept comment = "Allow ICMP" disabled = no
add chain = input src-address = 192.168.0.0/27 action = accept comment = "Allow access \
to router from known network "disabled = no
add chain = input action = drop comment = "Drop anything else" disabled = no
add chain = forward protocol = tcp connection-state = invalid action = drop \
comment = "drop invalid connections" disabled = no
add chain = forward connection-state = established action = accept comment = "allow \
already established connections "disabled = no
add chain = forward connection-state = related action = accept comment = "allow \
related connections "disabled = no
add chain = forward src-address = 0.0.0.0 / 8 action = drop comment = "" disabled = no
add chain = forward dst-address = 0.0.0.0 / 8 action = drop comment = "" disabled = no
add chain = forward src-address = 127.0.0.0 / 8 action = drop comment = "" disabled = no
add chain = forward dst-address = 127.0.0.0 / 8 action = drop comment = "" disabled = no
add chain = forward src-address = 224.0.0.0 / 3 action = drop comment = "" disabled = no
add chain = forward dst-address = 224.0.0.0 / 3 action = drop comment = "" disabled = no
add chain = forward protocol = tcp action = jump jump-target = tcp comment = "" \
disabled = no
add chain = forward protocol = udp action = jump jump-target = udp comment = "" \
disabled = no
add chain = forward protocol = icmp action = jump jump-target = icmp comment = "" \
disabled = no
add chain = tcp protocol = tcp dst-port = 69 action = drop comment = "deny TFTP" \
disabled = no
add chain = tcp protocol = tcp dst-port = 111 action = drop comment = "deny RPC \
portmapper "disabled = no
add chain = tcp protocol = tcp dst-port = 135 action = drop comment = "deny RPC \
portmapper "disabled = no
add chain = tcp protocol = tcp dst-port = 137-139 action = drop comment = "deny NBT" \
disabled = no
add chain = tcp protocol = tcp dst-port = 445 action = drop comment = "deny cifs" \
disabled = no
add chain = tcp protocol = tcp dst-port = 2049 action = drop comment = "deny NFS" \
disabled = no
add chain = tcp protocol = tcp dst-port = 12345-12346 action = drop comment = "deny \
NetBus "disabled = no
add chain = tcp protocol = tcp dst-port = 20034 action = drop comment = "deny NetBus" \
disabled = no
add chain = tcp protocol = tcp dst-port = 3133 action = drop comment = "deny \
BackOriffice "disabled = no
add chain = tcp protocol = tcp dst-port = 67-68 action = drop comment = "deny DHCP" \
disabled = no
add chain = udp protocol = udp dst-port = 69 action = drop comment = "deny TFTP" \
disabled = no
add chain = udp protocol = udp dst-port = 111 action = drop comment = "deny PRC \
portmapper "disabled = no
add chain = udp protocol = udp dst-port = 135 action = drop comment = "deny PRC \
portmapper "disabled = no
add chain = udp protocol = udp dst-port = 137-139 action = drop comment = "deny NBT" \
disabled = no
add chain = udp protocol = udp dst-port = 2049 action = drop comment = "deny NFS" \
disabled = no
add chain = udp protocol = udp dst-port = 3133 action = drop comment = "deny \
BackOriffice "disabled = no
add chain = input protocol = tcp psd = 21.3 s, 3.1 action = add-src-to-address-list \
address-list = "port scanners" address-list-timeout = 2w comment = "Port \
scanners to list "disabled = no
add chain = input protocol = tcp tcp-flags = fin,! syn,! rst,! PSH,! ack,! URG \
action = add-src-to-address-list address-list = "port scanners" \
address-list-timeout = 2w comment = "NMAP FIN Stealth scan" disabled = no
add chain = input protocol = tcp tcp-flags = fin, syn action = add-src-to-address-list \
address-list = "port scanners" address-list-timeout = 2w comment = "SYN / FIN \
scan "disabled = no
add chain = input protocol = tcp tcp-flags = syn, rst action = add-src-to-address-list \
address-list = "port scanners" address-list-timeout = 2w comment = "SYN / RST \
scan "disabled = no
add chain = input protocol = tcp tcp-flags = FIN, PSH, URG,! syn,! rst,! ack \
action = add-src-to-address-list address-list = "port scanners" \
address-list-timeout = 2w comment = "FIN / PSH / URG scan" disabled = no
add chain = input protocol = tcp tcp-flags = fin, syn, rst, PSH, ACK, URG \
action = add-src-to-address-list address-list = "port scanners" \
address-list-timeout = 2w comment = "ALL / ALL scan" disabled = no
add chain = input protocol = tcp tcp-flags =! fin,! syn,! rst,! PSH,! ack,! URG \
action = add-src-to-address-list address-list = "port scanners" \
address-list-timeout = 2w comment = "NMAP NULL scan" disabled = no
add chain = input src-address-list = "port scanners" action = drop comment = "dropping \
port scanners "disabled = no
add chain = icmp protocol = icmp icmp-options = 0:0 action = accept comment = "drop \
invalid connections "disabled = no
add chain = icmp protocol = icmp icmp-options = 3:0 action = accept comment = "allow \
established connections "disabled = no
add chain = icmp protocol = icmp icmp-options = 3:1 action = accept comment = "allow \
already established connections "disabled = no
add chain = icmp protocol = icmp icmp-options = 4:0 action = accept comment = "allow \
source quench "disabled = no
add chain = icmp protocol = icmp icmp-options = 8:0 action = accept comment = "allow \
echo request "disabled = no
add chain = icmp protocol = icmp icmp-options = 11:0 action = accept comment = "allow \
time exceed "disabled = no
add chain = icmp protocol = icmp icmp-options = 12:0 action = accept comment = "allow \
parameter bad "disabled = no
add chain = icmp action = drop comment = "deny all other types" disabled = no
add chain = tcp protocol = tcp dst-port = 25 action = reject \
reject-with = icmp-network-unreachable comment = "smtp" disabled = no
add chain = tcp protocol = udp dst-port = 25 action = reject \
reject-with = icmp-network-unreachable comment = "smtp" disabled = no
add chain = tcp protocol = tcp dst-port = 110 action = reject \
reject-with = icmp-network-unreachable comment = "smtp" disabled = no
add chain = tcp protocol = udp dst-port = 110 action = reject \
reject-with = icmp-network-unreachable comment = "smtp" disabled = no
add chain = tcp protocol = udp dst-port = 110 action = reject \
reject-with = icmp-network-unreachable comment = "smtp" disabled = no
-------------------------- [10/01] - Service and Viewing the Active Service with PortScanner
To ensure that any active service in Machine mikrotik, we need to scan to a specific port, if
there are services that are not needed, better off alone.
To disable and enable servise, the command is:
We verify what services are active
---------------------------[Admin @ myrouter]> ip service
[Admin @ myrouter] ip service> print
Flags: X - disabled, I - invalid
# NAME PORT ADDRESS CERTIFICATE
X 0 telnet 23 0.0.0.0 / 0
1 ftp 21 0.0.0.0 / 0
2 www 80 0.0.0.0 / 0
3 ssh 22 0.0.0.0 / 0
4 www-ssl 443 0.0.0.0 / 0 none
[Admin @ myrouter]ip service>
---------------------------Suppose the FTP service is disabled, ie in the above list is located at
number 1 (see Flags) then:
--------------------------[Admin @ myrouter] ip service> set 1 disabled = yes
--------------------------We need to check again,
--------------------------[Admin @ myrouter] ip service> print
Flags: X - disabled, I - invalid
# NAME PORT ADDRESS CERTIFICATE
X 0 telnet 23 0.0.0.0 / 0
1 X ftp 21 0.0.0.0 / 0
2 www 80 0.0.0.0 / 0
3 ssh 22 0.0.0.0 / 0
4 www-ssl 443 0.0.0.0 / 0 none
[Admin@myrouter] ip service>
--------------------------Now the FTP service has been disabled.
Using nmap tool we can check what ports are active on the machine
gateway has been configured.
Command: nmap-vv-sS-sV-P0 192.168.0.30
Results:
----------------------------Starting Nmap 4.20 (http://insecure.org) at 2007-04-04 19:55 SE Asia Standard Time
Initiating ARP Ping Scan at 19:55
Scanning 192.168.0.30 [1 port]
SF: 1 \ n \ xf6 \ x9b \ xa0, \ xb0 \ xe1 \ xa5 ")% r (NessusTPv10, 4," \ x01 ");
MAC Address: 00:90:4 C: 91:77:02 (Epigram)
Service Info: Host: myrouter; Device: router
Service detection performed. Please report any incorrect results at
http://insecure.org/nmap/submit/.
Nmap finished: 1 IP address (1 host up) scanned in 123 031 seconds
Raw packets sent: 1706 (75.062KB) | rcvd: 1722 (79.450KB)
------------------------From the results of such scanning can we take the conclusion, that the service and active
port is a FTP version of the MikroTik router ftpd 2.9.27. To SSH with OpenSSH version 2.3.0
mikrotik 2.9.27 (protocol 1.99). And the Web use the Squid proxy in Squid version webproxy
2.5.STABLE11.
Of course, the vendor has to patch against mikrotik Hole or Vulnerabilities of the above
Protocol Version.
- [10/02] - Network Administration Tool
Practically speaking, there are some tools that can be utilized in mela do network
troubleshooting, such as tools ping, traceroute, ssh, etc.. Some tools are often used later in
the day-to-day administration
are:
o
o
o
o
Telnet
SSH
Traceroute
Sniffer
a. Telnet
Remote commands are almost the same machine with the use of the existing telnet
on Linux or Windows.
[Admin @myrouter]> system telnet?
Sekilias above command to see what parameters are there. For example
remote machine with IP address 192.168.0.21 and port 23. Then
[Admin @ myrouter]> system telnet 192.168.0.21
Use of telnet should be limited to certain conditions for reasons security, as we know, a
packet of data sent via telnet has not been encrypted. To be more safe we use SSH.
b. SSH
Together with the telnet command is also needed in the remote machine, and principle same
parameters with the command on Linux and Windows.
[Admin @myrouter]> system ssh 192.168.0.21
SSH parameters above, a slight difference with telnet. If you see helpnya
has an additional parameter of the user.
-------------------------[Admin @ myrouter]> ssh system?
The SSH feature can be used with Various SSH Telnet clients to securely connect