Guest User

Untitled

a guest
Jul 22nd, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 20.59 KB | None | 0 0
  1. > system default-configuration print
  2.             script: #| Welcome to RouterOS!
  3.                     #|    1) Set a strong router password in the System > Users menu
  4.                     #|    2) Upgrade the software in the System > Packages menu
  5.                     #|    3) Enable firewall on untrusted networks
  6.                     #|    4) Set your country name to observe wireless regulations
  7.                     #|    5) Set antenna gain on wireless interface
  8.                     #| -----------------------------------------------------------------------------
  9.                     #| RouterMode:
  10.                     #|  * WAN port is protected by firewall and enabled DHCP client
  11.                     #|  * Wireless and Ethernet interfaces (except WAN port/s)
  12.                     #|    are part of LAN bridge
  13.                     #| LAN Configuration:
  14.                     #|     IP address 192.168.88.1/24 is set on bridge (LAN port)
  15.                     #|     DHCP Server: enabled;
  16.                     #|     DNS: enabled;
  17.                     #| wlan1 Configuration:
  18.                     #|     mode:                ap-bridge;
  19.                     #|     band:                2ghz-b/g/n;
  20.                     #|     tx-chains:           0;1;
  21.                     #|     rx-chains:           0;1;
  22.                     #|     installation:        indoor;
  23.                     #|     wpa2:      no;
  24.                     #|     ht-extension:        20/40mhz-XX;
  25.                     #| WAN (gateway) Configuration:
  26.                     #|     gateway:  ether1 ;
  27.                     #|     ip4 firewall:  enabled;
  28.                     #|     ip6 firewall:  enabled;
  29.                     #|     NAT:   enabled;
  30.                     #|     DHCP Client: enabled;
  31.                    
  32.                     :global ssid;
  33.                     :global defconfMode;
  34.                     :log info "Starting defconf script";
  35.                     #-------------------------------------------------------------------------------
  36.                     # Apply configuration.
  37.                     # these commands are executed after installation or configuration reset
  38.                     #-------------------------------------------------------------------------------
  39.                     :if ($action = "apply") do={
  40.                       # wait for interfaces
  41.                       :local count 0;
  42.                       :while ([/interface ethernet find] = "") do={
  43.                         :if ($count = 30) do={
  44.                           :log warning "DefConf: Unable to find ethernet interfaces";
  45.                           /quit;
  46.                         }
  47.                         :delay 1s; :set count ($count +1);
  48.                       };
  49.                       :local count 0;
  50.                       :while ([/interface wireless print count-only] < 1) do={
  51.                         :set count ($count +1);
  52.                         :if ($count = 40) do={
  53.                           :log warning "DefConf: Unable to find wireless interface(s)";
  54.                           /ip address add address=192.168.88.1/24 interface=ether1 comment="defconf";
  55.                           /quit
  56.                         }
  57.                         :delay 1s;
  58.                       };
  59.                      /interface list add name=WAN comment="defconf"
  60.                      /interface list add name=LAN comment="defconf"
  61.                      /interface bridge
  62.                        add name=bridge disabled=no auto-mac=yes protocol-mode=rstp comment=defconf;
  63.                      :local bMACIsSet 0;
  64.                      :foreach k in=[/interface find where !(slave=yes  || name="ether1" || name~"bridge")] do={
  65.                        :local tmpPortName [/interface get $k name];
  66.                        :if ($bMACIsSet = 0) do={
  67.                          :if ([/interface get $k type] = "ether") do={
  68.                            /interface bridge set "bridge" auto-mac=no admin-mac=[/interface get $tmpPortName mac-address];
  69.                            :set bMACIsSet 1;
  70.                          }
  71.                        }
  72.                        /interface bridge port
  73.                          add bridge=bridge interface=$tmpPortName comment=defconf;
  74.                      }
  75.                        /ip pool add name="default-dhcp" ranges=192.168.88.10-192.168.88.254;
  76.                        /ip dhcp-server
  77.                          add name=defconf address-pool="default-dhcp" interface=bridge lease-time=10m disabled=no;
  78.                        /ip dhcp-server network
  79.                          add address=192.168.88.0/24 gateway=192.168.88.1 comment="defconf";
  80.                       /ip address add address=192.168.88.1/24 interface=bridge comment="defconf";
  81.                      /ip dns {
  82.                          set allow-remote-requests=yes
  83.                          static add name=router.lan address=192.168.88.1 comment=defconf
  84.                      }
  85.                    
  86.                       /interface wireless {
  87.                         set *C mode=ap-bridge band=2ghz-b/g/n disabled=no wireless-protocol=802.11 \
  88.                            distance=indoors installation=indoor
  89.                         set *C channel-width=20/40mhz-XX;
  90.                         set *C frequency=auto
  91.                         :local wlanMac  [/interface wireless get *C mac-address];
  92.                         :set ssid "MikroTik-$[:pick $wlanMac 9 11]$[:pick $wlanMac 12 14]$[:pick $wlanMac 15 17]"
  93.                         set *C ssid=$ssid
  94.                       }
  95.                        /ip dhcp-client add interface=ether1 disabled=no comment="defconf";
  96.                      /interface list member add list=LAN interface=bridge comment="defconf"
  97.                      /interface list member add list=WAN interface=ether1 comment="defconf"
  98.                      /ip firewall nat add chain=srcnat out-interface-list=WAN ipsec-policy=out,none action=masquerade comment="defconf: masquerade"
  99.                      /ip firewall {
  100.                        filter add chain=input action=accept connection-state=established,related,untracked comment="defconf: accept established,relat>
  101.                       filter add chain=input action=drop connection-state=invalid comment="defconf: drop invalid"
  102.                       filter add chain=input action=accept protocol=icmp comment="defconf: accept ICMP"
  103.                       filter add chain=input action=accept dst-address=127.0.0.1 comment="defconf: accept to local loopback (for CAPsMAN)"
  104.                       filter add chain=input action=drop in-interface-list=!LAN comment="defconf: drop all not coming from LAN"
  105.                       filter add chain=forward action=accept ipsec-policy=in,ipsec comment="defconf: accept in ipsec policy"
  106.                       filter add chain=forward action=accept ipsec-policy=out,ipsec comment="defconf: accept out ipsec policy"
  107.                       filter add chain=forward action=fasttrack-connection connection-state=established,related comment="defconf: fasttrack"
  108.                       filter add chain=forward action=accept connection-state=established,related,untracked comment="defconf: accept established,rel>
  109.                        filter add chain=forward action=drop connection-state=invalid comment="defconf: drop invalid"
  110.                        filter add chain=forward action=drop connection-state=new connection-nat-state=!dstnat in-interface-list=WAN comment="defconf:>
  111.                     }
  112.                     /ipv6 firewall {
  113.                       address-list add list=bad_ipv6 address=::/128 comment="defconf: unspecified address"
  114.                       address-list add list=bad_ipv6 address=::1 comment="defconf: lo"
  115.                       address-list add list=bad_ipv6 address=fec0::/10 comment="defconf: site-local"
  116.                       address-list add list=bad_ipv6 address=::ffff:0:0/96 comment="defconf: ipv4-mapped"
  117.                       address-list add list=bad_ipv6 address=::/96 comment="defconf: ipv4 compat"
  118.                       address-list add list=bad_ipv6 address=100::/64 comment="defconf: discard only "
  119.                       address-list add list=bad_ipv6 address=2001:db8::/32 comment="defconf: documentation"
  120.                       address-list add list=bad_ipv6 address=2001:10::/28 comment="defconf: ORCHID"
  121.                       address-list add list=bad_ipv6 address=3ffe::/16 comment="defconf: 6bone"
  122.                       address-list add list=bad_ipv6 address=::224.0.0.0/100 comment="defconf: other"
  123.                       address-list add list=bad_ipv6 address=::127.0.0.0/104 comment="defconf: other"
  124.                       address-list add list=bad_ipv6 address=::/104 comment="defconf: other"
  125.                       address-list add list=bad_ipv6 address=::255.0.0.0/104 comment="defconf: other"
  126.                       filter add chain=input action=accept connection-state=established,related,untracked comment="defconf: accept established,relat>
  127.                        filter add chain=input action=drop connection-state=invalid comment="defconf: drop invalid"
  128.                        filter add chain=input action=accept protocol=icmpv6 comment="defconf: accept ICMPv6"
  129.                        filter add chain=input action=accept protocol=udp port=33434-33534 comment="defconf: accept UDP traceroute"
  130.                        filter add chain=input action=accept protocol=udp dst-port=546 src-address=fe80::/10 comment="defconf: accept DHCPv6-Client pr>
  131.                       filter add chain=input action=accept protocol=udp dst-port=500,4500 comment="defconf: accept IKE"
  132.                       filter add chain=input action=accept protocol=ipsec-ah comment="defconf: accept ipsec AH"
  133.                       filter add chain=input action=accept protocol=ipsec-esp comment="defconf: accept ipsec ESP"
  134.                       filter add chain=input action=accept ipsec-policy=in,ipsec comment="defconf: accept all that matches ipsec policy"
  135.                       filter add chain=input action=drop in-interface-list=!LAN comment="defconf: drop everything else not coming from LAN"
  136.                       filter add chain=forward action=accept connection-state=established,related,untracked comment="defconf: accept established,rel>
  137.                        filter add chain=forward action=drop connection-state=invalid comment="defconf: drop invalid"
  138.                        filter add chain=forward action=drop src-address-list=bad_ipv6 comment="defconf: drop packets with bad src ipv6"
  139.                        filter add chain=forward action=drop dst-address-list=bad_ipv6 comment="defconf: drop packets with bad dst ipv6"
  140.                        filter add chain=forward action=drop protocol=icmpv6 hop-limit=equal:1 comment="defconf: rfc4890 drop hop-limit=1"
  141.                        filter add chain=forward action=accept protocol=icmpv6 comment="defconf: accept ICMPv6"
  142.                        filter add chain=forward action=accept protocol=139 comment="defconf: accept HIP"
  143.                        filter add chain=forward action=accept protocol=udp dst-port=500,4500 comment="defconf: accept IKE"
  144.                        filter add chain=forward action=accept protocol=ipsec-ah comment="defconf: accept ipsec AH"
  145.                        filter add chain=forward action=accept protocol=ipsec-esp comment="defconf: accept ipsec ESP"
  146.                        filter add chain=forward action=accept ipsec-policy=in,ipsec comment="defconf: accept all that matches ipsec policy"
  147.                        filter add chain=forward action=drop in-interface-list=!LAN comment="defconf: drop everything else not coming from LAN"
  148.                      }
  149.                        /ip neighbor discovery-settings set discover-interface-list=LAN
  150.                        /tool mac-server set allowed-interface-list=LAN
  151.                        /tool mac-server mac-winbox set allowed-interface-list=LAN
  152.                     }
  153.                     #-------------------------------------------------------------------------------
  154.                     # Revert configuration.
  155.                     # these commands are executed if user requests to remove default configuration
  156.                     #-------------------------------------------------------------------------------
  157.                     :if ($action = "revert") do={
  158.                     /user set admin password=""
  159.                      /system routerboard mode-button set enabled=no
  160.                      /system routerboard mode-button set on-event=""
  161.                      /system script remove [find comment~"defconf"]
  162.                      /ip firewall filter remove [find comment~"defconf"]
  163.                      /ipv6 firewall filter remove [find comment~"defconf"]
  164.                      /ipv6 firewall address-list remove [find comment~"defconf"]
  165.                      /ip firewall nat remove [find comment~"defconf"]
  166.                      /interface list member remove [find comment~"defconf"]
  167.                      /interface detect-internet set detect-interface-list=none
  168.                      /interface detect-internet set lan-interface-list=none
  169.                      /interface detect-internet set wan-interface-list=none
  170.                      /interface detect-internet set internet-interface-list=none
  171.                      /interface list remove [find comment~"defconf"]
  172.                      /tool mac-server set allowed-interface-list=all
  173.                      /tool mac-server mac-winbox set allowed-interface-list=all
  174.                      /ip neighbor discovery-settings set discover-interface-list=!dynamic
  175.                        :local o [/ip dhcp-server network find comment="defconf"]
  176.                        :if ([:len $o] != 0) do={ /ip dhcp-server network remove $o }
  177.                        :local o [/ip dhcp-server find name="defconf" !disabled]
  178.                        :if ([:len $o] != 0) do={ /ip dhcp-server remove $o }
  179.                        /ip pool {
  180.                          :local o [find name="default-dhcp" ranges=192.168.88.10-192.168.88.254]
  181.                          :if ([:len $o] != 0) do={ remove $o }
  182.                        }
  183.                        :local o [/ip dhcp-client find comment="defconf"]
  184.                        :if ([:len $o] != 0) do={ /ip dhcp-client remove $o }
  185.                      /ip dns {
  186.                        set allow-remote-requests=no
  187.                        :local o [static find comment="defconf"]
  188.                        :if ([:len $o] != 0) do={ static remove $o }
  189.                      }
  190.                      /ip address {
  191.                        :local o [find comment="defconf"]
  192.                        :if ([:len $o] != 0) do={ remove $o }
  193.                      }
  194.                      :foreach iface in=[/interface ethernet find] do={
  195.                        /interface ethernet set $iface name=[get $iface default-name]
  196.                      }
  197.                      /interface bridge port remove [find comment="defconf"]
  198.                      /interface bridge remove [find comment="defconf"]
  199.                      /interface bonding remove [find comment="defconf"]
  200.                      /interface wireless cap set enabled=no interfaces="" caps-man-addresses=""
  201.                      /interface wireless reset-configuration wlan1
  202.                      /interface wireless security-profile set default mode=none\
  203.                           authentication-types="" disable-pmkid=no wpa2-pre-shared-key="" comment=""
  204.                       /caps-man manager set enabled=no
  205.                       /caps-man manager interface remove [find comment="defconf"]
  206.                       /caps-man manager interface set [ find default=yes ] forbid=no
  207.                       /caps-man provisioning remove [find comment="defconf"]
  208.                       /caps-man configuration remove [find comment="defconf"]
  209.                     }
  210.                     :log info Defconf_script_finished;
  211.                     :set defconfMode;
  212.                     :set ssid;
  213.                    
  214.   caps-mode-script: #-------------------------------------------------------------------------------
  215.                     # Note: script will not execute at all (will throw a syntax error) if
  216.                     #       dhcp or wireless-fp packages are not installed
  217.                     #-------------------------------------------------------------------------------
  218.                    
  219.                     #| CAP configuration
  220.                     #|
  221.                     #|   Wireless interfaces are set to be managed by CAPsMAN.
  222.                     #|   All ethernet interfaces and CAPsMAN managed interfaces are bridged.
  223.                     #|   DHCP client is set on bridge interface.
  224.                    
  225.                     # bridge port name
  226.                     :global brName  "bridgeLocal";
  227.                     :global logPref "defconf:";
  228.                    
  229.                    
  230.                     :global action;
  231.                    
  232.                     :log info $action
  233.                    
  234.                     :if ($action = "apply") do={
  235.                    
  236.                       # wait for ethernet interfaces
  237.                       :local count 0;
  238.                       :while ([/interface ethernet find] = "") do={
  239.                         :if ($count = 30) do={
  240.                           :log warning "DefConf: Unable to find ethernet interfaces";
  241.                           /quit;
  242.                         }
  243.                         :delay 1s; :set count ($count + 1);
  244.                       }
  245.                    
  246.                       :local macSet 0;
  247.                       :local tmpMac "";
  248.                    
  249.                       :foreach k in=[/interface ethernet find] do={
  250.                         # first ethernet is found; add bridge and set mac address of the ethernet port
  251.                         :if ($macSet = 0) do={
  252.                           :set tmpMac [/interface ethernet get $k mac-address];
  253.                           /interface bridge add name=$brName auto-mac=no admin-mac=$tmpMac comment="defconf";
  254.                           :set macSet 1;
  255.                         }
  256.                         # add bridge ports
  257.                         /interface bridge port add bridge=$brName interface=$k comment="defconf"
  258.                       }
  259.                    
  260.                       # try to add dhcp client on bridge interface (may fail if already exist)
  261.                       :do {
  262.                         /ip dhcp-client add interface=$brName disabled=no comment="defconf"
  263.                       } on-error={ :log warning "$logPref unable to add dhcp client";}
  264.                    
  265.                    
  266.                       # try to configure caps (may fail if for example specified interfaces are missing)
  267.                       :local interfacesList "";
  268.                       :local bFirst 1;
  269.                    
  270.                       # wait for wireless interfaces
  271.                       :while ([/interface wireless find] = "") do={
  272.                         :if ($count = 30) do={
  273.                           :log warning "DefConf: Unable to find wireless interfaces";
  274.                           /quit;
  275.                         }
  276.                         :delay 1s; :set count ($count + 1);
  277.                       }
  278.                    
  279.                       # delay just to make sure that all wireless interfaces are loaded
  280.                       :delay 5s;
  281.                       :foreach i in=[/interface wireless find] do={
  282.                         if ($bFirst = 1) do={
  283.                           :set interfacesList [/interface wireless get $i name];
  284.                           :set bFirst 0;
  285.                         } else={
  286.                           :set interfacesList "$interfacesList,$[/interface wireless get $i name]";
  287.                         }
  288.                       }
  289.                       :do {
  290.                         /interface wireless cap
  291.                           set enabled=yes interfaces=$interfacesList discovery-interfaces=$brName bridge=$brName
  292.                       } on-error={ :log warning "$logPref unable to configure caps";}
  293.                    
  294.                     }
  295.                    
  296.                     :if ($action = "revert") do={
  297.                       :do {
  298.                         /interface wireless cap
  299.                           set enabled=no interfaces="" discovery-interfaces="" bridge=none
  300.                       } on-error={ :log warning "$logPref unable to unset caps";}
  301.                    
  302.                       :local o [/ip dhcp-client find comment="defconf"]
  303.                       :if ([:len $o] != 0) do={ /ip dhcp-client remove $o }
  304.                    
  305.                       /interface bridge port remove [find comment="defconf"]
  306.                       /interface bridge remove [find comment="defconf"]
  307.                    
  308.                     }
  309.      custom-script:
Add Comment
Please, Sign In to add comment