MikroTik RouterOS是一种路由操作系统,是基于Linux核心开发,兼容x86 PC的路由软件,并通过该软件将标准的PC电脑变成专业路由器,在软件RouterOS 软路由图的开发和应用上不断的更新和发展,软件经历了多次更新和改进,使其功能在不断增强和完善。特别在无线、认证、策略路由、带宽控制和防火墙过滤等功能上有着非常突出的功能,其极高的性价比,受到许多网络人士的青睐。
1 路由版本
# mar/09/1970 09:10:50 by RouterOS 6.23
2 以太网接口
#以太网口重命名 /interface ethernet set [ find default-name=ether1 ] name=ether01 set [ find default-name=ether2 ] name=ether02 set [ find default-name=ether3 ] name=ether03 set [ find default-name=ether4 ] name=ether04 set [ find default-name=ether5 ] name=ether05 set [ find default-name=ether6 ] name=ether06 set [ find default-name=ether7 ] name=ether07 set [ find default-name=ether8 ] name=ether08 set [ find default-name=ether9 ] name=ether09 set [ find default-name=ether10 ] name=ether10
3 网桥配置
3.1 配置网桥
/interface bridge add name=bridge01
3.2 添加网桥成端口
/interface bridge port add bridge=bridge01 interface=ether06 add bridge=bridge01 interface=ether07 add bridge=bridge01 interface=ether08 add bridge=bridge01 interface=ether09 add bridge=bridge01 interface=ether10
4 内网接口配置
/ip address #内网接口IP配置 add address=10.0.0.1/24 interface=bridge01 network=10.0.0.0
5 源地址NAT
把内网的源主机伪装成具有当前公网IP的主机与外网通讯
/ip firewall nat add action=masquerade chain=srcnat
6 DHCP相关配置
6.1 配置DHCP分配地址池
/ip pool add name=default-dhcp ranges=10.0.0.50-10.0.0.199
6.2 配置DHCP服务
/ip dhcp-server add address-pool=default-dhcp disabled=no interface=bridge01 name=dhcp1
6.3 配置DHCP服务网络
/ip dhcp-server network add address=10.168.0.0/24 comment="default configuration" \ dns-server=202.96.128.86,202.96.128.166 gateway=10.168.0.1 netmask=24
6.4 配置DHCP客户端网络参数指定
/ip dhcp-server network add address=10.0.0.0/24 comment="default configuration" \ dns-server=202.96.128.86,202.96.128.166 gateway=10.0.0.1
6.5 本机作为DHCP客户端的配置
/ip dhcp-client add comment="default configuration" dhcp-options=hostname,clientid interface=ether01
7 外网口配置
7.1 PPPOE拨号配置
/interface pppoe-client add ac-name="" add-default-route=yes allow=pap,chap,mschap1,mschap2 \ default-route-distance=1 dial-on-demand=yes disabled=no interface=ether01 \ keepalive-timeout=60 max-mru=1480 max-mtu=1480 mrru=disabled name=\ ChinaNet password=******* profile=default service-name="" use-peer-dns=\ no user=0769*******@163.gd
7.2 外网接口静态IP配置
/ip address add interface=ether01 address=192.168.1.64
8 默认路由配置
#外网接口为固定IP地址使用 /ip route add dst-address=0.0.0.0/0 gateway=192.168.1.1
9 目标地址NAT(端口映射)
注:以下配置无需防火墙允许,直接生效
9.1 将外网的某个端口映射到内网主机的某个端口
/ip firewall nat add chain=dstnat action=dst-nat to-addresses=192.168.0.200 to-ports=8082 \ protocol=tcp dst-port=8082
9.2 映射同时只允许特定的源地址访问某个目标端口
/ip firewall address-list add list=cmdschool.org address=116.6.95.48 add list=cmdschool.org address=116.6.95.49 /ip firewall nat add chain=dstnat action=dst-nat to-addresses=192.168.0.250 to-ports=1194 \ protocol=tcp src-address-list=cmdschool.org dst-port=1194
10 防火墙配置
10.1 地址列表:
/ip firewall address-list add list=10.0.0.0/24 address=10.0.0.2-10.0.0.254
10.2 filter
10.2.1 基础配置代码
/ip firewall filter #--允许icmp协议(ping)的数据包进入所有接口 add chain=input action=accept protocol=icmp #--允许已经建立连接状态的数据包进入所有接口 add chain=input action=accept connection-state=established add chain=input action=accept connection-state=related #--拒接所有(TCP/UDP等)数据包进入all-ppp接口(如果固定IP接口使用ether01) add chain=input action=drop in-interface=all-ppp #--允许已经建立连接状态的数据包内核转发 add chain=forward action=accept connection-state=established add chain=forward action=accept connection-state=related #--拒绝无效状态的数据包内核转发 add chain=forward action=drop connection-state=invalid
10.2.2 允许端口访问
#--开启特定的IP对路由管理 /ip firewall address-list add list=cmdschool.org address=116.6.95.48 add list=cmdschool.org address=116.6.95.49 /ip firewall filter add chain=input action=accept protocol=tcp src-address-list=cmdschool.org \ dst-port=22
10.2.3 数据包过滤
/ip firewall filter add chain=forward action=accept protocol=tcp in-interface=bridge01 dst-port=53 add chain=forward action=accept protocol=udp in-interface=bridge01 dst-port=53 add chain=forward action=accept protocol=tcp in-interface=bridge01 dst-port=80 add chain=forward action=accept protocol=tcp in-interface=bridge01 dst-port=443 add chain=forward action=drop in-interface=bridge01
11 NTP服务器与时区设置
/system ntp client set enabled=yes server-dns-names=1.centos.pool.ntp.org /system clock set time-zone-name=Asia/Shanghai
12 其他配置
12.1 邻居发现协议(默认值)
/ip neighbor discovery set ether01 discover=no
12.2 管理端口
/port set 0 name=serial0
12.3 DNS服务器配置
/ip dns set allow-remote-requests=yes servers=202.96.128.86,202.96.128.166
12.4 服务配置
/ip service set telnet disabled=yes /lcd set time-interval=daily /tool mac-server set [ find default=yes ] disabled=yes add interface=ether02 add interface=ether03 add interface=ether04 add interface=ether05 add interface=ether06 add interface=ether07 add interface=ether08 add interface=ether09 add interface=ether10 add interface=sfp1 add /tool mac-server mac-winbox set [ find default=yes ] disabled=yes add interface=ether02 add interface=ether03 add interface=ether04 add interface=ether05 add interface=ether06 add interface=ether07 add interface=ether08 add interface=ether09 add interface=ether10 add interface=sfp1 add
13 备注
console口配置每秒位115200