CPE - Router Comfig
CPE - Router Comfig
7
# software id = Z0GY-TZ0T
#
script: #| Welcome to RouterOS!
#| 1) Set a strong router password in the System > Users
menu
#| 2) Upgrade the software in the System > Packages menu
#| 3) Enable firewall on untrusted networks
#| 4) Set your country name to observe wireless regulations
#| 5) Set antenna gain on wireless interface
#|
-----------------------------------------------------------------------------
#| CPE RouterMode:
#| * wireless interface connected to providers network (WAN
port);
#| * WAN port is protected by firewall and enabled DHCP client
#| wlan1 Configuration:
#| mode: station;
#| band: 2ghz-b/g/n;
#| tx-chains: 0;1;
#| rx-chains: 0;1;
#| installation: outdoor;
#| wpa2: no;
#| ht-extension: 20/40mhz-XX;
#| LAN Configuration:
#| IP address 192.168.88.1/24 is set on ether1 (LAN port)
#| DHCP Server: enabled;
#| DNS: enabled;
#| WAN (gateway) Configuration:
#| gateway: wlan1 ;
#| ip4 firewall: enabled;
#| ip6 firewall: enabled;
#| NAT: enabled;
#| DHCP Client: enabled;
#| Login
#| admin user protected by password
:global ssid;
:global defconfMode;
:log info "Starting defconf script";
#-------------------------------------------------------------------------------
# Apply configuration.
# these commands are executed after installation or
configuration reset
#-------------------------------------------------------------------------------
:if ($action = "apply") do={
# wait for interfaces
:local count 0;
:while ([/interface ethernet find] = "") do={
:if ($count = 30) do={
:log warning "DefConf: Unable to find ethernet
interfaces";
/quit;
}
:delay 1s; :set count ($count +1);
};
:local count 0;
:while ([/interface wireless print count-only] < 1) do={
:set count ($count +1);
:if ($count = 40) do={
:log warning "DefConf: Unable to find wireless
interface(s)";
/ip address add address=192.168.88.1/24 interface=ether1
comment="defconf";
/quit
}
:delay 1s;
};
/interface wireless {
:local ifcId [/interface wireless find where default-
name=wlan1]
:local currentName [/interface wireless get $ifcId name]
set $ifcId mode=station band=2ghz-b/g/n disabled=no
wireless-protocol=any \
distance=dynamic installation=outdoor
set $ifcId channel-width=20/40mhz-XX;
set $ifcId frequency=auto
}
/interface list add name=WAN comment="defconf"
/interface list add name=LAN comment="defconf"
/ip pool add name="default-dhcp" ranges=192.168.88.10-
192.168.88.254;
/ip dhcp-server
add name=defconf address-pool="default-dhcp"
interface=ether1 lease-time=10m disabled=no;
/ip dhcp-server network
add address=192.168.88.0/24 gateway=192.168.88.1 dns-
server=192.168.88.1 comment="defconf";
/ip address add address=192.168.88.1/24 interface=ether1
comment="defconf";
/ip dns {
set allow-remote-requests=yes
static add name=router.lan address=192.168.88.1
comment=defconf
}
#-------------------------------------------------------------------------------
# Revert configuration.
# these commands are executed if user requests to remove
default configuration
#-------------------------------------------------------------------------------
:if ($action = "revert") do={
/user set admin password=""
/system routerboard mode-button set enabled=no
/system routerboard mode-button set on-event=""
/system script remove [find comment~"defconf"]
/ip firewall filter remove [find comment~"defconf"]
/ipv6 firewall filter remove [find comment~"defconf"]
/ipv6 firewall address-list remove [find comment~"defconf"]
/ip firewall nat remove [find comment~"defconf"]
/interface list member remove [find comment~"defconf"]
/interface detect-internet set detect-interface-list=none
/interface detect-internet set lan-interface-list=none
/interface detect-internet set wan-interface-list=none
/interface detect-internet set internet-interface-list=none
/interface list remove [find comment~"defconf"]
/tool mac-server set allowed-interface-list=all
/tool mac-server mac-winbox set allowed-interface-list=all
/ip neighbor discovery-settings set discover-interface-list=!
dynamic
:local o [/ip dhcp-server network find comment="defconf"]
:if ([:len $o] != 0) do={ /ip dhcp-server network remove
$o }
:local o [/ip dhcp-server find name="defconf" !disabled]
:if ([:len $o] != 0) do={ /ip dhcp-server remove $o }
/ip pool {
:local o [find name="default-dhcp" ranges=192.168.88.10-
192.168.88.254]
:if ([:len $o] != 0) do={ remove $o }
}
:local o [/ip dhcp-client find comment="defconf"]
:if ([:len $o] != 0) do={ /ip dhcp-client remove $o }
/ip dns {
set allow-remote-requests=no
:local o [static find comment="defconf"]
:if ([:len $o] != 0) do={ static remove $o }
}
/ip address {
:local o [find comment="defconf"]
:if ([:len $o] != 0) do={ remove $o }
}
:foreach iface in=[/interface ethernet find] do={
/interface ethernet set $iface name=[get $iface default-
name]
}
/interface bridge port remove [find comment="defconf"]
/interface bridge remove [find comment="defconf"]
/interface bonding remove [find comment="defconf"]
/interface wireless cap set enabled=no interfaces="" caps-man-
addresses=""
/interface wireless reset-configuration wlan1
/interface wireless security-profile set default mode=none\
authentication-types="" disable-pmkid=no wpa2-pre-shared-
key="" comment=""
/caps-man manager set enabled=no
/caps-man manager interface remove [find comment="defconf"]
/caps-man manager interface set [ find default=yes ]
forbid=no
/caps-man provisioning remove [find comment="defconf"]
/caps-man configuration remove [find comment="defconf"]
/caps-man security remove [find comment="defconf"]
}
:log info Defconf_script_finished;
:set defconfMode;
:set ssid;
caps-mode-script:
#-------------------------------------------------------------------------------
# Note: script will not execute at all (will throw a syntax
error) if
# dhcp or wireless-fp packages are not installed
#-------------------------------------------------------------------------------
#| CAP configuration
#|
#| Wireless interfaces are set to be managed by CAPsMAN.
#| All ethernet interfaces and CAPsMAN managed interfaces are
bridged.
#| DHCP client is set on bridge interface.
:global action;
:local macSet 0;
:local tmpMac "";
}
custom-script: