Senin, 25 November 2013

Script Initial Configuration Mikrotik

#| ether1 is renamed to ether1-gateway
#| DHCP client and masquerade is set on ether1-gateway
#| ether2 is renamed to ether2-master-local and configured as switch master port for ether3-ether5
#| IP address 192.168.88.1/24 and DHCP server is set on ether2-master interface
#| DHCP servers address pool is 192.168.88.10-192.168.88.254

:global action;
:local dhcpEnabled 0;
:local wirelessEnabled 0;

#check for wireless and dhcp packages
:if ([:len [/system package find name="dhcp" !disabled]] != 0) do={
:set dhcpEnabled 1;
}
:if ([:len [/system package find name="wireless" !disabled]] != 0) do={
:set wirelessEnabled 1;
}

#-------------------------------------------------------------------------------
# Apply configuration.
# these commands are executed after installation or configuration reset
#-------------------------------------------------------------------------------
:if ($action = "apply") do={
# wait for interfaces
:while ([/interface ethernet find] = "") do={ :delay 1s; };

/interface set ether1 name="ether1-gateway";
:if ( $dhcpEnabled = 1) do={
/ip dhcp-client add interface=ether1-gateway disabled=no comment="default configuration";
}

/interface {
set ether2 name=ether2-master-local;
set ether3 name=ether3-slave-local;
set ether4 name=ether4-slave-local;
set ether5 name=ether5-slave-local;
}
/interface ethernet {
set ether3-slave-local master-port=ether2-master-local;
set ether4-slave-local master-port=ether2-master-local;
set ether5-slave-local master-port=ether2-master-local;
}


/ip address add address=192.168.88.1/24 interface=ether2-master-local comment="default configuration";
:if ($dhcpEnabled = 1) do={
/ip pool add name="default-dhcp" ranges=192.168.88.10-192.168.88.254;
/ip dhcp-server
add name=default address-pool="default-dhcp" interface=ether2-master-local 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="default configuration";
}
/ip firewall nat add chain=srcnat out-interface=ether1-gateway action=masquerade comment="default configuration"
/ip dns {
set allow-remote-requests=yes
static add name=router address=192.168.88.1
}

}

#-------------------------------------------------------------------------------
# Revert configuration.
# these commands are executed if user requests to remove default configuration
#-------------------------------------------------------------------------------
:if ($action = "revert") do={
:if ($dhcpEnabled = 1) do={
:local o [/ip dhcp-server network find comment="default configuration"]
:if ([:len $o] != 0) do={ /ip dhcp-server network remove $o }
:local o [/ip dhcp-server find name="default" address-pool="default-dhcp" interface="ether2-master-local" !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="default configuration"]
:if ([:len $o] != 0) do={ /ip dhcp-client remove $o }
}
/ip dns {
set allow-remote-requests=no
:local o [static find name=router address=192.168.88.1]
:if ([:len $o] != 0) do={ static remove $o }
}
/ip address {
:local o [find comment="default configuration"]
:if ([:len $o] != 0) do={ remove $o }
}
# remove switch
/interface set ether2-master-local name=ether2;
/interface ethernet set ether3-slave-local master-port=none;
/interface set ether3-slave-local name=ether3;
/interface ethernet set ether4-slave-local master-port=none;
/interface set ether4-slave-local name=ether4;
/interface ethernet set ether5-slave-local master-port=none;
/interface set ether5-slave-local name=ether5;

}

Tidak ada komentar:

Posting Komentar