The console is used for accessing the MikroTik Router's configuration and management features using text terminals, either remotely using serial port, telnet, SSH, console screen within WinBox, or directly using monitor and keyboard. The console is also used for writing scripts. This manual describes the general console operation principles. Please consult the Scripting Manual on some advanced console commands and on how to write scripts.
Console login options enables or disables various console features like colour, terminal detection and many other.
Additional login parameters can be appended to login name after '+' sign.
login_name ::= user_name [ '+' parameters ] parameters ::= parameter [ parameters ] parameter ::= [ number ] 'a'..'z' number ::= '0'..'9' [ number ]
If parameter is not present, then default value is used. If number is not present then implicit value of parameter is used.
Example: admin+c80w - will disable console colours and set terminal width to 80.
|"w"||auto||auto||Set terminal width|
|"h"||auto||auto||Set terminal height|
|"c"||on||off||disable/enable console colours|
|"t"||on||off||Do auto detection of terminal capabilities|
|"e"||on||off||Enables "dumb" terminal mode|
Banner and Messages
Login process will display MikroTik banner and short help after validating user name and password.
After the banner can be printed other important information, like system note set by another admin, last few critical log messages, demo version upgrade reminder and default configuration description.
For example, demo license prompt and last critical messages are printed
At the end of successful login sequence login process prints banner, shows command prompt and hands over control to the user.
Default command prompt, consists of user name, system identity, and current command path />
For example, change current path from root to interface then go back to root
Use up arrow to recall previous commands from command history, TAB key to automatically complete words in the command you are typing, ENTER key to execute the command, Control-C to interrupt currently running command and return to prompt and ? to display built-in help.
The easiest way to log out of console is to press Control-D at the command prompt while the command line is empty (You can cancel current command and get an empty line with Control-C, so Control-C followed by Control-D will log you out in most cases).
It is possible to write commands that consist of multiple lines. When entered line is not a complete command and more input is expected, console shows continuation prompt that lists all open parentheses, braces, brackets and quotes, and also trailing backslash if the previous line ended with backslash-white-space.
When you are editing such multiple line entry, prompt shows number of current line and total line count instead of usual username and system name.
line 2 of 3> :put (\
Sometimes commands ask for additional input from the user. For example, command '
/password' asks for old and new passwords. In such cases prompt shows name of requested value, followed by colon and space.
The console allows configuration of the router's settings using text commands. Since there is a lot of available commands, they are split into groups organized in a way of hierarchical menu levels. The name of a menu level reflects the configuration information accessible in the relevant section.
For example, you can issue the
/ip route print command:
Instead of typing `/ip route` path before each command, the path can be typed only once to move into this particular branch of menu hierarchy. Thus, the example above could also be executed like this:
Each word in the path can be separated by space (as in example above) or by "/"
Notice that the prompt changes in order to reflect where you are located in the menu hierarchy at the moment. To move to the top level again, type " / "
To move up one command level, type " .. "
You can also use / and .. to execute commands from other menu levels without changing the current level:
Item Names and Numbers
Many of the command levels operate with arrays of items: interfaces, routes, users etc. Such arrays are displayed in similarly looking lists. All items in the list have an item number followed by flags and parameter values.
To change properties of an item, you have to use set command and specify name or number of the item.
Some lists have items with specific names assigned to each of them. Examples are interface or user levels. There you can use item names instead of item numbers.
You do not have to use the print command before accessing items by their names, which, as opposed to numbers, are not assigned by the console internally, but are properties of the items. Thus, they would not change on their own. However, there are all kinds of obscure situations possible when several users are changing router's configuration at the same time. Generally, item names are more "stable" than the numbers, and also more informative, so you should prefer them to numbers when writing console scripts.
Item numbers are assigned by the print command and are not constant - it is possible that two successive print commands will order items differently. But the results of last print commands are memorized and, thus, once assigned, item numbers can be used even after add, remove and move operations (since version 3, move operation does not renumber items). Item numbers are assigned on a per session basis, they will remain the same until you quit the console or until the next print command is executed. Also, numbers are assigned separately for every item list, so
ip address print will not change numbering of the interface list.
You can specify multiple items as targets to some commands. Almost everywhere, where you can write the number of item, you can also write a list of numbers.
There are some commands that are common to nearly all menu levels, namely: print, set, remove, add, find, get, export, enable, disable, comment, move. These commands have similar behavior throughout different menu levels.
|add||This command usually has all the same arguments as set, except the item number argument. It adds a new item with the values you have specified, usually at the end of the item list, in places where the order of items is relevant. There are some required properties that you have to supply, such as the interface for a new address, while other properties are set to defaults unless you explicitly specify them.|
|edit||This command is associated with the set command. It can be used to edit values of properties that contain large amount of text, such as scripts, but it works with all editable properties. Depending on the capabilities of the terminal, either a full-screen editor, or a single line editor is launched to edit the value of the specified property.|
|find||The find command has the same arguments as set, plus the flag arguments like disabled or active that take values yes or no depending on the value of respective flag. To see all flags and their names, look at the top of print command's output. The find command returns internal numbers of all items that have the same values of arguments as specified.|
|move||Changes the order of items in list. Parameters:|
|hows all information that\'s accessible from particular command level. Thus, |
|remove||Removes specified item(-s) from a list.|
|set||Allows you to change values of general parameters or item parameters. The set command has arguments with names corresponding to values you can change. Use ? or double Tab to see list of all arguments. If there is a list of items in this command level, then set has one action argument that accepts the number of item (or list of numbers) you wish to set up. This command does not return anything.|
It is possible to switch between several input modes:
- Normal mode - indicated by normal command prompt.
- Safe mode - safe mode is indicated by a word SAFE after command prompt. In this mode configuration is saved to disk only after safe mode is turned off. Safe mode can bet turned on/off with Ctrl+c. Read more >>
- Hot-lock mode - indicated by additional yellow >. Hot-lock mode auto completes commands and can be turned on/off with Ctrl+v
There are two features in the console that help entering commands much quicker and easier - the [Tab] key completions, and abbreviations of command names. Completions work similarly to the bash shell in UNIX. If you press the [Tab] key after a part of a word, console tries to find the command within the current context that begins with this word. If there is only one match, it is automatically appended, followed by a space:
/inte[Tab]_ becomes /interface _
If there is more than one match, but they all have a common beginning, which is longer than that what you have typed, then the word is completed to this common part, and no space is appended:
/interface set e[Tab]_ becomes /interface set ether_
If you've typed just the common part, pressing the tab key once has no effect. However, pressing it for the second time shows all possible completions in compact form:
[admin@MikroTik] > interface set e[Tab]_ [admin@MikroTik] > interface set ether[Tab]_ [admin@MikroTik] > interface set ether[Tab]_ ether1 ether5 [admin@MikroTik] > interface set ether_
The [Tab] key can be used almost in any context where the console might have a clue about possible values - command names, argument names, arguments that have only several possible values (like names of items in some lists or name of protocol in firewall and NAT rules). You cannot complete numbers, IP addresses and similar values.
Another way to press fewer keys while typing is to abbreviate command and argument names. You can type only beginning of command name, and, if it is not ambiguous, console will accept it as a full name. So typing:
[admin@MikroTik] > pi 10.1 c 3 si 100
[admin@MikroTik] > ping 10.0.0.1 count 3 size 100
It is possible to complete not only beginning, but also any distinctive sub-string of a name: if there is no exact match, console starts looking for words that have string being completed as first letters of a multiple word name, or that simply contain letters of this string in the same order. If single such word is found, it is completed at cursor position. For example:
[admin@MikroTik] > interface x[TAB]_ [admin@MikroTik] > interface export _ [admin@MikroTik] > interface mt[TAB]_ [admin@MikroTik] > interface monitor-traffic _
List of Keys
|Control-D||log out (if input line is empty)|
|Control-K||clear from cursor to the end of line|
|Control-X||toggle safe mode|
|Control-V||toggle hotlock mode mode|
|F1 or ?||show context sensitive help. If the previous character is \, then inserts literal ?.|
|Tab||perform line completion. When pressed second time, show possible completions.|
|Delete||remove character at cursor|
|Control-H or Backspace||remove character before cursor and move cursor back one position.|
|Control-\||split line at cursor. Insert newline at cursor position. Display second of the two resulting lines.|
|Control-B or Left||move cursor backwards one character|
|Control-F or Right||move cursor forward one character|
|Control-P or Up||go to previous line. If this is the first line of input then recall previous input from history.|
|Control-N or Down||go to next line. If this is the last line of input then recall next input from history|
|Control-A or Home||move cursor to the beginning of the line. If cursor is already at the beginning of the line, then go to the beginning of the first line of current input|
|Control-E or End||move cursor to the end of line. If cursor is already at the end of line, then move it to the end of the last line of current input|
|Control-L or F5||reset terminal and repaint screen|