(一)routeros命令笔记:开局篇
1.保存配置脚本
/export file=backup-step3
2.清除所有配置
/system reset-configuration no-defaults=yes skip-backup=yes
3.常用开局
设置创建桥接接口并分配桥接端口;
为桥接接口分配IP地址;
配置DHCP服务器。
/interface bridge add name=bridge1
/interface bridge port add interface=ether2 bridge=bridge1
/ip address add address=192.168.88.1/24 interface=bridge1
[admin@MikroTik] > ip dhcp-server/ setup [enter]
Select interface to run DHCP server on dhcp server interface: bridge1 [enter]
Select network for DHCP addresses dhcp address space: 192.168.88.0/24 [enter]
Select gateway for given network gateway for dhcp network: 192.168.88.1 [enter]
Select pool of ip addresses given out by DHCP server addresses to give out: 192.168.88.2-192.168.88.254 [enter]
Select DNS servers dns servers: 192.168.88.1 [enter]
Select lease time lease time: 1800 [enter]
三种上网方式DHCP自动获取、静态公网IP和PPPOE拨号
1.DHCP自动获取配置方法
/ip dhcp-client add disabled=no interface=ether1
查看DHCP服务端分配的信息
[admin@MikroTik] > ip dhcp-client print
Columns: INTERFACE, USE-PEER-DNS, ADD-DEFAULT-ROUTE, STATUS, ADDRESS
# INTERFACE USE-PEER-DNS ADD-DEFAULT-ROUTE STATUS ADDRESS
0 ether1 yes yes bound 1.2.3.100/24
2.静态公网IP配置方法
配置静态地址时,ISP会提供具体参数,例如:
• IP地址:1.2.3.100/24
• 网关:1.2.3.1
• DNS服务器:8.8.8.8
/ip address add address=1.2.3.100/24 interface=ether1
/ip route add gateway=1.2.3.1
/ip dns set servers=8.8.8.8
3.PPPOE拨号方式配置
服务提供商(ISP)会为提供连接所需的用户名和密码
/interface pppoe-clientadd disabled=no interface=ether1 user=me password=123 \add-default-route=yes use-peer-dns=yes
配置后验证连接
[admin@MikroTik] > /ping 8.8.8.8SEQ HOST SIZE TTL TIME STATUS 0 8.8.8.8 56 55 14ms399us 1 8.8.8.8 56 55 18ms534us 2 8.8.8.8 56 55 14ms384us
验证DNS
[admin@MikroTik] > /ping www.baidu.comSEQ HOST SIZE TTL TIME STATUS 0 220.181.7.203 56 55 14ms475us 1 220.181.7.203 56 55 14ms308us 2 220.181.7.203 56 55 14ms238us
配置NAT:此时,PC还无法访问互联网,因为本地使用的地址在互联网上是不可路由的。远程主机根本不知道如何正确回复你的本地地址。
解决这个问题的方法是将出站数据包的源地址更改为路由器的公共IP。这可以通过NAT规则来实现:
/ip firewall natadd chain=srcnat out-interface=pppoe-out1 action=masquerade
如果公共接口是PPPoE、LTE或其他任何类型,'out-interface’应设置为该接口。
这种设置的另一个好处是,路由器后的NAT客户端并不直接连接到互联网,因此通常不需要额外的防护来抵御外部攻击。某些客户端设备可能需要通过特定端口直接访问互联网。例如,必须能够通过远程桌面协议(RDP)访问IP地址为192.168.88.254的客户端。 如果设置了严格的防火墙规则,则必须在防火墙筛选转发链中允许RDP协议。
/ip firewall natadd chain=dstnat protocol=tcp port=3389 in-interface=ether1 \action=dst-nat to-address=192.168.88.254
4.修改密码
[admin@MikroTik] > /password
old-password: ********
new-password: ****************************
confirm-new-password: ****************************
5.创建新管理员账号
/user add name=myname password=mypassword group=full
/user remove admin
6.禁止WAN口访问winbox,只允许LAN口访问
[admin@MikroTik] > /interface list add name=LAN
[admin@MikroTik] > /interface list member add list=LAN interface=bridge1
[admin@MikroTik] > /tool mac-server set allowed-interface-list=LAN
[admin@MikroTik] > /tool mac-server mac-winbox set allowed-interface-list=LAN
只允许LAN运行邻居发现协议
/ip neighbor discovery-settings set discover-interface-list=LAN
7.防火墙基本限制
/ip firewall filteradd chain=input action=accept connection-state=established,related,untracked comment="accept established,related,untracked"add chain=input action=drop connection-state=invalid comment="drop invalid"add chain=input in-interface=ether1 action=accept protocol=icmp comment="accept ICMP"add chain=input in-interface=ether1 action=accept protocol=tcp port=8291 comment="allow Winbox";add chain=input in-interface=ether1 action=accept protocol=tcp port=22 comment="allow SSH";add chain=input in-interface=ether1 action=drop comment="block everything else";
8.关闭不必要的服务和更该端口号
/ip service disable telnet,ftp,www,api
/ip service set ssh port=2200
9.其他事项
带宽服务器用于测试两台MikroTik路由器之间的吞吐量。在生产环境中请禁用该功能。
/tool bandwidth-server set enabled=no
路由器可能启用了DNS缓存功能,这会缩短客户端向远程服务器发送DNS请求时的解析时间。如果路由器不需要DNS缓存,或者使用其他路由器来实现此功能,请将其禁用。
/ip dns set allow-remote-requests=no
为了减少对路由器的未经授权访问,建议禁用所有未使用的接口。
/interface print
/interface set ether13 disabled=yes
RouterOS采用更强的SSH加密算法,启用SSH强加密
/ip ssh set strong-crypto=yes
10.在CLI中运行undo或redo命令,或在GUI中点击撤销和重做按钮来撤销或重做任何操作
下面演示如何添加防火墙规则以及如何撤销和重做该操作。
[admin@v7_ccr_bgp] /ip/firewall/filter> add chain=forward action=drop [admin@v7_ccr_bgp] /ip/firewall/filter> print
Flags: X - disabled, I - invalid; D - dynamic
0 X chain=input action=drop protocol=icmp src-address=10.155.101.1 log=no
log-prefix=""1 chain=forward action=drop[admin@v7_ccr_bgp] /ip/firewall/filter> /system/history/print
Flags: U - undoable, R - redoable, F - floating-undo
Columns: ACTION, BY, POLICy
ACTION BY POLIC
F filter rule added admin write
U --- write
[admin@v7_ccr_bgp] /ip/firewall/filter>
撤销命令
[admin@v7_ccr_bgp] /ip/firewall/filter> /undo
[admin@v7_ccr_bgp] /ip/firewall/filter> print
Flags: X - disabled, I - invalid; D - dynamic
0 X chain=input action=drop protocol=icmp src-address=10.155.101.1 log=no
log-prefix=""[admin@v7_ccr_bgp] /ip/firewall/filter>
现在返回最后一次更改
[admin@v7_ccr_bgp] /ip/firewall/filter> /redo
[admin@v7_ccr_bgp] /ip/firewall/filter> print
Flags: X - disabled, I - invalid; D - dynamic
0 X chain=input action=drop protocol=icmp src-address=10.155.101.1 log=no
log-prefix=""1 chain=forward action=drop [admin@v7_ccr_bgp] /ip/firewall/filter>
/system history
可以查看所有操作记录
[admin@v7_ccr_bgp] /system/history> print detail
Flags: U - undoable, R - redoable, F - floating-undo F redo=/ip firewall filter add action=accept chain=forward disabled=no log=no \log-prefix="" protocol=tcpundo=/ip firewall filter remove *4 action="filter rule added" by="admin" policy=write time=oct/10/2019 18:51:05 F redo=/ip firewall filter add action=accept chain=forward undo=/ip firewall filter remove *3 action="filter rule added" by="admin" policy=write time=oct/10/2019 18:49:03 U redo="" undo="" action="---" by="" policy=write time=sep/27/2019 13:07:35
[admin@v7_ccr_bgp] /system/history>
11.返回顶层,请键入“/”
[admin@MikroTik] > ip route
[admin@MikroTik] ip route> /
[admin@MikroTik] >
要向上移动一个命令级别,请输入"…"
[admin@MikroTik] ip route> ..
[admin@MikroTik] ip>
其他常用命令
查看端口信息
[admin@rack1_b32_CCR1036] /interface ethernet> print
Flags: X - disabled, R - running, S - slave # NAME MTU MAC-ADDRESS ARP SWITCH 0 R ether1 1500 D4:CA:6D:01:22:96 enabled 1 R ether2 1500 D4:CA:6D:01:22:97 enabled 2 R ether3 1500 D4:CA:6D:01:22:98 enabled 3 ether4 1500 D4:CA:6D:01:22:99 enabled 4 ether5 1500 D4:CA:6D:01:22:9A enabled 5 ether6 1500 D4:CA:6D:01:22:9B enabled 6 ether7 1500 D4:CA:6D:01:22:9C enabled 7 R ether8 1500 D4:CA:6D:01:22:9D enabled 8 sfp-sfpplus1 1500 D4:CA:6D:01:22:94 enabled 9 sfp-sfpplus2 1500 D4:CA:6D:01:22:95 enabled
查看arp
[admin@host_a] /ip arp> print
Flags: X - disabled, I - invalid, H - DHCP, D - dynamic, P - published,
C - complete # ADDRESS MAC-ADDRESS INTERFACE 0 DC 10.155.101.217 08:00:27:3C:79:3A ether1 [admin@host_b] /ip arp> print
Flags: X - disabled, I - invalid, H - DHCP, D - dynamic, P - published,
C - complete # ADDRESS MAC-ADDRESS INTERFACE 0 DC 10.155.101.225 08:00:27:85:69:B5 ether1