DICA: CONFIGURANDO O IPV6

Publicado por André Andrade em

DICA IPV6 – Como colocar para rodar na sua Rede

A partir do minuto 42, ele explica como ativar IPV6.

👉 https://www.youtube.com/watch?v=_MxBe0hFuTU&feature=emb_logo

Realmente gostei dos 2 scripts.

Um ótimo trabalho do Sr. Ademir Vida (Wide Soft International, Brazil).

A ativação do IPV6 da forma apresentada além de simples. Acaba com a necessidade de se ter LOG para o IPV6 pois o range ficará atribuído diretamente ao assinante.

Na parte inicial do vídeo ele trata de CGNAT de uma forma bem bacana e que fica perfeito com o seu ReceitaNet.

Script IPV6
IPV6-Leftmost

OU Copie e Cole os comandos abaixo no new terminal do mikrotik:

/system script remove [find name="wm-ipv6"];/system script add name=wm-ipv6 source=":if\_([:len [/system script job find script=\"wm-ipv6\"]] = 1) do={:local pd [:parse \":local b [:parse \\\":local r 1;:if ((bt) != (bi)) do={:for i from=(bt) to=((bi)-1) do={:set r ((r) * 2);};};:return (r);\\\"];:local n [:parse \\\":local i (ip);:return [:tonum (\\\\\\\"0x\\\\\\\".[:pick (i) 10 14].[:pick (i) 15 19])];\\\"];:local h [:parse \\\":local i (d);:local p (ip);:local\_n;:while ((i) != 0) do={:local t [:toa \\\\\\\"0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F\\\\\\\"];:local f ((i) / 16);:local q ((f) * 16);:local s 0;:if (q != (i)) d={:set s ((i) - q);};:set n ([:pic (t) (s)].(n));:set i (f);};:while ([:len (n)] < 8) do={:set n (\\\\\\\"0\\\\\\\".(n));};:set n ([:pick (p) 0 10].[:pick (n) 0 4].\\\\\\\":\\\\\\\".[:pick (n) 4 8].\\\\\\\"::\\\\\\\");:return (n);\\\"];:local ie [:parse \\\":local i (ip);:local b [:find (i) \\\\\\\"/\\\\\\\"];:local n;:if ([:tostr (b)] = \\\\\\\"\\\\\\\") do={:set b [:len\_(i)];} else={:set n [:pick (i) (b) [:len (i)]];};:set i [:pick (i) 0 (b)];:local c 0;:while ([:tostr [:find (i) \\\\\\\":\\\\\\\"]] != \\\\\\\"\\\\\\\") do={:set i ([:pick (i) 0 [:find (i) \\\\\\\":\\\\\\\"]].\\\\\\\",\\\\\\\".[:pick (i) ([:find (i) \\\\\\\":\\\\\\\"]+1) [:len (i)]]);:set c ((c)+1);};:local v [:find (i) \\\\\\\",,\\\\\\\"];:if ([:tostr (v)] != \\\\\\\"\\\\\\\") do={:local e \\\\\\\",\\\\\\\";:if ([:tostr [:pick (i) ((v)-1)]] = \\\\\\\"\\\\\\\") do={:set e ((e).\\\\\\\"0,\\\\\\\");};:if ([:tostr [:pick (i) ((v)+2)]] = \\\\\\\"\\\\\\\") do={:set e ((e).\\\\\\\"0,\\\\\\\");};:for p\_from=0 to=(7-(c)) do={:set e ((e).\\\\\\\"0,\\\\\\\");};:set i ([:pick (i)\_0 (v)].(e).[:pick (i) ((v)+2) [:len (i)]]);};:set i [:toarray (i)];:local ie;:foreach z in=(i) do={:set z [:tostr (z)];:while ([:len (z)] < 4) do={:set z (\\\\\\\"0\\\\\\\".(z));};:set ie ((ie).(z).\\\\\\\":\\\\\\\");};:set ie\_([:pick (ie) 0 ([:len (ie)]-1)].(n));:return (ie);\\\"];:local z [:parse \\\":local n (c);:while ((n) ~ \\\\\\\"^0\\\\\\\") do={:set n [:pick (n) 1 [:len (n)]];};:return (n);\\\"];:local sc (m);:if ((sc) = \\\"p\\\") do={:set\_sc 0;} else={:set sc 3;};:local pd [:toarray [/system scheduler get [find name=wm-ipv6] comment]];:local in [(ie) ip=[:pick (pd) (sc)]];:local pd1 [:pick (in) 0 4];:local pd2 [:pick (in) 5 9];:local pd0 ([(z) c=(pd1)] . \\\":\\\" . [(z) c=(pd2)]);:local ipv6;:local ll [:toarray \\\"\\\"];:if ((sc) = 0) do={:foreach ii in=[/ppp secret find service=pppoe remote-ipv6-prefix~(\\\"^\\\" . (pd0))] do={:local p [:tostr [/ppp secret get (ii) remote-ipv6-prefix]];:local m [:tonum [:pick (p) ([:find (p) \\\"/\\\"]+1) [:len (p)]]];:if\_((m) > 31 && (m) < 65) do={:local pr [(ie) ip=(p)];:set pr [:pick (pr) 0 20];:local ipp [(n) ip=(pr)];:local bc [(b) bt=(m) bi=64];:local bcp ((ipp)+((bc)-1));:set ll ((ll)+[:toarray (ipp)]+[:toarray (bcp)]);};};} else={:foreach ii in=[/ipv6 pool find dynamic=no prefix~(\\\"^\\\" . (pd0))] do={:local p [:tostr [/ipv6 pool get (ii) prefix]];:local m [:tonum [:pick (p) ([:find (p) \\\"/\\\"]+1) [:len (p)]]];:if ((m) > 31 && (m) < 65) do={:local pr [(ie) ip=(p)];:set pr [:pick (pr) 0 20];:local ipp [(n) ip=(pr)];:local bc [(b) bt=(m) bi=64];:local bcp ((ipp)+((bc)-1));:set ll ((ll)+[:toarray (ipp)]+[:toarray (bcp)]);};};};:local r [(b) bt=[:pick (pd) ((sc)+1)] bi=64];:local e [(b) bt=[:pick (pd) ((sc)+2)] bi=64];:local m 1;:local l [:toarray (m)];:while ((r) != (m)) do={:set m ((m) *2);:set l ([:toarray (m)]+(l));};:local p [:toarray \\\"\\\"];:local i 0;:local nf true;:while ([:len (p)] != ((r)/(e))\_&& (nf)) do={:local c [:pick (l) (i)];:local f 0;:local s [:toarray \\\"\\\"];:while ((f) != (r) && (nf)) do={:if ([:tostr [:find (p) (f)]] = \\\"\\\") do={:set s ((s)+[:toarray (f)]);:local il ([(n) ip=(in)]+(f));:local ip [(h) d=(il) ip=(in)];:if ([:tostr [:find (ll) (il)]] = \\\"\\\") do={:local lb\_true;:local ib ((il)+((e)-1));:local bc [(h) d=(ib) ip=(ip)];:for ii from=0 to=(([:len (ll)]/2)-1) do={:local i1 [:pick (ll) ((ii)*2)];:local i2 [:pick (ll) (((ii)*2)+1)];:if ((i1) < (il) && (il) < (i2) || (il) < (i1) && (i1) < (ib)) do={:set lb false;};};:if (lb) do={:put ((ip).\\\"/\\\".(bc));:if ([:tostr (ip)] != \\\"\\\") do={:set ipv6 ((ip).\\\"/\\\".[:pick (pd) ((sc)+2)]);};:set nf false;};};};:set f ((c)+(f));};:set p ((p)+(s));:set i ((i)+1);};:return (ipv6);\"];:foreach i in=[/ppp secret find service=pppoe remote-ipv6-prefix=[:toid \"\"]] do={:local pp [(pd) m=p];/ppp secret set (i) remote-ipv6-prefix=(pp);:local dd [(pd) m=d];:local u [/ppp secret get (i) name];:local n [:tostr [:toip6 [:pick (dd) 0 [:find (dd) \"/\"]]]];:local l [:pick (dd) ([:find (dd) \"/\"]+1) [:len (dd)]];:local nl ((n).\"/\".(l));:local c (\"<pppoe-\".(u).\">\");:local in pppoe;:if ([:tostr [/interface pppoe-server\_server find]] != \"\") do={:set in [:tostr [/interface pppoe-server server\_get [:pick [find] 0] service-name]];};/interface pppoe-server remove [find\_name=(c) || user=(u) && service=(in)];\t/interface pppoe-server add name=(c) user=(u) service=(in);/ipv6 dhcp-server binding remove [find address=(nl)\_|| server=(c)];:if ([:tostr [/ipv6 pool find name=(c)]] = \"\") do={/ipv6 pool add name=(c) prefix=(nl) prefix-length=(l);};/ipv6 dhcp-server remove [find name=(c) || interface=(c)];/ipv6 dhcp-server add name=(c) interface=(c)\_address-pool=(c) lease-time=1d;};};";/system scheduler remove [find name="wm-ipv6"];/system scheduler add comment=2001:0db8::,48,64,2001:db9::,48,60 interval=5s start-time=startup name=wm-ipv6 on-event=wm-ipv6;</pppoe-\".(u).\">

Script CGNAT
CGNAT

OU Copie e Cole os comandos abaixo no new terminal do mikrotik:

/system scheduler remove [find name="wm-cgnat"];/system scheduler add interval=5s start-time=startup name=wm-cgnat on-event=":local g 0;:local ip;:local d;:if ([:tostr [/ip pool find name~\"^wm-cgnat/\"]] != \"\") do={:set ip [:pick [/ip pool get [find name~\"^wm-cgnat/\"] ranges] 0];:if ([:tostr [:find (ip) \"/\"]]\_!= \"\") do={:set d [/ip pool get [find name~\"^wm-cgnat/\"] name];:if ([:tostr [:find (d) \"/\"]] != \"\") do={:set d [:tonum [:pick (d) ([:find (d) \"/\"]+1) [:len (d)]]];:if ((d) > 1 && (d) < 65) do={:if ([:tostr (d)] = \"\" || [:tonum (d)] > 64) do={:set d 64;\t};:if ([:tostr (g)] = \"\") do={:set g 0;\t};/ip firewall address-list remove [find list=no-wm-cgnat];/ip firewall nat remove [find comment~\"^wm-cgnat\"];/ip pool remove [find name~\"^wm-cgnat\"];:foreach i in=[:toarray \"10.0.0.0/8,172.16.0.0/12,192.168.0.0/16\"] do={/ip firewall address-list add list=no-wm-cgnat address=(i);/};:local\_p1 0;:local p2 1023;:local ac netmap;:local ipa;:for i from=0 to=([:len (ip)]-1) do={:local c [:pick (ip) (i)];:if ((c) = \".\") do={:set ipa ((ipa).\",\");} else={:if ((c) = \"/\" || (c) = \"-\") do={:set ipa ((ipa).\",\");};:set ipa ((ipa).(c));:if ((c) = \"-\") do={:set ac src-nat;:set ipa ((ipa).\",\");};};};:set ipa [:toarray (ipa)];:local r;:local t;:local u;:local a;:local pl \"\";:local n none;:for i from=0 to=((d)-1) do={:set p1 (p2+1);:set\_p2 ((64511 /(d))+(p2));:if ((i) = ((d)-1)) do={:set p2 65535;};:local p (\"\\\"wm-cgnat [\".(p1).\"-\".(p2).\"]\\\"\");:local cg;:for ii from=0 to=([:len (ipa)]-1) do={:local c [:pick (ipa) (ii)];:if ((ii) = 0 || (ii) = 5 && [:pick (ipa) (4)] = \"-\") do={:set cg ((cg).\"100\");} else={:if ((ii) != 4) do={:set cg ((cg).\".\");};:if ((ii) = 1 || (ii) = 6) do={:set cg ((cg).((i)+64));} else={:set cg ((cg).(c));};};};:foreach ii in=[:toarray \"tcp,udp,all\"] do={:local h (\"\\\"wm-cgnat (jump --> \".(ii).\")\\\"\");:local j;:if ((i) = 0) do={:set j (\"/ip firewall nat add chain=srcnat action=jump jump-target=\".(h).\" dst-address-list=!no-wm-cgnat comment=\".(h));};:local f (\"/ip firewall nat add chain=\".(h).\" src-address=\".(cg).\" dst-address-list=!no-wm-cgnat action=\".(ac).\" to-address=\\\"\".(ip).\"\\\" comment=\".(p));:if ((ii) != \"all\") do={:if ((i) = 0) do={:set j ((j).\" protocol=\".(ii).\";\\n\\r\");};:set f ((f).\" to-ports=\".((p1).\"-\".(p2)).\" protocol=\".(ii));:if ((ii) = \"tcp\") do={:set t ((t).(j).(f).\";\\n\\r\");} else={:set u ((u).(j).(f).\";\\n\\r\");};} else={:if ((i) = 0) do={:set j ((j).\";\\n\\r\");};:set a ((a).(j).(f).\";\\n\\r\");};};:if ((g) = 0) do={:set r ((r).\"/ip pool add name=\".(p).\" range=\".(cg).\";\\n\\r\");:if ((i) != 0 &&\_(i) != (d)) do={:set r ((r).\"/ip pool set [find name=\".(n).\"] next-pool=\".(p).\";\\n\\r\");};} else={:set pl ((pl).(cg).\",\");};:set n (p);};:if ((g) = 1) do={:set r ((r).\"/ip pool add name=wm-cgnat range=\\\"\".(pl).\"\\\";\\n\\r\");};:set r ((r).(t).(u).(a));:put (r);[:parse (r)];};};};};";

Pronto!

Equipe RECEITANET trabalhando para impulsionar o seu crescimento!


André Andrade

Pós Graduação em Engenharia de Redes e Sistemas de telecomunicações - Inatel