<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[Artesans Digitals]]></title><description><![CDATA[Tornant del núvol a la terra]]></description><link>https://blog.lares21.xyz/</link><image><url>https://blog.lares21.xyz/favicon.png</url><title>Artesans Digitals</title><link>https://blog.lares21.xyz/</link></image><generator>Ghost 5.83</generator><lastBuildDate>Sat, 11 Apr 2026 20:46:11 GMT</lastBuildDate><atom:link href="https://blog.lares21.xyz/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Benvinguts, passeu passeu...]]></title><description><![CDATA[<p>Aix&#xF2; &#xE9;s Artesans Digitals, un lloc web al qual trobar&#xE0;s informaci&#xF3;, guies i altres publicacions relacionades amb la sobirania digital, programari lliure, com fer una millor gesti&#xF3; dels dispositius electr&#xF2;nics, trucs per millorar la seguretat en l&#xED;nia, i altres temes</p>]]></description><link>https://blog.lares21.xyz/benvinguts/</link><guid isPermaLink="false">665e10efd242c72c9151bfa0</guid><category><![CDATA[Intro]]></category><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Mon, 03 Jun 2024 18:52:31 GMT</pubDate><media:content url="https://static.ghost.org/v4.0.0/images/feature-image.jpg" medium="image"/><content:encoded><![CDATA[<img src="https://static.ghost.org/v4.0.0/images/feature-image.jpg" alt="Benvinguts, passeu passeu..."><p>Aix&#xF2; &#xE9;s Artesans Digitals, un lloc web al qual trobar&#xE0;s informaci&#xF3;, guies i altres publicacions relacionades amb la sobirania digital, programari lliure, com fer una millor gesti&#xF3; dels dispositius electr&#xF2;nics, trucs per millorar la seguretat en l&#xED;nia, i altres temes relacionats.</p><p>Parlo de com aprofitar dispositius per a tenir els teus propis serveis i dades, i no haver de pagar per &quot;el cloud&quot;. Creu-me, no cal utilitzar Google Drive.</p><figure class="kg-card kg-embed-card"><iframe src="https://tenor.com/embed/18807050" width="600" height="400" frameborder="0"></iframe></figure><p>Dedicat a tots aquells artesans digitals, curiosos i amants de la tecnologia, que vulguin alliberar-se de les cadenes a les que ens intenten lligar.</p><p>Totalment obert, gratu&#xEF;t, i en Catal&#xE0;. Per qu&#xE8; alg&#xFA; ho havia de fer.</p><p>Si est&#xE0;s cansat de que els anuncis et persegueixin, de no saber qu&#xE8; fer d&apos;aquell port&#xE0;til antic que tens tirat per casa, i tens una m&#xED;nima curiositat per a saber com protegir les teves dades davant dels gegants tecnol&#xF2;gics i el futur dist&#xF2;picament artificial al que ens estem apropant... Benvingut, aqu&#xED; t&apos;hi trobar&#xE0;s com a casa.</p><p>Tot el que trobareu aqu&#xED; s&#xF3;n recopilacions d&apos;informaci&#xF3; que jo tamb&#xE9; he trobat de forma gratu&#xEF;ta per internet. Simplement resumida i organitzada per a que sigui m&#xE9;s f&#xE0;cil d&apos;utilitzar.<br>Si alg&#xFA; us intenta cobrar per aquest material, segurament treballi a una Big4.</p><p><em>Nota: Els posts previs al juny de 2024 han sigut importats d&apos;altres plataformes on els havia compartit anteriorment.</em></p><hr><p>Per un Internet que ens faci m&#xE9;s lliures, i no m&#xE9;s oprimits, passeu, apreneu i compartiu el que creieu m&#xE9;s important amb el vostre cercle proper. Potser dem&#xE0; sereu vosaltres qui els ajudareu a alliberar-se.</p>]]></content:encoded></item><item><title><![CDATA[Nextcloud - L'alternativa a GDrive, iCloud, Calendar... i molt més]]></title><description><![CDATA[<p></p><p>Tens <strong>poc espai al Google Drive</strong>?</p><p><strong>Les fotos del m&#xF2;vil t&apos;ocupen molt</strong> per&#xF2; no les vols penjar a iCloud per si les hackegen?</p><p>Tagradaria tenir un calendari amb el qual <strong>Google no pugui accedir a tota la teva agenda personal</strong>?</p><p>Voldries <strong>enviar missatges privats i</strong></p>]]></description><link>https://blog.lares21.xyz/nextcloud-lalternativa-a-g-drive-icloud/</link><guid isPermaLink="false">6688113b180a9a061fea2052</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Fri, 05 Jul 2024 16:56:53 GMT</pubDate><media:content url="https://blog.lares21.xyz/content/images/2024/07/nextcloud-gmbh-logo-vector-2871134528.png" medium="image"/><content:encoded><![CDATA[<img src="https://blog.lares21.xyz/content/images/2024/07/nextcloud-gmbh-logo-vector-2871134528.png" alt="Nextcloud - L&apos;alternativa a GDrive, iCloud, Calendar... i molt m&#xE9;s"><p></p><p>Tens <strong>poc espai al Google Drive</strong>?</p><p><strong>Les fotos del m&#xF2;vil t&apos;ocupen molt</strong> per&#xF2; no les vols penjar a iCloud per si les hackegen?</p><p>Tagradaria tenir un calendari amb el qual <strong>Google no pugui accedir a tota la teva agenda personal</strong>?</p><p>Voldries <strong>enviar missatges privats i segurs</strong> a tots aquells amb qui comparteixes documents?</p><p>Tant si et sents identificada amb totes les preguntes anteriors, com nom&#xE9;s amb alguna, avui et porto una soluci&#xF3; sigui quina sigui la teva situaci&#xF3;.</p><p>Amb el post d&apos;avui, podr&#xE0;s deixar de fer servir les solucions tancades dels gegants tecnol&#xF2;gics, i seguir disfrutant dels serveis essencials pel teu dia a dia de forma totalment personal i privada:</p><ul><li><strong>Calendari</strong></li><li><strong>Contactes</strong></li><li><strong>Documents</strong></li><li><strong>Fotos</strong></li><li><strong>Notes</strong></li><li><strong>Xat personal i grupal</strong></li><li><strong>i molt m&#xE9;s&#x2026;</strong></li></ul><p>I tot aix&#xF2;, nom&#xE9;s amb un sol programa que podem instal&#xB7;lar de forma facil&#xED;ssima al <a href="https://blog.lares21.xyz/com-instal-lar-i-configurar-el-teu-nuvol-personal/" rel="noreferrer">nostre servidor</a>.</p><p>Aquest programa &#xE9;s <a href="https://nextcloud.com/?ref=blog.lares21.xyz">Nextcloud</a>, i a la guia d&apos;avui l&apos;instal&#xB7;larem al servidor Linux que pr&#xE8;viament hem configurat a un dispositiu allotjat a la nostra xarxa wifi de casa, i us ensenyar&#xE9; com el podeu fer servir de forma personal, o tamb&#xE9; oferir-lo com a alternativa a Google Drive, calendari personal, etc. per als vostres amics / familia / comunitat, o qui vulgueu.</p><blockquote>La seguretat i la usabilitat van de la m&#xE0;, nom&#xE9;s cal posar una mica m&#xE9;s d&apos;esfor&#xE7; del que ens han acostumat les grans corporacions intrusives</blockquote><hr><p><em><strong>Disclaimer</strong>: Aquesta gu&#xED;a NO est&#xE0; pensada per a una instal&#xB7;laci&#xF3; &#x201C;professional&#x201D; de Nextcloud per a empreses. Si voleu tenir una inst&#xE0;ncia per a la vostre empresa, recomano instal&#xB7;lar Nextcloud-AIO en comptes de la forma com ho farem en aquesta guia.</em></p><p><br><em><strong>Disclaimer</strong> <strong>2</strong>: Pr&#xF2;ximament penjare un article sobre com instal&#xB7;lar Nextcloud per a una empresa, els passos s&#xF3;n una mica m&#xE9;s extensos que a la guia d&apos;avui degut a l&apos;increment de seguretat que requereix gestionar una empresa.</em></p><hr><p>La principal difer&#xE8;ncia entre aquesta instal&#xB7;laci&#xF3; de Nextcloud i una de &quot;professional&quot;, &#xE9;s que aquesta NO la obrirem a internet. Per tant, nom&#xE9;s qui estigui connectat a la VPN (recordeu que en l&apos;article sobre com instal&#xB7;lar el nostre servidor &quot;n&#xFA;vol&quot; personal hem instal&#xB7;lat tamb&#xE9; <a href="https://tailscale.com/?ref=blog.lares21.xyz" rel="noreferrer">Tailscale</a>) o a la xarxa wifi de casa podr&#xE0; entrar a Nextcloud.</p><p>Aix&#xF2; ens proporciona alguns inconvenients, com limitar el n&#xFA;mero d&apos;usuaris que hi accedeixen, per&#xF2; a canvi ens d&#xF3;na una major seguretat per a tota la informaci&#xF3; personal que hi pengem, ja que ning&#xFA; hi podr&#xE0; accedir des d&apos;internet directament.</p><p>Mans a la obra.</p><p>Si preferiu una versi&#xF3; en angl&#xE8;s, aquesta gu&#xED;a est&#xE0; basada en la seg&#xFC;ent: <a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-nextcloud-on-ubuntu-20-04?ref=blog.lares21.xyz">https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-nextcloud-on-ubuntu-20-04</a></p><hr><h2 id="instal%C2%B7laci%C3%B3">Instal&#xB7;laci&#xF3;</h2><p>Instal&#xB7;lar Nextcloud al nostre servidor &#xE9;s molt f&#xE0;cil. Nom&#xE9;s ens hi hem de connectar per SSH i executar les seg&#xFC;ents comandes:</p><pre><code>sudo apt update
sudo apt upgrade
sudo apt install snapd
sudo snap install nextcloud</code></pre><p>Un cop executades, ja tenim nextcloud instal&#xB7;lat. Si ho volem comprovar executem <code>sudo snap info nextcloud</code>, on veurem tota la informaci&#xF3; corresponent a la instal&#xB7;laci&#xF3; (paquets addicionals, base de dades, versi&#xF3;...).</p><p>Fixeu-vos que no hem hagut d&apos;escollir res de res. Aquesta instal&#xB7;laci&#xF3; es fa per defecte al port 80 (HTTP), per tant quan accedim a la IP del nostre servidor, serem redirigits autom&#xE0;ticament a Nextcloud.</p><p><em>Nota: Oju! Si ja teniu algun altre programa executant-se al port 80, com APACHE o NGINX. &#xC9;s possible que us doni problemes en aquest cas. Si no &#xE9;s estrictament necessari, recomano desinstal&#xB7;lar NGINX o canviar-li la configuraci&#xF3; predeterminada.</em></p><p>Ara a trav&#xE9;s del nostre ordinador personal, entrem al navegador i escrivim la IP del servidor. Podem utilitzar tant la de la xarxa wifi de casa (ser&#xE0; semblant a 192.168.1.xxx) o la de Tailscale.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/07/image.png" class="kg-image" alt="Nextcloud - L&apos;alternativa a GDrive, iCloud, Calendar... i molt m&#xE9;s" loading="lazy" width="2000" height="1246" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/07/image.png 600w, https://blog.lares21.xyz/content/images/size/w1000/2024/07/image.png 1000w, https://blog.lares21.xyz/content/images/size/w1600/2024/07/image.png 1600w, https://blog.lares21.xyz/content/images/2024/07/image.png 2000w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">P&#xE0;gina inicial de Nextcloud</span></figcaption></figure><p>El primer que veurem ser&#xE0; que ens demana crear un compte d&apos;administrador. El creem i guardem les credencials segures. Aquest usuari ser&#xE0; el que haurem d&apos;utilitzar en cas de tenir algun problema. M&#xE9;s endavant crearem el nostre usuari personal.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/07/image--1-.png" class="kg-image" alt="Nextcloud - L&apos;alternativa a GDrive, iCloud, Calendar... i molt m&#xE9;s" loading="lazy" width="2000" height="1336" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/07/image--1-.png 600w, https://blog.lares21.xyz/content/images/size/w1000/2024/07/image--1-.png 1000w, https://blog.lares21.xyz/content/images/size/w1600/2024/07/image--1-.png 1600w, https://blog.lares21.xyz/content/images/2024/07/image--1-.png 2000w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Instal&#xB7;lant les apps</span></figcaption></figure><p>Seguidament ens permet escollir quines apps volem instal&#xB7;lar. Si teniu suficient espai al servidor, podeu instal&#xB7;lar totes les recomanades i m&#xE9;s endavant ja eliminareu les que no utilitzeu.</p><p>Finalment hauriem de poder veure una pantalla similar a la seg&#xFC;ent:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/07/image--2-.png" class="kg-image" alt="Nextcloud - L&apos;alternativa a GDrive, iCloud, Calendar... i molt m&#xE9;s" loading="lazy" width="2000" height="1292" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/07/image--2-.png 600w, https://blog.lares21.xyz/content/images/size/w1000/2024/07/image--2-.png 1000w, https://blog.lares21.xyz/content/images/size/w1600/2024/07/image--2-.png 1600w, https://blog.lares21.xyz/content/images/2024/07/image--2-.png 2000w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Dashboard de Nextcloud</span></figcaption></figure><p>Felicitats! Ja tenim el nostre Nextcloud operatiu! F&#xE0;cil oi?</p><p>Per&#xF2; abans d&apos;utilitzar-lo, recomano crear un certificat SSL auto-firmat. El teu navegador possiblement encara detecti que la connexi&#xF3; es insegura, per&#xF2; almenys les comunicacions amb el servidor sempre aniran xifrades.</p><p>Per fer-ho, des de la terminal del servidor executem les seg&#xFC;ents comandes:</p><pre><code>sudo ufw allow 80.443/tcp
sudo nextcloud.enable-https self-signed</code></pre><p>Ens hauria d&apos;apareixer un output similar al seg&#xFC;ent:</p><pre><code class="language-text-plain">OutputGenerating key and self-signed certificate... done
Restarting apache... done</code></pre><p>Ara si recarreguem la p&#xE0;gina al navegador, hauria de detectar el certificat. Encara que ens diu que no &#xE9;s segur, procedim per qu&#xE8; sabem que el certificat l&apos;hem signat nosaltres.</p><p><em>Si aix&#xF2; us passa amb alguna altre p&#xE0;gina web externa, no hi entreu o almenys assegureu-vos de no afegir-hi informaci&#xF3; personal, ja que aquesta pot ser interceptada.</em></p><p><strong><em>Troubleshooting</em></strong></p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/07/image-1.png" class="kg-image" alt="Nextcloud - L&apos;alternativa a GDrive, iCloud, Calendar... i molt m&#xE9;s" loading="lazy" width="1753" height="742" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/07/image-1.png 600w, https://blog.lares21.xyz/content/images/size/w1000/2024/07/image-1.png 1000w, https://blog.lares21.xyz/content/images/size/w1600/2024/07/image-1.png 1600w, https://blog.lares21.xyz/content/images/2024/07/image-1.png 1753w" sizes="(min-width: 720px) 720px"></figure><p><em>Si teniu problemes per accedir tot i haver seguit tots els passos anteriors, &#xE9;s possible que hagueu d&apos;afegir la IP de Tailscale, o fins i tot la vostre IP local com a &quot;trusted domain&quot;. Si heu afegit un nom de host per accedir-hi, tamb&#xE9; l&apos;haureu d&apos;afegir al fitxer indicat. </em></p><hr><h2 id="configuraci%C3%B3-i-usuaris">Configuraci&#xF3; i usuaris</h2><p>Seguim ara amb la creaci&#xF3; del nostre usuari personal. Anem a la cantonada superior dreta, i fem click a &quot;Usuarios&quot;.</p><p>Creem un nou usuari personal i si ho creieu oport&#xFA; li doneu permisos d&apos;administrador.</p><p>En cas d&apos;oferir aquest Nextcloud a amics / familiars / comunitat, tamb&#xE9; haureu crear els seus usuaris, ja que no hem configurat cap servidor de correu per a que els notifiqui. Haureu d&apos;afegir una contrassenya per a ells, per&#xF2; els hi haureu de fer saber que se la han de canviar un cop hi entrin. En cas que la perdin des de l&apos;usuari administrador els hi podr&#xE0;s resetejar.</p><p>I fins aqu&#xED; seria la configuraci&#xF3; b&#xE0;sica inicial.</p><p>Ara ja nom&#xE9;s us queda trastejar una mica el funcionament de Nextcloud per dins, mirar si voleu instal&#xB7;lar alguna App addicional des de la seva botiga d&apos;apps interna (totes s&#xF3;n gratu&#xEF;tes), i pujar els primers documents / fotos / contactes, o el que vulgueu.</p><hr><h2 id="sincronitzaci%C3%B3-webdav-i-apps-m%C3%B2bils">Sincronitzaci&#xF3; WebDAV i Apps M&#xF2;bils</h2><p>Un dels grans potencials de Nextcloud, &#xE9;s que podem sincronitzar una carpeta del nostre ordinador directament amb el servidor.</p><p>Per tant, no ens far&#xE0; falta entrar cada cop al navegador per a guardar fitxers, sin&#xF3; que fins i tot si estem sense connexi&#xF3;, podem estar treballant sobre un document, guardar-lo a la carpeta sincronitzada amb Nextcloud, i un cop tornem a tenir connexi&#xF3;, aquest es penjar&#xE0; autom&#xE0;ticament al nostre servidor.</p><p>Per a crear aquesta carpeta sincronitzada, primer necessitarem descarregar la Aplicaci&#xF3; de Nextcloud per escriptori (disponible per a Windows, MacOs i Linux. Tamb&#xE9; per a Android i iOS): <a href="https://nextcloud.com/es/install/?ref=blog.lares21.xyz#install-clients">https://nextcloud.com/es/install/#install-clients</a></p><p>Un cop descarregada, la obrim i hauriem de veure alguna cosa similar a la seg&#xFC;ent imatge:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/07/image-2.png" class="kg-image" alt="Nextcloud - L&apos;alternativa a GDrive, iCloud, Calendar... i molt m&#xE9;s" loading="lazy" width="1474" height="1353" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/07/image-2.png 600w, https://blog.lares21.xyz/content/images/size/w1000/2024/07/image-2.png 1000w, https://blog.lares21.xyz/content/images/2024/07/image-2.png 1474w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Nextcloud Desktop</span></figcaption></figure><p>Fem click a &quot;Iniciar Sesi&#xF3;n en tu Nextcloud&quot; i afegim la <strong><u>IP de Tailscale</u></strong> del nostre servidor. Important afegir la de Tailscale, i no la local, ja que sin&#xF3; quan no estiguem connectats al wifi de casa nostre no ens podrem connectar a Nextcloud.</p><p>Si ens diu que el certificat no &#xE9;s segur, li diem que hi confiem i continuem.</p><p>Ara ja nom&#xE9;s ens far&#xE0; falta escollir un nom per la carpeta que volem afegir al nostre ordinador, i que estigui sincronitzada amb el servidor. No us feu la vida dif&#xED;cil i poseu-li un nom f&#xE0;cil... com &quot;Nextcloud&quot; &#x1F609;.</p><p>I... voil&#xE0;! Ja tenim una carpeta sincronitzada amb el nostre servidor! Podeu comprovar que tenim els mateixos documents si accedim des de la carpeta com des del navegador:</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/07/image--3-.png" class="kg-image" alt="Nextcloud - L&apos;alternativa a GDrive, iCloud, Calendar... i molt m&#xE9;s" loading="lazy" width="1851" height="1058" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/07/image--3-.png 600w, https://blog.lares21.xyz/content/images/size/w1000/2024/07/image--3-.png 1000w, https://blog.lares21.xyz/content/images/size/w1600/2024/07/image--3-.png 1600w, https://blog.lares21.xyz/content/images/2024/07/image--3-.png 1851w" sizes="(min-width: 720px) 720px"></figure><p></p><p>Ja queda poc, ara farem el mateix per&#xF2; pels nostres dispositius m&#xF2;bils.</p><p>A trav&#xE9;s de la App Store que creieu m&#xE9;s oportuna (si &#xE9;s Android podeu utilitzar F-Droid o Aurora Store), descarregueu-vos les seg&#xFC;ents apps:</p><ul><li>Nextcloud --&gt; <em>Per als documents</em></li><li>Nextcloud Talk --&gt; <em>Per als xats</em></li><li>Nextcloud Notes --&gt; <em>Per a les notes</em></li></ul><p>Un cop descarregades, haureu de seguir el mateix procediment de connectar-vos a la IP del servidor. &#xD2;bviament necessiteu tenir Tailscale instal&#xB7;lat tamb&#xE9; al vostre m&#xF2;bil.</p><p>Amb tot l&apos;anterior, ja podeu accedir des de qualsevol dels vostres dispositius als documents, xats i notes personals sense haver d&apos;utilitzar cap aplicaci&#xF3; amb la que no confiem.</p><p>Cada cop som m&#xE9;s aprop de ser soberans amb les nostres dades, i no permetem que s&apos;utilitzin en contra nostre i/o per benefici d&apos;altri.</p><p>Heu de ser conscients que aquest pas us fa a vosaltres les principals responsables d&apos;aquestes dades, i per tant heu de planificar b&#xE9; les c&#xF2;pies de seguretat de les m&#xE9;s importants. Poc a poc anireu guanyant confian&#xE7;a en la gesti&#xF3; d&apos;aquestes, i us adonareu que &#xE9;s molt m&#xE9;s f&#xE0;cil ser nosaltres els propis responsables del que les grans corporacions ens han fet creure.</p><p>L&apos;internet &#xE9;s un lloc obert, i simplement hem de triar on i com volem utilitzar-lo. No fa falta acceptar directament tots els termes i condicions que ens posin a davant, nom&#xE9;s per qu&#xE8; &quot;&#xE9;s la opci&#xF3; f&#xE0;cil&quot; (creu-me, en realitat no ho &#xE9;s).</p><hr><h2 id="opcional-sincronitzant-el-calendari-i-contactes-del-m%C3%B2bil">Opcional: Sincronitzant el Calendari i Contactes del m&#xF2;bil</h2><p>Nextcloud ens ofereix tamb&#xE9; la opci&#xF3; de sincronitzar els nostres contactes i el calendari del nostre m&#xF2;bil, per&#xF2; s&apos;han de seguir uns passos extres, no &#xE9;s tant autom&#xE0;tic com amb les apps anteriors.</p><p>Aix&#xED; com per sincronitzar la carpeta al nostre ordinador hem utilitzat una tecnologia anomenada WebDAV, pel calendari farem servir CalDAV i pels contactes CardDAV.</p><p>Aquests s&#xF3;n protocols oberts que podem utilitzar amb altres aplicacions de codi obert que no fa falta que siguin les pr&#xF2;pies de Nextcloud (de fet, Nextcloud no en t&#xE9; cap de pr&#xF2;pia).</p><p>Un cop instal&#xB7;lats, podreu tenir el calendari del m&#xF2;bil i el del vostre ordinador sincronitzats amb totes les vostres reunions i esdeveniments, rebre notificacions, afegir recordatoris, etc. Igual que amb qualsevol altre app de Calendari, pero en comptes de donar-li la vostra agenda personal directament a l&apos;empresa que hi hagi darrere la app, aquestes dades estaran emmagatzemades al vostre servidor.</p><p>I pels contactes, &quot;m&#xE1;s de lo mismo&quot;. Quan afegiu un nou contacte, podreu emmagatzemar-lo a Nextcloud, en comptes de al vostre compte de Google, o iOS. Aix&#xED; si m&#xE9;s endavant us canvieu el m&#xF2;bil, podreu recuperar el contacte pero sense que els gegants tecnol&#xF2;gics puguin crear grafs de connexions amb els teus contactes.</p><p>B&#xE9;, prou de xerrar. Mans a la obra.</p><p>Les apps que fan falta instal&#xB7;lar al m&#xF2;bil s&#xF3;n:</p><ul><li>DAV5x - Sincronitzaci&#xF3; CardDAV i CalDAV</li><li>Etar - Calendari de codi obert&#xE7;</li></ul><p>Primer entrem a Dav5x per a crear la connexi&#xF3; pertinent amb el nostre servidor. Si ja heu seguit les seccions anteriors, aqu&#xED; ser&#xE0; el mateix. Afegir la IP de Tailscale del vostre servidor, i iniciar sessi&#xF3; a Nextcloud si us ho demana. Escolliu sincronitzar tant els contactes com el calendari (CardDAV i CalDAV).</p><p>Un cop sincronitzat, pels contactes podeu importar si ho voleu els que tingueu guardats a altres llocs, i aix&#xED; us feu una c&#xF2;pia a Nextcloud dels contactes actuals.</p><p>Pel calendari, escollim tots els calendaris que vulguem sincronitzar. Ens hauria de detectar autom&#xE0;ticament si tenim m&#xE9;s d&apos;un perfil de calendari, com &quot;Personal&quot;, &quot;Feina&quot;, &quot;Dies festius&quot;, etc.</p><p>Quan ja estiguin tots sincronitzats, ja podeu entrar a l&apos;altre aplicaci&#xF3; que hem instal&#xB7;lat, Etar.</p><p>A dins, ens dirigim a la configuraci&#xF3;, i escollim que el volem connectar a CalDAV. Aix&#xF2; ens redirigir&#xE0; a la app Dav5x i haurem d&apos;escollir quins s&#xF3;n els calendaris que volem connectar a Etar. Si no hi ha cap error inesperat, haurieu de veure tots els vostres esdeveniments del calendari tamb&#xE9; a Etar.</p><hr><h2 id="actualitzant-a-la-%C3%BAltima-versi%C3%B3">Actualitzant a la &#xFA;ltima versi&#xF3;</h2><p>Si veieu que Nextcloud s&apos;ha d&apos;actualitzar, ho podeu fer de forma molt f&#xE0;cil amb la seg&#xFC;ent comanda des de la terminal del servidor:</p><p><code>sudo snap refresh nextcloud</code></p><hr><h2 id="notes-finals">Notes finals</h2><p>Benvingut a la teva nova pila d&apos;apps sobirana. Tenir un Google pixel amb GrapheneOS no &#xE9;s suficient (tot i que molt recomanable), la tecnologia sobirana no ha de ser avorrida o inutilitzable. La seguretat i la usabilitat van de la m&#xE0;, nom&#xE9;s cal posar una mica m&#xE9;s d&apos;esfor&#xE7; del que ens han acostumat les grans corporacions intrusives i, a poc a poc per&#xF2; amb bona lletra, anir&#xE0;s guanyant confian&#xE7;a i aconseguint tornar a ser un individu sober&#xE0;.</p><blockquote>la tecnologia sobirana no ha de ser avorrida o inutilitzable<br>- Markush</blockquote><h3 id></h3><p>En cas de tenir qualsevol dubte, trobar&#xE0;s les meves dades de contacte a la p&#xE0;gina de&#xA0;<a href="https://blog.lares21.xyz/contacte" rel="noreferrer">contacte</a>.</p><p><strong><em>Si aquest blog t&apos;ha aportat valor o has apr&#xE8;s alguna cosa nova, pots ajudar-me compartint-lo a xarxes socials, o deixant-me una donaci&#xF3; a trav&#xE9;s de la icona del llamp que trobareu a la part inferior dreta.<br>S&#xED;, aqu&#xED; nom&#xE9;s s&apos;accepta Bitcoin &#x26A1;</em></strong></p>]]></content:encoded></item><item><title><![CDATA[Com instal·lar i configurar el teu servidor "núvol" personal]]></title><description><![CDATA[<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-7m7dokjnmfukgl--n7cdrg-1.gif" class="kg-image" alt="upload in progress, 0" loading="lazy" width="876" height="600" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-7m7dokjnmfukgl--n7cdrg-1.gif 600w, https://blog.lares21.xyz/content/images/2024/06/1-7m7dokjnmfukgl--n7cdrg-1.gif 876w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Passos a seguir per configurar Ubuntu Server</span></figcaption></figure><blockquote>En la actual era digital, on estem evolucionant cap a un futur dist&#xF2;pic, l&apos;auto allotjament s&apos;ha de convertir en la norma... Tornem a les arrels, per entendre per qu&#xE8; cauen les fulles.</blockquote><p>Benvinguts al primer blog</p>]]></description><link>https://blog.lares21.xyz/com-instal-lar-i-configurar-el-teu-nuvol-personal/</link><guid isPermaLink="false">665f5de2d242c72c9151c2e4</guid><category><![CDATA[homelab]]></category><category><![CDATA[privacy sanctuary]]></category><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Tue, 04 Jun 2024 19:48:29 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1601370552761-d129028bd833?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=M3wxMTc3M3wwfDF8c2VhcmNofDZ8fGNsb3VkfGVufDB8fHx8MTcxNzUzNzY4OXww&amp;ixlib=rb-4.0.3&amp;q=80&amp;w=2000" medium="image"/><content:encoded><![CDATA[<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-7m7dokjnmfukgl--n7cdrg-1.gif" class="kg-image" alt="Com instal&#xB7;lar i configurar el teu servidor &quot;n&#xFA;vol&quot; personal" loading="lazy" width="876" height="600" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-7m7dokjnmfukgl--n7cdrg-1.gif 600w, https://blog.lares21.xyz/content/images/2024/06/1-7m7dokjnmfukgl--n7cdrg-1.gif 876w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Passos a seguir per configurar Ubuntu Server</span></figcaption></figure><blockquote>En la actual era digital, on estem evolucionant cap a un futur dist&#xF2;pic, l&apos;auto allotjament s&apos;ha de convertir en la norma... Tornem a les arrels, per entendre per qu&#xE8; cauen les fulles.</blockquote><img src="https://images.unsplash.com/photo-1601370552761-d129028bd833?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=M3wxMTc3M3wwfDF8c2VhcmNofDZ8fGNsb3VkfGVufDB8fHx8MTcxNzUzNzY4OXww&amp;ixlib=rb-4.0.3&amp;q=80&amp;w=2000" alt="Com instal&#xB7;lar i configurar el teu servidor &quot;n&#xFA;vol&quot; personal"><p>Benvinguts al primer blog sobre com tenir el teu propi servidor i diverses aplicacions auto allotjades per a deixar de dependre de les grans corporacions en la gesti&#xF3; de les nostres dades.</p><hr><p>En aquesta guia, explicar&#xE9; com crear el teu propi servidor &quot;cloud&quot; des de zero. Sense utilitzar cap sistema operatiu preinstal&#xB7;lat, posarem un sistema operatiu Ubuntu Server nou al maquinari que trieu i el configurareu perqu&#xE8; tingui un dispositiu segur i llest per actuar com a servidor personal.</p><p>A mesura que hi afegeixi programari nou, seguir&#xE9; creant i penjant m&#xE9;s guies per explicar com he instal&#xB7;lat i estic utilitzant la resta de programari. Estigueu atents si voleu aprendre a convertir-vos en un ninja d&apos;Internet.</p><p><em><strong>Nota: </strong>Tot el que trobareu aqu&#xED; (fins i tot la p&#xE0;gina web que est&#xE0;s veient), est&#xE0; auto allotjat a un servidor que tinc a casa, i ho faig servir al meu dia a dia. El cost total que he invertit en aquest equipament no supera els 250 euros, incloent el mateix servidor, i perif&#xE8;rics. Si hagu&#xE9;s de pagar per a tots els serveis que hi tinc instal&#xB7;lats, en menys d&apos;un any ja hauria pagat m&#xE9;s del que m&apos;ha costat la inversi&#xF3; inicial.<br>I el valor real &#xE9;s tot el coneixement que guanyes pel cam&#xED;.<br>Si hi ha qualsevol cosa que no us quedi clara, no dubteu en contactar-me.</em></p><h2 id="problema">Problema</h2><p>Depenem en gran mesura de serveis de tercers, tant per a les nostres dades com per als nostres diners. Estem constantment sota vigil&#xE0;ncia per les nostres accions i no podem ser lliures fins que no aprenguem a utilitzar els serveis digitals de manera privada.</p><p>La constant cessi&#xF3; de les nostres dades permet que les grans corporacions facin negocis amb elles, i han de gastar cada cop m&#xE9;s materials, recursos i energia en centres de dades per gestionar-les.</p><h2 id="soluci%C3%B3">Soluci&#xF3;</h2><p>Instal&#xB7;lar serveis i aplicacions en un ordinador allotjat a casa. Deixem de regalar les nostres dades per al benefici d&apos;altri i aconseguim ser realment lliure al m&#xF3;n digital, sense perdre cap avantatge en utilitzar Internet amb els nostres propis dispositius electr&#xF2;nics.</p><p>Doneu sentit als dispositius que, en cas contrari, acabarien a la brossa, contribuint a la reducci&#xF3; de residus i fomentant la reutilitzaci&#xF3; de materials inform&#xE0;tics que acabarien obsolets. L&apos;auto allotjament de serveis i l&apos;&#xFA;s de programes de codi obert ens beneficien tant a nosaltres com al nostre planeta.</p><p>La revoluci&#xF3; comen&#xE7;a amb petits gestos. Si entenem el poder que tenim i l&apos;usem, mai m&#xE9;s ens el podran treure.</p><p>Converteix-te en un individu sobir&#xE0;.</p><hr><h2 id="instal%C2%B7laci%C3%B3">Instal&#xB7;laci&#xF3;</h2><h2 id="0-preparacions">0. Preparacions</h2><p>Abans de comen&#xE7;ar a embrutar-nos les mans (o el teclat), &#xE9;s important que tinguem tot el material necessari per construir el nostre propi servidor cloud personal. En cas contrari, haureu de c&#xF3;rrer a la vostra tenda electr&#xF2;nica de confian&#xE7;a a comprar l&apos;adaptador m&#xE9;s estrany que se us pugui oc&#xF3;rrer perqu&#xE8; el vostre servidor no t&#xE9; un port determinat.</p><p>Assegureu-vos de saber quins ports podeu utilitzar amb el vostre maquinari nou per connectar-hi les seg&#xFC;ents peces:</p><ul><li>Un port&#xE0;til antic o mini-pc (NUC, raspberry, etc.)</li><li>Monitor</li><li>Teclat</li><li>Cable Ethernet</li><li>Emmagatzematge extern (HDD o SDD) de com a m&#xED;nim 1TB</li><li>Un pendrive</li></ul><p>Un cop ho tenim tot, podem comen&#xE7;ar a preparar la nostra nova configuraci&#xF3;.</p><p>Abans de connectar-lo a la corrent, connecteu el servidor al router mitjan&#xE7;ant un cable Ethernet, connecteu l&apos;emmagatzematge extern a trav&#xE9;s d&apos;USB o SATA i connecteu tant el teclat a un port USB com la pantalla amb un cable HDMI o DisplayPort.</p><p>Tamb&#xE9;, abans d&apos;iniciar el servidor, prepararem el nou sistema operatiu que alimentar&#xE0; la vostra m&#xE0;quina. En aquest cas, utilitzarem Ubuntu Server 22.04. Podeu trobar l&apos;enlla&#xE7; de desc&#xE0;rrega aqu&#xED;: <a href="https://ubuntu.com/download/server?ref=blog.lares21.xyz" rel="noopener noreferrer">https://ubuntu.com/download/server</a></p><p>Descarregueu la versi&#xF3; m&#xE9;s recent i emmagatzmeu-la localment al vostre ordinador.</p><p>Descarregueu Balena Etcher: <a href="https://etcher.balena.io/?ref=blog.lares21.xyz" rel="noopener noreferrer">https://etcher.balena.io/</a> &#x2192; aquest programari us ser&#xE0; &#xFA;til cada vegada que vulgueu flashejar un sistema operatiu a un dels vostres dispositius.</p><p>Finalment, connecteu el vostre pendrive a l&apos;ordinador, obriu Balena Etcher i trieu el fitxer que heu acabat de descarregar (fitxer .iso d&apos;Ubuntu Server) per flashejar-lo al vostre pendrive.</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-4wpzunyvx555t1wsg89ufq.png" class="kg-image" alt="Com instal&#xB7;lar i configurar el teu servidor &quot;n&#xFA;vol&quot; personal" loading="lazy" width="800" height="482" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-4wpzunyvx555t1wsg89ufq.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-4wpzunyvx555t1wsg89ufq.png 800w" sizes="(min-width: 720px) 720px"></figure><p>Un cop finalitzat el flashejat, podeu extreure el pendrive i estarem llestos per iniciar la instal&#xB7;laci&#xF3; real del vostre servidor personal.</p><hr><h2 id="1-instal%C2%B7laci%C3%B3-del-sistema-operatiu">1. Instal&#xB7;laci&#xF3; del Sistema Operatiu</h2><p>En aquesta secci&#xF3; explicarem el proc&#xE9;s d&apos;instal&#xB7;laci&#xF3; pas a pas, incloent-hi instruccions especials per utilitzar tot el disc, per&#xF2; tamb&#xE9; un disc extern i crear una estructura de dades per muntar-lo (/mnt).</p><p><strong>ABANS</strong> d&apos;encendre el servidor per primera vegada, connecta-hi la mem&#xF2;ria USB que pr&#xE8;viament has flashejat amb Ubuntu Server.</p><p>Ara, podem engegar el servidor per primera vegada. Connecta&apos;l a la corrent i prem el bot&#xF3; d&apos;engegada, si n&apos;hi ha.</p><p>Habitualment, en el primer inici es mostrar&#xE0; autom&#xE0;ticament una finestra amb diverses opcions. En aquest moment, has de pr&#xE9;mer una de les tecles que s&apos;haurien d&apos;indicar per accedir al men&#xFA; d&apos;arrencada o simplement moure&apos;t per la llista d&apos;opcions disponibles amb les fletxes del teclat i seleccionar l&apos;opci&#xF3; d&apos;arrencada del men&#xFA;.</p><p>All&#xE0; veur&#xE0;s l&apos;opci&#xF3; d&apos;<strong>arrencar des del dispositiu extra&#xEF;ble</strong> (mem&#xF2;ria USB). Fes clic en aquesta opci&#xF3;. Ara comen&#xE7;ar&#xE0; el proc&#xE9;s de flashejar tot el sistema operatiu nou al teu servidor cloud personal.</p><p>Utilitza les tecles FLETXA AMUNT, FLETXA ABAIX i ENTER del teclat per navegar per les opcions. Segueix les instruccions seg&#xFC;ents:</p><ol><li>1. A la primera pantalla, selecciona l&apos;idioma que prefereixes (es recomana angl&#xE8;s)</li><li>2. Si hi ha disponible una actualitzaci&#xF3; del programa d&apos;instal&#xB7;laci&#xF3;, selecciona &quot;Actualitzar al nou instal&#xB7;lador&quot;, prem ENTER i espera</li><li>3. Selecciona la distribuci&#xF3; del teclat i la variant (es recomana espanyol per a usuaris nadius de castell&#xE0;. Si us hi sentiu c&#xF2;modes tamb&#xE9; podeu escollir angl&#xE8;s) i prem [done].</li><li>4. Segueix seleccionant &quot;Ubuntu Server&quot; com a base per a la instal&#xB7;laci&#xF3;, fins a [done], i prem ENTER.</li><li>5. Selecciona la connexi&#xF3; de xarxa d&apos;interf&#xED;cie que vols utilitzar (es recomana Ethernet) i anota la teva IP obtinguda autom&#xE0;ticament mitjan&#xE7;ant DHCP. (Normalment 192.168.x.xx). Prem [done] Tingues en compte que m&#xE9;s tard assignarem una <strong>IP est&#xE0;tica</strong> al servidor.</li><li>6. Deixa l&apos;opci&#xF3; seg&#xFC;ent buida si no vols utilitzar un proxy HTTP per accedir-hi. Prem [done].</li><li>7. Si no vols utilitzar un mirall alternatiu per a Ubuntu, deixa&apos;l buit i prem [done] directament.</li><li>8. A la distribuci&#xF3; d&apos;emmagatzematge, aturem-nos-hi per assegurar-nos que entenem el que estem fent aqu&#xED; (la configuraci&#xF3; del sistema de fitxers &#xE9;s MOLT important perqu&#xE8; el teu servidor funcioni correctament). Segons el teu cas, escull una de les seg&#xFC;ents opcions:<ol><li>Marca &quot;Utilitza tot el disc&quot;, <strong>si nom&#xE9;s tens una unitat d&apos;emmagatzematge</strong> principal (1+ TB). En aquest cas, assegura&apos;t que desmarques &quot;Configura aquest disc com a grup LVM&quot; abans de seleccionar [done] i pr&#xE9;mer ENTER. A continuaci&#xF3;, continua amb el pas 9. </li><li>Marca &quot;Distribuci&#xF3; d&apos;emmagatzematge personalitzada&quot;, <strong>si vols utilitzar un disc secundari</strong>, per exemple, un disc principal per al sistema i un disc secundari per a dades. Assegura&apos;t que aquest disc est&#xE0; muntat i formateja&apos;l si tens dubtes que encara pugui tenir dades que no necessites. </li></ol></li></ol><p><em>En el meu cas, vaig seguir la segona opci&#xF3; ja que tinc un disc intern per al sistema i algunes aplicacions, i un altre disc dur extern per a altres dades que vull mantenir separades del sistema principal en cas que li passi alguna cosa.</em></p><p><em>En el futur, hauries de veure el teu sistema de fitxers d&apos;una manera similar a aquesta:</em></p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-10wqfac2yaaar_1tn-tspw.png" class="kg-image" alt="Com instal&#xB7;lar i configurar el teu servidor &quot;n&#xFA;vol&quot; personal" loading="lazy" width="800" height="284" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-10wqfac2yaaar_1tn-tspw.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-10wqfac2yaaar_1tn-tspw.png 800w" sizes="(min-width: 720px) 720px"></figure><p><em>Observa com tenim el directori personal (/) muntat a la partici&#xF3; sda2, i el directori d&apos;emmagatzematge extern (/mnt) muntat a la partici&#xF3; sdb1.</em></p><ol start="9"><li>9. Confirma l&apos;acci&#xF3; destructiva seleccionant l&apos;opci&#xF3; [Continua]. Prem ENTER</li><li>10. Segueix seleccionant &quot;Ometre per ara&quot;, quan aparegui la secci&#xF3; &quot;Actualitza a Ubuntu Pro&quot;, prem ENTER al bot&#xF3; [done]</li><li>11. Tria el teu nom d&apos;usuari i contrasenya. Assegura&apos;t que no siguin f&#xE0;cils d&apos;endevinar ni contrasenyes que s&apos;hagin filtrat a internet (ho pots comprovar a <a href="https://haveibeenpwned.com/?ref=blog.lares21.xyz" rel="noreferrer">https://haveibeenpwned.com</a>). Encara que no obrim el servidor a la xarxa p&#xFA;blica d&apos;internet, la seguretat mai no s&apos;ha de menysprear.</li><li>12. Prem ENTER per marcar &quot;Instal&#xB7;lar servidor OpenSSH&quot; prement la tecla ENTER, i cap avall per seleccionar la casella [done] i prem ENTER novament</li><li>13. Si vols preinstal&#xB7;lar programari addicional (no recomanat, es poden instal&#xB7;lar m&#xE9;s tard), selecciona&apos;ls, si no, prem [done] directament per saltar al seg&#xFC;ent pas.</li><li>14. Ara es duran a terme totes les configuracions anteriors i s&apos;instal&#xB7;lar&#xE0; el sistema. Aix&#xF2; trigar&#xE0; uns minuts en funci&#xF3; del maquinari utilitzat. Pots mostrar registres extensos prement [<strong>View full log</strong>] si vols. <br>&#x231B; Espera fins que finalitzi la instal&#xB7;laci&#xF3;, quan succeeixi, apareixer&#xE0; [Reboot now]. Selecciona-ho i prem ENTER.</li><li>15. Quan el missatge et mostri &quot;Elimina el medi d&apos;instal&#xB7;laci&#xF3;, despr&#xE9;s prem ENTER&quot;, treu la mem&#xF2;ria USB del PC i prem ENTER finalment. </li></ol><p></p><p>Ja tenim el sistema operatiu instal&#xB7;lat! Ara l&apos;ordinador hauria de reiniciar-se i mostrar-te el missatge per iniciar la sessi&#xF3;. Pots desconnectar el teclat i la pantalla, i continuar connectant-te remotament des del teu ordinador habitual per continuar amb la instal&#xB7;laci&#xF3;. Si no saps com fer-ho, ho explico a la seg&#xFC;ent secci&#xF3; &#x1F447;.</p><hr><h2 id="2-acc%C3%A9s-remot-per-ssh">2. Acc&#xE9;s remot per SSH</h2><p>Connectar la pantalla i el teclat al servidor directament &#xE9;s un bon &#xFA;ltim recurs per utilitzar-lo, per&#xF2; idealment volem poder accedir-hi des de qualsevol lloc. Sobretot quan som a casa, per&#xF2; tamb&#xE9; en cas que instal&#xB7;lem algunes aplicacions que vulguem utilitzar en el nostre dia a dia, necessitem una manera de connectar-nos remotament a ell, i si &#xE9;s possible, de manera segura i privada.</p><p>Per aix&#xF2;, en lloc d&apos;utilitzar la pantalla i el teclat, ara iniciarem la sessi&#xF3; al nostre servidor a trav&#xE9;s d&apos;SSH. SSH &#xE9;s un protocol anomenat Secure SHell, que ens permet crear una connexi&#xF3; xifrada i segura entre dos dispositius.</p><p>Per fer-ho, obrirem el terminal al nostre ordinador personal i escriurem la seg&#xFC;ent comanda:</p><pre><code>ssh &lt;usuari&gt;@&lt;IP_del_servidor&gt;
</code></pre><p>L&apos;adre&#xE7;a IP del servidor es mostrar&#xE0; a la pantalla del servidor si encara el tens connectat. En cas contrari, el pots trobar mitjan&#xE7;ant una aplicaci&#xF3; de smartphone com <a href="https://www.fing.com/products/fing-app?ref=blog.lares21.xyz" rel="noopener noreferrer">Fing</a>, o utilitzant un software de CLI com Netdiscover, que detecta els dispositius que estan connectats a la mateixa xarxa que tu.</p><p>IMPORTANT: Assegureu-vos que esteu connectat a la mateixa xarxa wifi que el vostre servidor personal, en cas contrari Fing ser&#xE0; in&#xFA;til.</p><p>Un cop identificat, podeu accedir al vostre servidor a trav&#xE9;s de ssh mitjan&#xE7;ant aquesta IP i el nom d&apos;usuari que heu seleccionat pr&#xE8;viament.</p><p>Normalment les IP tenen aquest format: 192.168.XXX.XXX<br><em>Fixeu-vos en la seg&#xFC;ent imatge com al meu servidor se li ha assignat la IP 192.168.1.79 per a la interf&#xED;cie de xarxa en01.</em></p><p>Genial! Ara haur&#xED;eu d&apos;iniciar la sessi&#xF3; dins del vostre servidor! Enhorabona! &#x1F609;</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-jpsuzroxlxu2vlp9gzly8w.png" class="kg-image" alt="Com instal&#xB7;lar i configurar el teu servidor &quot;n&#xFA;vol&quot; personal" loading="lazy" width="800" height="545" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-jpsuzroxlxu2vlp9gzly8w.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-jpsuzroxlxu2vlp9gzly8w.png 800w" sizes="(min-width: 720px) 720px"></figure><p>No obstant aix&#xF2;, encara hi ha un petit problema. Aquesta manera de connectar-nos al servidor &#xE9;s genial, per&#xF2; nom&#xE9;s funciona si estem a la mateixa xarxa que el servidor. Per tant, ara per ara, nom&#xE9;s quan som a casa podem connectar-nos-hi.</p><p>Per aix&#xF2;, el primer que farem al nostre servidor &#xE9;s blindar-lo des de fora i instal&#xB7;lar una VPN privada per poder connectar-nos-hi des de qualsevol lloc sense preocupar-nos d&apos;estar exposats a internet.</p><p>Seguim!</p><hr><h2 id="3-configuracions-inicials">3. Configuracions inicials</h2><p>Per assegurar-nos que les comunicacions amb el servidor siguin segures, ara aplicarem algunes mesures de seguretat i usabilitat adequades.</p><ol><li>1. Fes que el teu usuari sigui un superusuari</li></ol><pre><code>sudo usermod -a -G sudo &lt;usuari&gt;
</code></pre><p>En aquest comandament, <code>&lt;usuari&gt;</code> substitueix-ho pel nom d&apos;usuari que has escollit durant la instal&#xB7;laci&#xF3;.</p><ol start="2"><li>2. (opcional) Inicia la sessi&#xF3; amb claus SSH &#x2013;&gt;En lloc d&apos;introduir la contrasenya del servidor cada vegada, tamb&#xE9; el podem configurar perqu&#xE8; nom&#xE9;s permeti que determinats dispositius s&apos;hi connectin.</li></ol><p>Per fer-ho, necessitem afegir la nostra pr&#xF2;pia clau SSH al fitxer .ssh/authorized_keys teclejant</p><pre><code>sudo nano .ssh/authorized_keys
</code></pre><p>i afegint-hi les nostres claus SSH.</p><p>Si no tens una clau SSH, pots crear-ne una al teu ordinador personal (no al servidor) executant aquesta comanda:</p><pre><code>ssh-keygen -t rsa -b 2048
</code></pre><p>Despr&#xE9;s, simplement copia i enganxa el contingut de la clau generada dins del fitxer authorized_keys, i estar&#xE0;s a punt per iniciar la sessi&#xF3; autenticant-te amb la teva clau SSH privada, en lloc d&apos;utilitzar la contrasenya.</p><ol start="3"><li>3. Com que en el nostre cas hem creat un directori muntat al disc connectat, li donarem permisos suficients al nostre usuari per accedir-hi sense problemes. En el nostre cas, el directori muntat a l&apos;emmagatzematge secundari &#xE9;s /mnt.</li></ol><pre><code>sudo chown &lt;usuari&gt;:&lt;usuari&gt; /mnt
</code></pre><p>En aquesta comanda, <code>&lt;usuari&gt;</code> substitueix-ho pel nom d&apos;usuari que has escollit durant la instal&#xB7;laci&#xF3;.</p><ol start="4"><li>4. Assignarem una IP est&#xE0;tica al servidor. No volem descobrir cada vegada que el connectem a una xarxa si l&apos;adre&#xE7;a IP ha canviat, per aix&#xF2; li assignarem una d&apos;est&#xE0;tica. Pots escollir la que vulguis (que encara no s&apos;utilitzi) del rang de 192.168.1.2 a 192.168.1.254.</li></ol><p>Per modificar la configuraci&#xF3; de xarxa actual, necessitem editar el seg&#xFC;ent fitxer:</p><pre><code>sudo nano /etc/netplan/00-installer-config.yaml
</code></pre><p>A continuaci&#xF3;, afegeix les seg&#xFC;ents l&#xED;nies:</p><pre><code class="language-yaml">network: 
  ethernets: 
    eno1: 
      dhcp4: false 
      dhcp6: false 
      addresses: 
      - 192.168.1.79/24 
      nameservers: 
        addresses: 
        - 9.9.9.9 
        - 149.112.112.112 
        search: [] 
      routes: 
      - to: default 
        via: 192.168.1.1 
  version: 2</code></pre><p>Si no vols que se&apos;t tanqui la sessi&#xF3; SSH actual, assegura&apos;t d&apos;utilitzar la mateixa IP que el teu router t&apos;havia assignat pr&#xE8;viament a l&apos;IP est&#xE0;tica.</p><p><em>Nota: Tamb&#xE9; he modificat els servidors de noms per utilitzar els de </em><a href="https://quad9.com/?ref=blog.lares21.xyz" rel="noreferrer"><em>Quad9</em></a><em> a causa de la major privadesa que ofereix. Pots escollir els que prefereixis, o simplement no afegir-los per a utilitzar els predeterminats.</em></p><p>Desa i tanca l&apos;editor amb CTRL+O i CTRL+X i executa la seg&#xFC;ent comanda:</p><pre><code>sudo netplan apply
</code></pre><p>Ara, la teva adre&#xE7;a IP i els servidors DNS s&apos;haurien d&apos;haver modificat.</p><p>Per comprovar-ho, pots executar <code>ip a</code>, <code>ifconfig</code> i <code>resolvectl status</code>, i hauries de veure els nous valors.</p><ol start="5"><li>5. Finalment configurarem i iniciarem el tallafoc preinstal&#xB7;lat del nostre servidor Linux; UFW (Uncomplicated Firewall) amb les seg&#xFC;ents comandes:</li></ol><pre><code class="language-shell">$ sudo ufw default deny incoming 
$ sudo ufw default allow outgoing 
$ sudo ufw allow 22/tcp comment &apos;allow SSH from anywhere&apos; 
$ sudo ufw logging off 
# Enable ufw, when the prompt shows you &quot;Command may disrupt existing ssh connections. Proceed with operation (y|n)?&quot;, press &quot;y&quot; and enter 
$ sudo ufw enable</code></pre><hr><h2 id="4-connexi%C3%B3-des-de-lexterior-tailscale">4. Connexi&#xF3; des de l&apos;exterior (Tailscale)</h2><p>Genial, gaireb&#xE9; hem acabat per avui, per&#xF2; fa falta una &#xFA;ltima cosa abans de plegar. Ara que tenim el servidor correctament protegit i configurat, seria ideal poder-hi accedir des de fora sense sacrificar la nostra privadesa. Per aix&#xF2;, utilitzarem un programari VPN privat anomenat <a href="https://tailscale.com/?ref=blog.lares21.xyz" rel="noreferrer">Tailscale</a>. Aquesta VPN &#xE9;s, en ess&#xE8;ncia, un t&#xFA;nel WireGuard que no requereix cap coneixement per configurar-lo.</p><p><em>En cas de tenir coneixements m&#xE9;s elevats, i vulgueu configurar la vostre pr&#xF2;pia connexi&#xF3; amb WireGuard, endavant! Us donar&#xE0; m&#xE9;s flexibilitat en la configuraci&#xF3; que Tailscale, tot i que aquest ofereixi certs serveis que WireGuard no fa.</em></p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/0-pqsxmyjlcljphtph.jpg" class="kg-image" alt="Com instal&#xB7;lar i configurar el teu servidor &quot;n&#xFA;vol&quot; personal" loading="lazy" width="800" height="539" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/0-pqsxmyjlcljphtph.jpg 600w, https://blog.lares21.xyz/content/images/2024/06/0-pqsxmyjlcljphtph.jpg 800w" sizes="(min-width: 720px) 720px"></figure><p>El m&#xE9;s interessant de Tailscale &#xE9;s que encara que sigui un servei de tercers per comunicar-nos amb els nostres dispositius personals, l&apos;empresa no pot veure res perqu&#xE8; tot el tr&#xE0;fic est&#xE0; xifrat de punta a punta (E2EE; End to End Encrypted). Tailscale nom&#xE9;s ajuda els nostres dispositius a identificar-se i comunicar-se entre ells de manera segura, sense comprometre les dades que envien.</p><p>Quan vulgueu crear la vostra pr&#xF2;pia xarxa privada amb Tailscale, necessitareu un compte per connectar els vostres dispositius entre ells. I aquest ser&#xE0; el compte que utilitzareu en tots ells. Tailscale ofereix diverses opcions per iniciar la sessi&#xF3;. En el meu cas, utilitzo el meu compte de Github.</p><p>Per tant, anirem al seu lloc web <a href="https://tailscale.com/?ref=blog.lares21.xyz" rel="noopener noreferrer">aqu&#xED;</a> i farem clic a &quot;Prova gratu&#xEF;ta&quot;. A continuaci&#xF3;, se&apos;ns mostrar&#xE0; l&apos;opci&#xF3; d&apos;iniciar la sessi&#xF3; i haurem de triar quin prove&#xEF;dor de serveis utilitzarem. Introdu&#xEF;u les vostres dades d&apos;autentificaci&#xF3; i haureu creat el vostre compte de Tailscale.</p><p><strong>Instal&#xB7;laci&#xF3; de Tailscale als nostres dispositius</strong></p><p>Un cop dins, volem comen&#xE7;ar a afegir dispositius nous. La manera m&#xE9;s f&#xE0;cil &#xE9;s fent clic a &quot;Afegeix dispositiu nou&quot; a la part superior esquerra del tauler d&apos;administraci&#xF3;. All&#xE0; veureu les diferents opcions en funci&#xF3; del sistema operatiu del vostre dispositiu.</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-gart0dqemipsxsuqmyewow-png.jpg" class="kg-image" alt="Com instal&#xB7;lar i configurar el teu servidor &quot;n&#xFA;vol&quot; personal" loading="lazy" width="800" height="156" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-gart0dqemipsxsuqmyewow-png.jpg 600w, https://blog.lares21.xyz/content/images/2024/06/1-gart0dqemipsxsuqmyewow-png.jpg 800w" sizes="(min-width: 720px) 720px"></figure><p>Per a dispositius m&#xF2;bils i d&apos;escriptori, podem descarregar les aplicacions Tailscale i seguir exactament el mateix procediment que hem fet fins ara. Els vostres dispositius comen&#xE7;aran a apar&#xE8;ixer al tauler de control un cop inicieu la sessi&#xF3; al vostre compte de Tailscale a trav&#xE9;s d&apos;un d&apos;ells. Per&#xF2; tingueu en compte que heu d&apos;aprovar individualment cadascun dels dispositius des del tauler d&apos;administraci&#xF3;.</p><p>Tanmateix, per als nostres servidors, &#xE9;s una mica m&#xE9;s complicat. Haur&#xE0;s d&apos;iniciar la sessi&#xF3; al servidor a trav&#xE9;s de SSH la primera vegada que el vulguis connectar a Tailscale. Un cop dins, haur&#xE0;s d&apos;executar l&apos;ordre proporcionada per Tailscale:</p><pre><code>sudo curl -fsSL https://tailscale.com/install.sh | sh
</code></pre><p>Aix&#xF2; instal&#xB7;lar&#xE0; totes les biblioteques i paquets necessaris perqu&#xE8; Tailscale funcioni correctament. Un cop finalitzada la instal&#xB7;laci&#xF3;, executa la seg&#xFC;ent comanda al terminal del servidor:</p><pre><code>sudo tailscale up
</code></pre><p>Copia l&apos;URL que et d&#xF3;na a la sortida del terminal i enganxa-la al teu navegador. Inicia la sessi&#xF3; amb el mateix compte que vas utilitzar anteriorment, i ara tindr&#xE0;s el servidor connectat a trav&#xE9;s d&apos;un t&#xFA;nel WireGuard amb els teus altres dispositius!</p><p>Magia! Sense obrir ports ni lluitar amb la configuraci&#xF3; de la xarxa!</p><p>Tanmateix, afegirem al nostre tallafoc una nova regla:</p><pre><code>sudo ufw allow in on tailscale0 
sudo ufw reload
</code></pre><p>Ara veureu que Tailscale ha assignat algunes IP als vostres diferents dispositius connectats. Aquestes IP seran les que utilitzarem per accedir a (gaireb&#xE9;) totes les nostres aplicacions allotjades per nosaltres mateixos. Connectar-s&apos;hi a trav&#xE9;s de Tailscale ofereix beneficis de seguretat i privadesa, ja que tot el tr&#xE0;fic que passa per la vostra xarxa de malla (<a href="https://ca.wikipedia.org/wiki/Xarxa_de_malla_sense_fil?ref=blog.lares21.xyz" rel="noreferrer">mesh network</a>) Tailscale ser&#xE0; xifrat de punta a punta (E2EE), de manera que ning&#xFA; podr&#xE0; espiar el vostre tr&#xE0;fic encara que estigui dins de la vostre xarxa wifi.</p><p>Si ara voleu augmentar encara m&#xE9;s la seguretat del vostre servidor permetent nom&#xE9;s l&apos;inici de sessi&#xF3; mitjan&#xE7;ant la xarxa de Tailscale, podeu seguir <a href="https://tailscale.com/kb/1077/secure-server-ubuntu-18-04/?ref=blog.lares21.xyz" rel="noreferrer">aquesta guia</a>.</p><p>Consell r&#xE0;pid: Despr&#xE9;s d&apos;aprovar el vostre dispositiu nou des del lloc web del tauler de control de Tailscale, feu clic a <em>Machine Settings &gt; Disable key expiry</em>. Aix&#xF2; garantir&#xE0; que el servidor SEMPRE estigui connectat a la vostra xarxa privada i no necessiteu tornar a casa per tornar-vos a autenticar cada dos dies.</p><hr><h2 id="5-%C3%BAltim-pas-reiniciar-el-servidor">5. &#xDA;ltim pas: reiniciar el servidor</h2><p>Doncs ja ho tens! El teu nou &quot;cloud&quot; personal est&#xE0; llest per comen&#xE7;ar a instal&#xB7;lar-hi aplicacions!</p><p>Ara el tenim protegit del tr&#xE0;fic d&apos;internet extern i ens hi podem connectar a trav&#xE9;s de Tailscale des de qualsevol lloc del m&#xF3;n.</p><p>Fem un reinici final i assegurem-nos que un cop tornem a iniciar la sessi&#xF3; tot est&#xE0; correcte. Si no &#xE9;s aix&#xED;, &#xE9;s que t&apos;has saltat algun dels passos i haur&#xE0;s de revisar quin &#xE9;s el problema que s&apos;ha de resoldre abans de continuar.</p><p>Aplica el reinici amb <code>sudo reboot now</code> i despr&#xE9;s d&apos;uns minuts, intenta iniciar la sessi&#xF3; per&#xF2; aquesta vegada utilitzant l&apos;IP de Tailscale, en lloc de la de la teva xarxa local.</p><p>Si pots iniciar la sessi&#xF3;, Tailscale funciona b&#xE9;. Ara comprova que el sistema d&apos;arxius encara est&#xE0; muntat correctament amb <code>lsblk</code> . Hauries de veure el mateix que hem vist al principi d&apos;aquest article:</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-10wqfac2yaaar_1tn-tspw.png" class="kg-image" alt="Com instal&#xB7;lar i configurar el teu servidor &quot;n&#xFA;vol&quot; personal" loading="lazy" width="800" height="284" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-10wqfac2yaaar_1tn-tspw.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-10wqfac2yaaar_1tn-tspw.png 800w" sizes="(min-width: 720px) 720px"></figure><p>En cas que el sistema ho necessiti, tamb&#xE9; aplica les actualitzacions necess&#xE0;ries. Pots comprovar-ho amb <code>sudo apt list --upgradable</code></p><p>I si tens actualitzacions pendents, executa <code>sudo apt update &amp;&amp; sudo apt upgrade</code></p><p>Despr&#xE9;s d&apos;aix&#xF2;, nom&#xE9;s puc dir-te:<br>Enhorabona. Est&#xE0;s en el cam&#xED; correcte per convertir-te en un veritable individu sober&#xE0; digital.</p><hr><h3 id="notes-finals">Notes finals</h3><p>En cas de tenir qualsevol dubte, trobar&#xE0;s les meves dades de contacte a la p&#xE0;gina de <a href="https://blog.lares21.xyz/contacte" rel="noreferrer">contacte</a>.</p><p><em>Si aquest blog t&apos;ha aportat valor o has apr&#xE8;s alguna cosa nova, pots ajudar-me compartint-lo a xarxes socials, o deixant-me una donaci&#xF3; a trav&#xE9;s de la icona del llamp que trobareu a la part inferior dreta.<br>S&#xED;, aqu&#xED; nom&#xE9;s s&apos;accepta Bitcoin &#x26A1;</em></p>]]></content:encoded></item><item><title><![CDATA[Personal server — How to setup and configure]]></title><description><![CDATA[In a digital era that is evolving to a surveillance nightmare, self hosting needs to become the norm… Get back to the roots, to understand…]]></description><link>https://blog.lares21.xyz/personal-server-how-to-setup-and-configure/</link><guid isPermaLink="false">665ee4afd242c72c9151c19f</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Sat, 11 Nov 2023 23:46:26 GMT</pubDate><media:content url="https://blog.lares21.xyz/content/images/2024/06/1-7m7dokjnmfukgl--n7cdrg.gif" medium="image"/><content:encoded><![CDATA[<figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-7m7dokjnmfukgl--n7cdrg-1.gif" class="kg-image" alt="Personal server&#x200A;&#x2014;&#x200A;How to setup and configure" loading="lazy" width="876" height="600" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-7m7dokjnmfukgl--n7cdrg-1.gif 600w, https://blog.lares21.xyz/content/images/2024/06/1-7m7dokjnmfukgl--n7cdrg-1.gif 876w" sizes="(min-width: 720px) 720px"></figure><blockquote>In a digital era that is evolving to a surveillance nightmare, self hosting needs to become the norm&#x2026; Get back to the roots, to understand the rotten leaves.</blockquote><img src="https://blog.lares21.xyz/content/images/2024/06/1-7m7dokjnmfukgl--n7cdrg.gif" alt="Personal server&#x200A;&#x2014;&#x200A;How to setup and configure"><p>In this guide I&#x2019;ll explain how to create your own home server, from scratch. Without using any pre-installed operating systems, but flashing a fresh ubuntu server into the hardware of your choice, and configuring it to have a secure and ready device to act as a home server.</p><p>As I keep adding new software into it, I&#x2019;ll keep creating and uploading more guides to explain how I&#x2019;ve installed and I&#x2019;m using the other pieces of software. Keep tuned if you want to learn how to become a sovereign Internet Ninja, and stop giving your private data to big companies, who will just benefit from you.</p><h3 id="problem">Problem</h3><p>We depend heavily on third-party services, both for our data and for our money. We are constantly under surveillance for our actions, and we cannot be free until we understand how to use digital services privately.</p><p>The constant surrender of our data allows large corporations to do business with them, and they have to spend more and more materials, resources, and energy on data centers to manage them.</p><h3 id="solution">Solution</h3><p>Install services and applications on a computer hosted at home.</p><p>Stop giving your data away for other&#x2019;s benefits and manage to be truly free in the digital world, without losing any advantages when using the Internet with our own electronic devices.</p><p>Give a purpose to devices that would otherwise end up in the trash, contributing to reducing waste and promoting the reuse of obsolete computer materials.</p><p>Self-hosting services and using open-source programs benefit both us and our planet.</p><p>Revolution begins with small gestures. If we understand the power we have and use it, it will never be taken away from us again.</p><p>Become a sovereign individual.</p><p></p><hr><h3 id="installation">Installation</h3><h4 id="0-preparations">0. Preparations</h4><p>Before starting to get our hands dirty, it is important that we have all the necessary material to build our own home server. Otherwise you&#x2019;ll need to rush to the hardware shop to buy the weirdest adapter you can think of cause your server does not have a certain port.</p><p>Make sure you know which ports you can use with your new hardware, to connect the following pieces to it:</p><ul><li>Screen</li><li>Keyboard</li><li>Ethernet Cable</li><li>External USB attached storage (HDD or SDD)</li><li>A pen drive</li></ul><p>Once we&#x2019;ve got everything, we can start preparing our new setup.</p><p>Without plugging it to the wall, connect your server to your router using an Ethernet cable, attach the external storage through USB or SATA, and connect both the keyboard on a USB port, and the screen with an hdmi or display port cable.</p><p>Now, before starting your server, we will prepare the new operating system that will power your machine. In this case, we will be using Ubuntu Server 22.04. You can find the download link here: <a href="https://ubuntu.com/download/server?ref=blog.lares21.xyz" rel="nofollow noopener">https://ubuntu.com/download/server</a></p><p>Download the latest version and store it locally on your computer.</p><p>Now also download (if you still don&#x2019;t have it) Balena Etcher: <a href="https://etcher.balena.io/?ref=blog.lares21.xyz" rel="nofollow noopener">https://etcher.balena.io/</a> &#x2192; this software will be useful each time you want to flash an operating system to one of your devices.</p><p>Finally, plug in your pen drive, open Balena Etcher, and choose the file you just downloaded (ubuntu server .iso file) to be flashed on your pen drive.</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-4wpzunyvx555t1wsg89ufq.png" class="kg-image" alt="Personal server&#x200A;&#x2014;&#x200A;How to setup and configure" loading="lazy" width="800" height="482" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-4wpzunyvx555t1wsg89ufq.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-4wpzunyvx555t1wsg89ufq.png 800w" sizes="(min-width: 720px) 720px"></figure><p>After the flashing is completed, you can remove the pen drive, and we will be ready to start the real installation of your home server.</p><hr><h4 id="1-installing-the-operating-system">1. Installing the Operating System</h4><p>Installation and walk-through of the steps, and special attention into using the full disk but also external disk and creating a data structure for it to be mounted to (/mnt).</p><p>BEFORE turning on your server for the first time, plug the USB pen drive that you previously flashed Ubuntu Server into it.</p><p>Now, we can start the server for the first time. Plug it to the electricity, and press the button to start it up if there is one.</p><p>Usually you will be automatically shown with a window to do different actions on the first boot. At this stage you either need press one of the keys that should be indicated to enter the <strong>boot menu</strong>, or simply go through the list of available options with your keyboard arrows, and click enter on the boot menu option.</p><p>There you&#x2019;ll see the option to boot from the removable device (pen drive). Click on that one. You will now start the process of flashing the full new operating system into your home server.</p><p>Use the <strong>UP</strong>, <strong>Down,</strong> and <strong>ENTER</strong> keys of your keyboard to navigate to the options. Follow the next instructions:</p><p><strong>1.</strong> On the first screen, select the language of your choice <strong>(English recommended)</strong></p><p><strong>2.</strong> If there is an installer update available, select <strong>&#x201C;Update to the new installer&#x201D;</strong>, press <strong>enter,</strong> and wait</p><p><strong>3.</strong> Select your keyboard layout and variant <strong>(Spanish recommended to Spanish native speakers)</strong> and press [<strong>done]</strong></p><p><strong>4.</strong> Keep selecting <strong>&#x201C;Ubuntu Server&#x201D;</strong> as the base for the installation, down to [<strong>done],</strong> and press <strong>enter</strong></p><p><strong>5.</strong> Select the interface network connection that you choose to use <strong>(Ethernet recommended)</strong> and <strong>take note of your IP</strong> obtained automatically through DHCP. (Normally 192.168.x.xx). Press [<strong>done]</strong><br><em>note that we will be assigning a static IP to the server later</em></p><p><strong>6.</strong> Leave the empty next option if you don&#x2019;t want to use an HTTP proxy to access it. Press [<strong>done]</strong></p><p><strong>7.</strong> If you don&#x2019;t want to use an alternative mirror for Ubuntu, leave it empty and press [<strong>done]</strong> directly</p><p>8. On the storage layout, let&#x2019;s stop a little bit more and make sure we understand what we&#x2019;re doing here (the filesystem configuration is VERY important for your server to operate correctly).</p><blockquote><em><strong>8.1.</strong> Check <strong>&#x201C;Use an entire disk&#x201D;</strong>, if you have <strong>only one primary unit storage (1+ TB)</strong>. In this case, ensure that you <strong>uncheck &#x201C;Set up this disk as an LVM group&#x201D;</strong> before select [<strong>done]</strong> and press <strong>enter</strong>. Then, continue with <strong>step 9</strong>.</em></blockquote><blockquote><em><strong>8.2.</strong> Check <strong>&#x201C;Custom storage layout&#x201D;</strong>, if you want to use one <strong>secondary</strong> disk, e.g. primary for the system and secondary disk for data. Make sure this disk is <strong>mounted</strong>, and format it if you have doubts that it could still have data that you don&#x2019;t need.</em></blockquote><p>In my case, I followed the 2nd option as I have an internal disk for the system, and some of the apps, and another external HDD disk for other data that I want to keep separated from the main system in case something happens to it.</p><p><em>In the future, you should see your filesystem in a similar way to this one:</em></p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-10wqfac2yaaar_1tn-tspw.png" class="kg-image" alt="Personal server&#x200A;&#x2014;&#x200A;How to setup and configure" loading="lazy" width="800" height="284" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-10wqfac2yaaar_1tn-tspw.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-10wqfac2yaaar_1tn-tspw.png 800w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Linux filesystem</span></figcaption></figure><p><em>Check out how we have both the home directory (/) mounted on the sda2 partition, and the external storage directory (/mnt) mounted on the sdb1 partition.</em></p><p><strong>9.</strong> Confirm destructive action by selecting the [<strong>Continue]</strong> option. Press <strong>enter</strong></p><p><strong>10.</strong> Keep selecting <strong>&#x201C;Skip for now&#x201D;,</strong> when the <strong>&#x201C;Upgrade to Ubuntu Pro&#x201D;</strong> section appears you press <strong>enter</strong> on the <strong>done</strong> button</p><p>11. Choose your <strong>username and password</strong>. Make sure they are not easy to guess or passwords that may have been leaked on the internet. Even if we will not be opening the server to the public internet, security should never be disregarded.</p><p><strong>12.</strong> Press <strong>enter</strong> to check <strong>&#x201C;Install OpenSSH server&#x201D;</strong> by pressing the <strong>enter</strong> key, and down to select the [<strong>Done]</strong> box and press <strong>enter</strong> again</p><p><strong>13.</strong> If you want to preinstall some additional software <strong>(not recommended</strong>, they can be installed later<strong>)</strong>, select them, if not, press [<strong>done]</strong> directly to jump to the next step.</p><p><strong>14.</strong> Now all before configurations will be applied and the system installed. This would be a few minutes depending on the hardware used. You can show extended logs by pressing <strong>[View full log]</strong> if you want.</p><p>&#x231B; Wait until the installation finishes, when it happens, [<strong>Reboot now]</strong> will appear. Select it and press <strong>enter</strong>.</p><p><strong>15.</strong> When the prompt shows you <strong>&#x201C;Please remove the installation medium, then press ENTER&#x201D;</strong>, extract the pen drive of the PC and press <strong>enter</strong> finally.</p><p>Now the PC should reboot and show you the prompt to log in. You can disconnect the keyboard and the screen, and proceed to connect remotely from your regular computer to continue with the installation.</p><hr><h4 id="2-acessing-remotely-ssh">2. Acessing remotely (SSH)</h4><p>Connecting the screen and keyboard to the server directly are a good last resource to use it, but ideally we want to be able to access it from anywhere. Specially when we are next to it at home, but also in case we install some apps that we want to use in our day to day, we need a way to connect remotely to it, and if possible, secure and privately.</p><p>That&#x2019;s why instead of using the screen and keyboard, we will now log in to our server through <strong>SSH</strong>. SSH is a protocol called Secure SHell, which allows us to create an encrypted and secure connection between two devices.</p><p>To do so, we will open the terminal in our personal computer, and type the following command:</p><pre><code class="language-xml">ssh &lt;user&gt;@&lt;server-IP&gt;</code></pre><p>The server IP will be shown in your server screen if you still have it plugged. Otherwise you can find it by using an app like <a href="https://www.fing.com/products/fing-app?ref=blog.lares21.xyz" rel="nofollow noopener">https://www.fing.com/products/fing-app</a> , which detects the devices that are connected in the same network as you are.</p><p><strong>IMPORTANT: </strong>Make sure you are connected to the same wifi as your personal server, otherwise Fing will be useless.</p><p>Once identified, you can access your server through ssh using that IP and the username you chose previously.</p><p><em>Usually the IP&#x2019;s have this form: 192.168.XXX.XXX</em></p><p>Cool! Now you should be logged inside your server! Congrats &#x1F609;</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-jpsuzroxlxu2vlp9gzly8w.png" class="kg-image" alt="Personal server&#x200A;&#x2014;&#x200A;How to setup and configure" loading="lazy" width="800" height="545" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-jpsuzroxlxu2vlp9gzly8w.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-jpsuzroxlxu2vlp9gzly8w.png 800w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Ubuntu Server login&#xA0;message</span></figcaption></figure><p>However, there is still one little problem. This way of connecting to the server is cool, but only works if we find ourselves in the same network as the server. So effectively, only when we are home we can connect to it.</p><p>That&#x2019;s why <strong>the first thing that we will do to our server, is blind it from the outside, and install a private VPN</strong> to be able to connect to it from the outside without worrying on being exposed to the internet.</p><p>Let&#x2019;s keep going!</p><hr><h4 id="3-initial-configurations">3. Initial Configurations</h4><p>To make sure our communications with the server are secure, we will now apply some security and proper usability measures.</p><ol><li>Make your user a super user</li></ol><pre><code class="language-css">sudo usermod -a -G sudo &lt;user&gt;</code></pre><p>2. (optional) Login with SSH keys</p><p>Instead of entering our server password each time, we can also configure it to ONLY allow certain devices to connect to it.</p><p>To do so, we need to add our own SSH key into the <code>.ssh/athorized_keys</code> by typing</p><pre><code class="language-bash">sudo nano .ssh/authorized_keys</code></pre><p>and adding our SSH keys into it. If you don&#x2019;t have an SSH key, you can create one by executing this command:</p><pre><code class="language-css">ssh-keygen -t rsa -b 2048</code></pre><p>Then simply copy paste the content of the generated key inside the authorized_keys file, and you&#x2019;ll be ready to log in authenticating with your private SSH key, instead of using the password.</p><p>3. Since in our case we have created a directory mounted in the attached disk, we will give enough permissions to our user to access it without problems. In our case, the mounted directory in the secondary storage is /mnt.</p><pre><code class="language-ruby">sudo chown &lt;user&gt;:&lt;user&gt; /mnt</code></pre><p>4. We&#x2019;ll start with assigning a static IP to our server. We don&#x2019;t want to discover each time we connect it to a network if the IP has changed, so that&#x2019;s why we will assign a static one to it. You can choose the one you want (that is not already in use) on the range from 192.168.1.2 to 192.168.1.254.</p><p>To modify the current network configuration, we need to edit the following file:</p><pre><code class="language-bash">sudo nano /etc/netplan/00-installer-config.yaml</code></pre><p>And add the following lines:</p><pre><code class="language-yaml">network: 
  ethernets: 
    eno1: 
      dhcp4: false 
      dhcp6: false 
      addresses: 
      - 192.168.1.79/24 
      nameservers: 
        addresses: 
        - 9.9.9.9 
        - 149.112.112.112 
        search: [] 
      routes: 
      - to: default 
        via: 192.168.1.1 
  version: 2</code></pre><p>If you don&#x2019;t want to break your current ssh session, make sure to use the same IP that you were assigned previously by your router to the static IP.</p><p><em>Note: I&#x2019;ve also modified the nameservers to use the Quad9 ones due to higher privacy in their end. You can choose the ones you prefer.</em></p><p>Save and close the editor, and run the following command:</p><pre><code class="language-typescript">sudo netplan apply</code></pre><p>Now your IP address and DNS servers should be modified.</p><p>To check it you can either run <code>ip a</code> , <code>ifconfig</code> and <code>resolvectl status</code> , and you should see the new values there.</p><p>5. Finally we will configure and start the pre-installed firewall from our linux server: UFW (Uncomplicated Firewall).</p><p>Run the following commands:</p><pre><code class="language-shell">$ sudo ufw default deny incoming 
$ sudo ufw default allow outgoing 
$ sudo ufw allow 22/tcp comment &apos;allow SSH from anywhere&apos; 
$ sudo ufw logging off 
# Enable ufw, when the prompt shows you &quot;Command may disrupt existing ssh connections. Proceed with operation (y|n)?&quot;, press &quot;y&quot; and enter 
$ sudo ufw enable</code></pre><hr><h4 id="5-connecting-from-the-outside-tailscale">5. Connecting from the outside (Tailscale)</h4><p>Alright, we&#x2019;ll be almost done for today, but there is one last thing missing.</p><p>Now that we have our server properly secured and configured, it would be ideal to be able to access it from the outside without sacrificing our privacy.</p><p>That&#x2019;s why we will be using a private VPN software called Tailscale. This VPN is effectively a WireGuard tunnel that requires 0 knowledge to set up.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/0-pqsxmyjlcljphtph.jpg" class="kg-image" alt="Personal server&#x200A;&#x2014;&#x200A;How to setup and configure" loading="lazy" width="800" height="539" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/0-pqsxmyjlcljphtph.jpg 600w, https://blog.lares21.xyz/content/images/2024/06/0-pqsxmyjlcljphtph.jpg 800w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Photo by </span><a href="https://unsplash.com/@privecstasy?utm_source=medium&amp;utm_medium=referral" target="_blank" rel="photo-creator noopener"><span style="white-space: pre-wrap;">Privecstasy</span></a><span style="white-space: pre-wrap;"> on&#xA0;</span><a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral" target="_blank" rel="photo-source noopener"><span style="white-space: pre-wrap;">Unsplash</span></a></figcaption></figure><p>The cool thing, is that even if we use a 3d party service to communicate with our personal devices, they cannot see anything cause <strong>all the traffic is End to End Encrypted (E2EE)</strong>. Tailscale just helps our devices identify them, and communicate between them securely, without compromising the data that they are sending.</p><p>When you want to create your own private network with Tailscale, you&#x2019;ll need to use an account to connect to your devices between them. And this will be the account that you&#x2019;ll use in all of them.</p><p>Tailscale offers a variety of different options to log in. In my case I&#x2019;m using Github.</p><p>So we&#x2019;ll go to their website <a href="https://tailscale.com]%28https://tailscale.com%29" rel="nofollow noopener">https://tailscale.com</a> and click on &#x201C;Try for free&#x201D;.</p><p>Then we&#x2019;ll be prompted with the option to log in, and we&#x2019;ll need to choose which service provider we&#x2019;ll be using.</p><p>Enter your authentication details, and you&#x2019;ll have created your tailscale account.</p><h4 id="installing-tailscale-on-our-devices"><strong>Installing Tailscale on our devices</strong></h4><p>Once inside, we want to start adding new devices.</p><p>The easiest way is by clicking on &#x201C;Add new device&#x201D; on the top left part of your admin dashboard. You&#x2019;ll see there the different options depending on your device operating system.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-gart0dqemipsxsuqmyewow-png.jpg" class="kg-image" alt="Personal server&#x200A;&#x2014;&#x200A;How to setup and configure" loading="lazy" width="800" height="156" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-gart0dqemipsxsuqmyewow-png.jpg 600w, https://blog.lares21.xyz/content/images/2024/06/1-gart0dqemipsxsuqmyewow-png.jpg 800w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Tailscale dashboard</span></figcaption></figure><p>For mobile, and desktop clients, we can download the Tailscale apps, and simply go through the same procedure we&#x2019;ve done up until now.</p><p>Your devices will start appearing in your dashboard as soon as you log in to your tailscale account through one of them. But take into account that you must individually <strong>approve</strong> each one of the devices from your administration dashboard.</p><p>However, for our servers, it&#x2019;s a little bit more tricky. We will need to log in to our server through ssh the first time we want to connect it to tailscale.</p><p>Once we&#x2019;re inside, we will need to execute the command provided by tailscale:</p><pre><code class="language-bash">sudo curl -fsSL https://tailscale.com/install.sh | sh</code></pre><p>This will install all the libraries and packages needed for tailscale to run properly. After the installation is complete, run the following command in your server&#x2019;s terminal:</p><pre><code class="language-typescript">sudo tailscale up</code></pre><p>Copy the URL that it gives you in the terminal output, and paste it in your browser. Log in with the same account you used previously, and you&#x2019;ll now have your server connected through a WireGuard Tunnel with your other devices!</p><p>Voil&#xE0;, without opening ports, or fighting with your network settings!</p><p>However, we will indicate to our firewall a new rule:</p><pre><code class="language-csharp">sudo ufw allow in on tailscale0 
sudo ufw reload</code></pre><p>Now you&#x2019;ll see that Tailscale has assigned some IPs to your different connected devices. This IPs will be the ones we will use to access (almost) all our self-hosted applications. Connecting to them through Tailscale brings security and privacy benefits, as all the traffic that goes through your mesh Tailscale network, will be E2EE, so no one can eavesdrop on your traffic even if they are inside your home network.</p><p>If you would like now to even increase the security of your node by only allowing to log in using Tailscale, you can follow this guide: <a href="https://tailscale.com/kb/1077/secure-server-ubuntu-18-04/?ref=blog.lares21.xyz" rel="nofollow noopener">https://tailscale.com/kb/1077/secure-server-ubuntu-18-04/</a></p><p><strong>Quick tip:</strong> After approving your new device from the Tailscale dashboard website, click on <em>Machine Settings &gt; Disable key expiry</em>. This will ensure that the server is ALWAYS connected to your private network, and you don&#x2019;t need to go home to reauthenticate every a couple of days.</p><hr><h4 id="6-final-check-%E2%80%94-rebooting">6. Final Check&#x200A;&#x2014;&#x200A;Rebooting</h4><p>There you are, your new personal home server is ready to start installing apps into it!</p><p>We now have it protected from the outside internet traffic, and we can connect to it through Tailscale from anywhere in the world.</p><p>Let&#x2019;s make a final reboot, and make sure that once we log in again everything is correct. If not, you missed some of the steps and should check out what&#x2019;s the problem that needs to be solved before proceeding!</p><p>Apply the reboot with <code>sudo reboot now</code> and after some minutes, try logging in but this time using the Tailscale IP, instead of your local network one.</p><p>If you manage to log in, Tailscale is working fine. Now check that the filesystem is still correctly mounted with <code>lsblk</code> and in case the system needs it, apply the necessary updates.</p><p>After this, I can only say: Congrats. You&#x2019;re on the correct path of becoming an Internet Ninja.</p>]]></content:encoded></item><item><title><![CDATA[Internet Educational Series #10: Routing]]></title><description><![CDATA[How do routers connect between them? How do they find the best way to send a message through the Internet?]]></description><link>https://blog.lares21.xyz/internet-educational-series-10-routing/</link><guid isPermaLink="false">665ee4afd242c72c9151c1a9</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Wed, 14 Jul 2021 07:07:48 GMT</pubDate><media:content url="https://blog.lares21.xyz/content/images/2024/06/0-u8ooxsj7g0bg5nrw.jpg" medium="image"/><content:encoded><![CDATA[<h4 id="1-shortest-path-algorithms-spas">1. Shortest Path Algorithms (SPAs)</h4><img src="https://blog.lares21.xyz/content/images/2024/06/0-u8ooxsj7g0bg5nrw.jpg" alt="Internet Educational Series #10: Routing"><p>In graph theory, the shortest path problem is the problem of finding a path between two vertices (or nodes) in a graph such that the sum of the weights of its constituent edges is minimized. Common algorithms for solving the shortest path problem include the Bellman-Ford algorithm and Dijkstra&#x2019;s algorithm.</p><h4 id="bellman-ford">Bellman-Ford</h4><p>This algorithm aims to find the shortest path to go from a source (s) to any destination in a certain topology.</p><p>Topologies are composed of vertex (nodes) and edges (links).</p><p>There are 2 different versions of topologies. Centralized ones, where the source node knows the whole topology, and <strong>distributed</strong> ones. In the latest version, a node wants to compute the shortest path to other nodes, but without knowing the whole topology, the source node will only have the estimated distances provided by its neighbors.</p><p>To explain it in plain words, the neighbor nodes exchange their <strong>vector of distances</strong> between them:</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-kb6r_akqd0pus1eyv_fvcg.png" class="kg-image" alt="Internet Educational Series #10: Routing" loading="lazy" width="277" height="139"></figure><p>When a node <em>u</em> receives the vector of distances <em>dk</em> from its neighbor <em>k</em>. it can use the distances on this vector to relax the edge to this neighbor <em>(u,k)</em>.</p><p>Let&#x2019;s see an example of a topology that uses the distributed version of BF to show the distribution of the route to the node <em>a</em>. You&#x2019;ll see the update messages and the route to the node <em>a</em> that each node learns when the <em>distance vectors</em> are exchanged between them.</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-56u_digds5isgxh1fnvrag.png" class="kg-image" alt="Internet Educational Series #10: Routing" loading="lazy" width="444" height="216"></figure><p>Notice the decentralized computation: <em>d</em> sends only the <strong>best path</strong> to <em>a</em>.</p><p>Process:</p><ul><li><em>b</em> relaxes <em>(a,b)</em> and sends the update to its neighbors.</li><li><em>d</em> receives the previous update from <em>b</em> and then relaxes <em>(d,b)</em> and sends the update to its neighbors.</li><li><em>g</em> receives the previous update from <em>d</em> and then relaxes <em>(g, d)</em> and sends the update to its neighbors.</li><li><em>h</em> receives the previous update from <em>g</em> and relaxes <em>(h,g)</em>.</li></ul><p>See how the algorithm converges to the optimal solution (shortest path) because this decentralized process? It runs BF in an end-less loop in which each node relaxes its edges.</p><p>Once all nodes have sent and received update messages it turns out to be like an iteration of the centralized algorithm.</p><h4 id="dijkstra">Dijkstra</h4><p>This is another algorithm to find the shortest path to go from a source (s) to any destination in a certain topology.</p><p>The difference between this one and BF, is that Dijkstra only works in topologies that are <strong>free of edges with negative weights</strong>.</p><p>Let&#x2019;s see an example of how Dijkstra algorithm works in the following topology:</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-tsux9sbscz_b154r8akdww.png" class="kg-image" alt="Internet Educational Series #10: Routing" loading="lazy" width="357" height="190"></figure><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-zpajsnz57w_wnh3xood-ea.png" class="kg-image" alt="Internet Educational Series #10: Routing" loading="lazy" width="800" height="175" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-zpajsnz57w_wnh3xood-ea.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-zpajsnz57w_wnh3xood-ea.png 800w" sizes="(min-width: 720px) 720px"></figure><p>When we initialize the algorithm, there are no sources, and the only &#x201C;reachable&#x201D; destination is node1.</p><ul><li>In the first iteration, we find the distance between 1&#x2013;2 and 1&#x2013;3. The path cell tells us that the only &#x201C;shortest path&#x201D; available now is how to reach node1 (only 1 hop without weight).</li><li>Extract 2 shows that we do now have 2 sources to reach the nodes 3, 4 and 5, and that the shortest path uses nodes 1 and 2 to reach node 5.</li><li>Extract 5 has node 5 as a source now. However instead of going for node4, it detects that now the shortest path (the one with less weight) is node3, so it adds the distance to reach node3 from node1, instead of adding the distance to the direct neighbor from the previous extract.</li><li>Extract 3 is the last one that is looking for a route to reach the only missing node (4). It calculates that the shortest path to reach node 4 is through nodes 2 and 5, instead of node 3.</li><li>Finally we do have all the distances between the nodes from the topology, and the shortest paths to reach each one of them.</li></ul><hr><p>Great, now that you have had a quick glimpse on SPAs, let&#x2019;s get into the real matter of this article. Routing Information Protocol (RIP).</p><h4 id="2-rip">2. RIP</h4><p>The Routing Information Protocol is a dynamic routing protocol that is used in small/medium IP networks. It is based on a <strong>distance-vector exchange</strong>, and a <strong>distributed version of BF</strong>.</p><p>RIP has been evolving during the years, and new versions have been surging, like RIPv2, RIPng (RIP next generation), which has been adapted for IPv6, and lately another protocol called OSPF has been gaining popularity. However, to understand all of the above, we need to know how the basic form of routing works.</p><p>RIP, like any other routing protocol, defines a r<strong>outing database</strong>, a <strong>protocol for exchanging information about routes</strong> and an <strong>algorithm for updating routing information</strong>.</p><p>We will describe these three parts below:</p><h4 id="21-routing-database">2.1 Routing Database</h4><p>Each RIP entity (normally routers) keep track in its routing database of all networks (and possibly individual hosts) in the RIP routing domain.</p><p>Each entry in the routing database includes the next intermediary router (called next hop) to which datagrams have to be delivered so that they can reach the final destination. In addition, the routing database includes a metric for measuring the total distance to the final destination.</p><p>The fields specified in the routing database are:</p><ul><li><strong>Address</strong>. Destination network or host. (@IP/MASK)</li><li><strong>Metric</strong>. The metric or cost from that node to the destination.*</li><li><strong>Router</strong>. Next-hop to reach the destination network or host.</li><li><strong>Interface</strong>. The network interface that must be used to reach the next router.</li><li><strong>Timers</strong>. Used to manage dynamics of the routing information.</li></ul><p>*The metric is basically the number of hops to the destination. A datagram makes a hop when it goes through a router. For example, if a RIP entity is directly connected to its destination, the distance is 1 hop, but if the source and destination are connected through another intermediary router, then the distance is 2 hops.</p><p>The valid metrics range is between 1 and 16 hops, however the maximum number of hops allowed for any destination is 15, and the distance 16 is reserved for &#x201C;infinity&#x201D;, in other words, destination unreachable.</p><h4 id="22-updating-algorithm">2.2 Updating Algorithm</h4><p>This is the part where RIP gets fun (at least for coders/technical people ;) ).</p><p>Distance vectors algorithms get their name from the fact that it is possible to compute optimal routes by periodically exchanging the vector of distances to the different destinations that each node in the network has.</p><p>The Routing Database of each RIP node is initialized with a description of the RIP entities that are directly connected (next-hop=1), and then it updates with a distributed version of BF.</p><p>However, what happens if the network we are in changes, a RIP entity disconnects, disappears, or another entity gets inside the network and then there is a better optimal path?</p><p>Let&#x2019;s first explain how the algorithm behaves in a <strong>static topology</strong>, and then we&#x2019;ll dive deeper into <strong>dynamic topologies</strong> and the problems that we may find.</p><h4 id="static-topology">Static Topology</h4><p>Let&#x2019;s first define some variables. <em>w(i,k)</em> is the weight or cost of the edge that connects nodes <em>i</em> and <em>k</em>. So <em>w(i, k)</em> = 1 if <em>i</em> and <em>k</em> are directly connected and <em>w(i, k)</em> = 16 (infinity) if they are not. Moreover, <em>m(P(i,j))</em> as the best current metric for the path or route between i and j.</p><p>The Bellman-ford equation and it says that &#x201C;the best route is through the neighbor that has the minimum distance to the destination&#x201D;.</p><p>So, when a RIP entity <em>i</em> receives the distance vector <em>dk</em> with the estimates of neighbor <em>k</em>, it adds <em>w(i, k)</em> to each of the estimations received. Then, for each destination <em>n</em>, the node <em>i</em> compares the metric provided by the neighbor with its current routing entry metric for this destination <em>R(n).metric.</em> The node picks the new route if the metric provided by the neighbor is smaller. With this algorithm, after receiving estimates from all the nodes in the network, <em>i</em> will have the smallest distance to all the destinations.</p><h4 id="dynamic-topology">Dynamic Topology</h4><p>Decrease the metric</p><p>The method so far only has a way to lower the metric, as the existing metric is kept until a smaller one shows up.</p><p>However, it is possible that the initial estimate might be too low. In this case, we need a method for &#x201C;increasing the metric&#x201D;.</p><p>For this purpose, it is enough to always consider the information <strong>received by the next hop</strong> of a route. For example, suppose the current route to a destination has metric D and uses router R. If a new set of information arrived from some source other than R, only update the route if the new metric is better than D. But if a new set of information arrives from R itself, always update D to the new value.</p><p>Updates</p><p>It is safe to run the algorithm asynchronously, that is, each RIP entity can send updates with its distance vector according to its own clock. The algorithm will converge to the correct distances in finite time in the absence of topology changes.</p><p>Originally each RIP router transmitted full updates every 30 seconds. In the early deployments, routing tables were small enough that the traffic was not significant. As networks grew in size, however, it became evident there could be a massive traffic burst every 30 seconds, even if the routers had been initialized at random times.</p><p>Modern RIP implementations introduce deliberate variation into the update timer intervals of each router.</p><p>Example</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-n5yrzwpgpwpq9ykhpv_mzg.png" class="kg-image" alt="Internet Educational Series #10: Routing" loading="lazy" width="594" height="320"></figure><p>As you can see, N1 is connected to RA and RB. We are going to illustrate how the information about Network 1 (N1) can be distributed by RIP. As the order of the RIP updates is randomly distributed (unpredictable), the description that follows is just a possible realization of the RIP update process.</p><p>Let&#x2019;s go step by step:</p><p>(1) As initial condition we assume that the only routers that have information about N1 are the two directly connected routers (RA and RB). Then, RA is the first router to send information about N1 in a RIP message (in this case, but RB could also be the first one). We will note this information as {N1,1}, which means that the RIP message sent by RA includes an entry for N1 showing that this router can reach this network with one hop. RA sends this RIP message to its one-hop neighbors: RB and RC. Upon receiving this information, RC updates its routing database because the information received by RA informs about a new reachable network. RB does nothing because it already knows N1 with a better (shorter) path.</p><p>(2) RC decides that it has to send a RIP message and it includes the new information it knows about N1. This information is that it can reach N1 with two hops {N1,2}. RC sends this information to its one-hop neighbors: RA and RD. In the case of RD, this is the first time it hears about N1, so it updates its routing database with the new information. Obviously, RA does nothing.</p><p>(3) This time RB sends its RIP message including the entry {N1,1} to its one-hop neighbors: RA and RD. RA does nothing, but RD updates its routing database because the new information from RB provides a shortest path to the destination than the previous one that RD possessed.</p><p>(4) This time RD sends its RIP message but nobody does nothing because the information provided by the router is worse than the information present at the routing databases of the rest of the routers (this is logical because RD is the farthest router).</p><p><strong>BROKEN LINK</strong></p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-casrycvu2tsfzj_5bamxna.png" class="kg-image" alt="Internet Educational Series #10: Routing" loading="lazy" width="594" height="324"></figure><p>Now, we are going to assume that one of the links is broken. In particular, the link that connected RB to N1.</p><p>In this case, we are going to observe that some nodes have too low estimations for N1 and we will see how nodes use the method for increasing the metric. The description that follows is a possible realization of the RIP update process:</p><p>(1) As an initial condition, we assume that all the routers have converged to the topology depicted in the first example. Thus, they have entries for N1. Then, RB detects that its link to N1 is broken. At this moment, RB updates the entry for N1 in its database setting the metric for this network to infinity (16).</p><p>(2) RA sends a RIP message to its one-hop neighbors: RB and RC. Upon receiving this information, RB updates its routing database because the information received by RA informs about a new path to reach again the network N1. RC does nothing because it already knows N1 with the same metric.</p><p>(3) At this time RB sends a RIP message to its one-hop neighbors: RA and RD. RA does nothing, but RD updates its routing database because although the information received contains a worse metric, it comes from the next hop router. Recall that according to the &#x201C;increasing metric method&#x201D;, we always have to update our routing entries when the information comes from the next hop. Notice also that this can be interpreted as an indication that our estimate for N1 is currently too low. Indeed, with the new network topology, RD cannot reach N1 with just two hops.</p><h4 id="23-improvements">2.3 Improvements</h4><p>In practice, routers and lines often fail and come back up. To properly handle dynamisms the algorithm presented so far is not yet suitable and some enhancements are required.</p><p>1. TIMERS</p><p>Notice that if a certain router X is included in the best route to a certain destination of some other router Y , and the router X is no longer available (for example because it crashed or because some network connection to it is broken), the algorithm explained so far might never reflect the change to router Y . The algorithm as shown so far depends upon routers notifying its neighbors if their metrics change. In order to handle problems of this kind, distance vector protocols must make some provision for timing out routes. For this purpose, there are two timers associated with each route: a &#x201C;timeout&#x201D; and a &#x201C;garbage-collection&#x201D; time.</p><ul><li>The <strong>timeout</strong> is used to limit the amount of time a route can stay in a routing database without being updated. Recall that RIP entities have to send update messages approximately every 30 seconds. The timeout is initialized to 180 seconds whenever a new route is established and is reset to the initial value whenever an update is heard for that route. If an update for a route is not heard within that 180 seconds (six update periods), the hop count for the route is changed to 16, marking the route as unreachable.</li><li>The other timer, the <strong>garbage collection timer</strong>, is used to make help neighbors making them know that the route is no longer valid. An unreachable route will be advertised with the infinite metric (16) until the garbage-collection timer expires (120 seconds by default). After this, the route is removed from the route database.</li></ul><p>2. COUNT TO INFINITY</p><p>To illustrate this problem, we continue our example but this time we &#x201C;break&#x201C; the link between RA and N1. As a result is broken, N1 is now unreachable for our four RIP routers.</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-dkpfgc39j0uho4fnynwida.png" class="kg-image" alt="Internet Educational Series #10: Routing" loading="lazy" width="594" height="429"></figure><p>(1) As shown in the image above, at a certain moment the last link to N1 is broken. At this moment, RA, who is the only one-hop RIP neighbor of N1 detects this situation and sets the metric for this network to infinity in its routing database.</p><p>(2) At a certain moment, RB sends a RIP message with its current information about N1. That is to say, RB sends {N1,2} since it has not received any new information about N1. This out-of-date information arrives to RA since it is a one-hop neighbor of RB, and it causes the update of the RA&#x2019;s entry for N1.</p><p>(3) RA sends its RIP update message including {N1,3}. This causes an update in the entries for N1 in RB and RC.</p><p>(4) RC sends its RIP update message including {N1,4}, which does not cause any update in the neighbors.</p><p>(5) RB sends its RIP update message including {N1,4}, which causes that RA increases the metric for this network up to 5. At this moment, <strong>RA and RB are in mutual deception</strong> because each mutual RIP update message causes an increase of the metric for the N1 network in the other neighbor.</p><p>Notice that the behavior of algorithm is correct in the sense that the network is now at a distance of infinity and in fact, with the successive updates, the metric for the route is slowly increasing to infinity. However, we have a problem because the &#x201C;counting to infinity&#x201D; will never end and thus the routing databases will never converge. Thus, at this point it might become clear why we have to limit the maximum number of hops of a RIP domain and why &#x201C;infinity&#x201D; should be chosen as small as possible. Notice however, that infinity must be large enough so that no real route is that big. Therefore, the choice of infinity is a trade-off between network size and speed of convergence in case counting to infinity happens. The designers of RIP believed that <strong>the protocol was unlikely to be practical for networks with a diameter larger than 15, and thus they decided to set infinity to 16</strong>.</p><p>3. SPLIT HORIZON</p><p>The counting to infinity problem that we saw in our previous example is caused by the fact that RA and RC are engaged in a pattern of mutual deception. Each claims to be able to get to N1 via the other. This can be prevented in many cases by being a bit more careful about which information is sent to which neighbors.</p><p>In general, the idea of providing a &#x201D;split view&#x201C; of your available information receives the name of &#x201D;split horizon&#x201D;. In the context networking, split horizon is used to solve several problems and also to provide certain functionalities. In the context of RIP, in its simplest version, the split horizon rule is just to omit routes learned from one neighbor in updates sent to that neighbor. The reason for this, is that it is never useful to send information about a certain route to the neighbor that you are using as next hop for the route in question. Let illustrate this technique with an example:</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-mykz9qvxwwnsbi-9wyusng.png" class="kg-image" alt="Internet Educational Series #10: Routing" loading="lazy" width="594" height="369"></figure><p>(1) At a certain moment the last link to N1 is broken. At this moment, RA, who is the only one-hop RIP neighbor of N1 detects this situation and sets the metric for this network to infinity in its routing database.</p><p>(2) At a certain moment, RC sends a RIP message with its current information about N1 but in this case RC applies the split horizon rule and thus, it sends information about N1 only RD and not to RA because RA is the next hop for N1 in the RB&#x2019;s routing database. This avoids contaminating the routing entry for N1 of RA with out-of-date information coming from RC.</p><p>(3) RA sends its update to its neighbors RB and RC. After receiving the update, RB and RC update their routing databases because both had RA as next hop router (they apply the &#x201C;increasing the metric rule&#x201D;).</p><p>(4) Using the simple split horizon rule, RB sends its update to RD. The final result is that RD updates its routing entry for N1 and that all the routers in the RIP domain know now that N1 is unreachable.</p><p>The simplest version of split horizon prevents the majority of the situations of mutual deception. However, in the eventual situation in which a router, say RC, thinks that it can get a network, say N1, via another router, say RD, and RD thinks that it can get N1 via RC, in this case, we have a loop. For solving this situation, the standard of RIP proposes a modification in the behavior of split horizon called &#x201C;split horizon with poisoned reverse&#x201D;. With poisoned reverse, there is also an &#x201C;split view&#x201D; of routing information available, but the idea is not omitting routes learned from one neighbor in updates sent to that neighbor but include them with their <strong>metrics set to infinity.</strong></p><p>3.1 Split Horizon with poisoned reverse</p><p>Let&#x2019;s see a particular way in which we might arrive to a situation of mutual deception although we have activated split horizon. Then, we show how activating split horizon with poison reverse might help. For this example, we are considering that packets that convey the RIP update data may suffer delays.</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-q69_zrygtkcezrpxetmkia.png" class="kg-image" alt="Internet Educational Series #10: Routing" loading="lazy" width="594" height="401"></figure><p>These delays are typically due to the process of transmitting the data through the network and also to the time spent by the packets at different queues at the sender and the receiver. These delays also cause that RIP update messages sent to a neighbor are not immediately received and processed by that neighbor.</p><p>Let&#x2019;s describe the situation:</p><p>(1) As mentioned, we consider at a first moment that only the simple split horizon is activated. Then, at a certain moment, the last link to N1 is broken. At this moment, RA, who is the only one-hop RIP neighbor of N1 detects this situation and sets the metric for this network to infinity in its routing database.</p><p>(2) RA sends RIP update messages containing the entry {N1,16} to neighbors RB and RC. As it is shown in Figure 2.5, these update messages arrive to the neighbors at different instants of time.</p><p>(3) RB after receiving and updating its entry for N1 to infinity, RB sends a message to its neighbor RD. Notice that RB does not send any update message to RA since slit horizon is activated.</p><p>(4) RD sends an update to RC including {N1,3}, just a little bit before receiving the update for N1 from RB. As split horizon is activated, RD does not send information about N1 to RB. The update from RD is received by RC after the update from RA, and thus, the entry in the RC&#x2019;s database for N1 is {N1,4,RD}.</p><p>(5) RC sends and update about N1 to RD just before receiving the update from RA telling that N1 is unreachable. As a result, RC will end with an entry for N1 that is {N1,3,RC}. At this point, RC and RD are in mutual deception. Furthermore, they will not send to each other any update message because of the split horizon rule. Therefore, to clean the route N1 from the routing tables, we will have to wait to the timeout.</p><p>(6) In the final step, we see that if we activate split horizon with poison reverse, RD might send an update message to RC and remove the loop with RC before the timeout for the route expires.</p><p>Certainly it is rather improbable that with simple split horizon activated two routers end with routes pointing at each other, but it can happen.</p><p>In general, split horizon with poisoned reverse is safer than simple split horizon because advertising reverse routes with a metric of 16 will break any loop of mutual deception between two routers immediately. If the reverse routes are simply not advertised, the erroneous routes will have to be eliminated by waiting for a timeout.</p><p>4. TRIGGERED UPDATES</p><p>Split horizon with poisoned reverse will prevent routing loops that involve two routers. However, it is still possible to end up with patterns in which three routers are engaged in mutual deception.</p><p>Triggered updates are used to speed up convergence by avoiding that out-of-date updates produce patterns of three or more routers in mutual deception. To implement triggered updates, we simply add a rule that whenever a router changes the metric for a route, it is required to send update messages to its neighbors almost immediately, even if it is not yet time for a regular update message.</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-hagr3fydw9oelfauqblf1g.png" class="kg-image" alt="Internet Educational Series #10: Routing" loading="lazy" width="594" height="363"></figure><p>(1) After the link to N1 is broken, RA sets the metric for this network to infinity in its routing database.</p><p>(2) RA sends an update about N1 to its neighbors RB and RC. Since this update message causes a change of metric for the entries of network N1 in RB and RC, these routers must &#x201C;immediately&#x201D; send a triggered update for this network.</p><p>(3) In particular, we can observe that after RB sends its triggered update and this message is processed, all the routers in the RIP routing domain have already converged to the correct metric (16) for N1.</p><p>Notice that if the system does not send any regular update while the triggered updates are being sent, it would work perfectly.</p><p>Unfortunately, things are not so nice. While the triggered updates are being sent, regular updates may be happening at the same time. Routers that haven&#x2019;t received the triggered update yet will still be sending out information based on the route that no longer exists. It is possible that after the triggered update has gone through a router, it might receive a normal update from one of these routers that hasn&#x2019;t yet gotten the word. This could reestablish an out-of-date version of the faulty route. If triggered updates happen quickly enough, this is very unlikely. However, counting to infinity is still possible.</p><p>The final aspect about triggered updates to be taken into account is related to performance. Triggered updates can cause excessive load on networks with limited capacity or networks with many routers on them. This is due to the fact that triggered updates cause a lot of network traffic in a short period of time. Therefore, the protocol requires that implementors include some mechanisms to avoid these performance problems. To this respect, the standard proposes two mechanisms:</p><ul><li>The first mechanism is to <strong>limit the frequency of triggered updates</strong>. After a triggered update is sent, a timer should be set for a random interval between 1 and 5 seconds. If other changes that would trigger updates occur before the timer expires, a single update is triggered when the timer expires. The timer is then reset to another random value between 1 and 5 seconds. Furthermore, a triggered update should be suppressed if a regular update is due by the time the triggered update would be sent.</li><li>The second mechanism says that <strong>triggered updates do not need to include the entire routing table</strong>. In principle, <strong>only those routes which have changed need to be included</strong>. Therefore, messages generated as part of a triggered update must include at least those routes that have their route change flag set. Split Horizon processing is done when generating triggered updates as well as normal updates. The only difference between a triggered update and other update messages is the possible omission of routes that have not changed. The remaining mechanisms must be applied to all updates.</li></ul><p>5. HOLD DOWN TIMER</p><p>As a final enhancement, we will explain the Hold Down Timer mechanism:</p><p>Each router starts the hold-down timer when it first receives information about a network that is no longer reachable (RIP distance=16). Until the hold-down timer expires, the router will discard any subsequent update messages that indicate the route is again reachable. A typical hold-down timer ranges from 60 to 120 seconds. The main advantage of the hold-down timer is that a router will not be confused by receiving spurious information about a route being accessible, when it was just recently told that the route was no longer valid. This provides a period of time for out-of-date information to be flushed from the system. However, this has a disadvantage because the hold-down timer forces a delay in a router responding to a route once it is fixed. For example, let us suppose that a network &#x201C;hiccup&#x201D; causes a route to go down for five seconds. After the network is up again, the hold-down timer must expire before the router will try to use that network again. This makes using hold-down relatively slow to respond and may lead to delays in accessing networks that fail intermittently.</p><h4 id="24-rip-history">2.4 RIP History</h4><p>Great, now we&#x2019;ve seen the different mechanisms that the RIP uses. Let&#x2019;s now explain how does the protocol itself, and the main improvements made in each version.</p><p>RIP messages are sent using the User Datagram Protocol (UDP) with <strong>UDP</strong> port number <strong>520 for RIP-1 and RIP-2</strong>, and <strong>521 for RIPng</strong>. Notice that even though RIP is considered part of layer three, in terms of message exchange, RIP behaves like an application (using UDP/IP). The format of RIP messages is <strong>version-dependent</strong>. On the other hand, RIP messages can be either sent to a specific RIP neighbor (unicast), or they can be sent to multiple neighbors (broadcast or multicast). For the three versions of RIP, we have only two basic types of messages:</p><ul><li><strong>RIP Requests</strong>. Requests are messages sent by a RIP entity to another RIP entity asking it to send back all or part of its routing table.</li><li><strong>RIP Responses</strong>. Responses are messages sent by a RIP entity containing all or part of its routing table. Despite the name &#x201C;response&#x201D;, as we have already seen, these messages are sent most of the time without any preceding request.</li></ul><h4 id="rip-1"><strong>RIP-1</strong></h4><p>RIP-1, the original specification of RIP uses classful network addresses because the message format of RIP-1 does not consider sending masks. As a result, this protocol lacks support for subnetting or supernetting. Another limitation of RIP-1 is that there is not support for router authentication, making RIP vulnerable to various attacks.</p><p>RIP messages are sent using the UDP/IP network. Regarding the IP layer, the RIP-1 entity can select a unicast transmission by setting the destination IP of the neighbor or a broadcast transmission by setting the universal broadcast IP address 255.255.255.255. Regarding the UDP layer, RIP-1 uses the UDP reserved port number 520. The UDP port numbers in RIP-1 are used as follows:</p><ul><li>RIP Request messages are sent to UDP destination port 520. They may have a source port of 520 or may use an ephemeral port number.</li><li>RIP Response messages sent in reply to an RIP Request are sent with a source port of 520, and a destination port equal to whatever source port the RIP Request used.</li><li>Unsolicited RIP Response messages (sent on a routine basis and not in response to a request) are sent with both the source and destination ports set to 520.</li></ul><h4 id="rip-2"><strong>RIP-2</strong></h4><p>RIP-2 represents a very modest change to the basic Routing Information Protocol. The new features introduced in RIP-2 are described as &#x201C;extensions&#x201D; to the basic protocol. The five RIP-2 extensions are:</p><ol><li><strong>Classless Addressing Support and Subnet Mask Specification</strong>. RIP-2 adds explicit support for subnets by allowing a subnet mask within the route entry for each network address. RIP-2 provides support for fixed-length subnet masking (FLSM), variable-length subnet masking (VLSM) and classless addressing (CIDR).</li><li><strong>Use of Multicasting</strong>. To help reduce network load, RIP-2 allows routers to be configured to use multicast with the address 224.0.0.9.</li><li><strong>Next Hop Specification</strong>. The immediate next hop IP address to which packets to the destination specified by this route entry should be forwarded. Specifying a value of 0.0.0.0 in this field indicates that routing should be via the originator of the RIP advertisement. An address specified as a next hop must, per force, be directly reachable on the logical subnet over which the advertisement is made. The purpose of the Next Hop field is to eliminate packets being routed through extra hops in the system. It is particularly useful when RIP is not being run on all of the routers on a network.<br>Note that Next Hop is an &#x201C;advisory&#x201D; field. That is, if the provided information is ignored, a possibly sub-optimal, but absolutely valid, route may be taken. If the received Next Hop is not directly reachable, it should be treated as 0.0.0.0 .</li><li><strong>Authentication</strong>. RIP-2 provides an optional authentication scheme, which allows routers to ascertain the identity of a router before it will accept RIP messages from it.</li><li><strong>Route Tag</strong>. Each RIP-2 entry includes a Route Tag field, where additional information about a route can be stored. This information is propagated along with other data about the route.</li></ol><p>RIP-2 messages are exchanged using the same basic mechanism as RIP-1 messages, that is to say, using the UDP/IP network. However, to help to reduce the network load, RIP-2 allows routers to be configured to use <strong>multicast</strong> instead of broadcast for sending out unsolicited RIP Response messages. In this case, UDP/IP datagrams are sent out using the special reserved multicast address <strong>224.0.0.9</strong> . All routers on a RIP-2 domain must use multicast for this feature to work properly.</p><h4 id="ripng"><strong>RIPng</strong></h4><p>RIPng is the IPv6-compatible version of RIP for IPv6. RIPng, which is also occasionally seen as RIPv6 for obvious reasons, was designed to be as similar as possible to the current version of RIP for IPv4, which is RIP Version 2 (RIP- 2).</p><p>Despite this effort, it was not possible to define RIPng as just a new version of the older RIP protocol because of the change in the length of the addresses: from 32-bit in IPv4 to 128-bit addresses in IPv6. This forced a new message format for RIPng. The main differences between RIPv2 and RIPng are:</p><ul><li>Support of IPv6 networking.</li><li>The maximum number of RTEs in RIPng is not restricted to 25 as it is in RIP-2 (and also RIP-1). It is limited only by the maximum transmission unit (MTU) of the network over which the message is being sent.</li><li>While RIPv2 supports authentication, RIPng does not include its own authentication mechanism. It is assumed that if authentication and/or encryption are needed, they will be provided using the standard IPSec features defined for IPv6 at the IP layer. This is more efficient than implementing authentication for each individual protocol.</li><li>RIPv2 allows attaching arbitrary tags to routes, RIPng does not.</li><li>RIPv2 encodes the next hop into each route entries, RIPng requires specific encoding of the next hop for a set of route entries. Due to the large size of IPv6 addresses, including a Next Hop field in the format of RIPng RTEs would almost double the size of every entry. Since Next Hop is an optional feature, this would be wasteful. Instead, when a Next Hop is needed, it is specified in a separate routing entry.</li></ul><p>RIPng uses multicasts for transmissions, using reserved IPv6 multicast address FF02::9. Since RIPng is a new protocol, it cannot use the same UDP reserved port number 520 used for RIP-1/RIP-2. Instead, RIPng uses well-known port number 521. The semantics for the use of this port is the same as those used for port 520 in RIP-1 and RIP-2.</p><h4 id="25-limitations-of-rip">2.5 Limitations of RIP</h4><ul><li>The protocol is <strong>limited to 15 hops</strong>. The designers of RIP believe that the basic protocol design is inappropriate for larger networks. Note that this statement of the limit assumes that a <em>cost of 1 is used for each network</em>. This is the way RIP is normally configured. If the system administrator chooses to use larger costs, the upper bound of 15 can easily become a problem.</li><li>RIP depends on &#x201C;counting to infinity&#x201D; to resolve certain unusual situations. If the system of networks has several hundred networks, and a routing loop was formed involving all of them, the resolution of the loop would require either much time (if the frequency of routing updates were limited) or bandwidth (if updates were sent whenever changes were detected). Such a loop would consume a large amount of network bandwidth before the loop was corrected. However, various precautions are taken that should prevent these problems in most cases.</li><li>RIP uses fixed &#x201C;metrics&#x201D; to compare alternative routes. It is not appropriate for situations where routes need to be chosen based on real-time parameters such a measured delay, reliability, or load.</li></ul><hr><p>This article was intended to cover a basic explanation of how does RIP work on Linux systems, using the <strong>Quagga implementation</strong>.</p><p>However, as it is getting too long, I guess this is enough for an overall understanding on how RIP works, and in case you want to dig further into how it actually works in practice in Linux systems, do not doubt on contacting me.</p><p>If I get many petitions about the subject I may end up writing an article about it ;)</p><hr><p>I&#x2019;ve previously mentioned it, but the implementations of the routing protocol explained above are not at all the only ones available, and actually nowadays they aren&#x2019;t either the most used, however from my point of view, they are the most begginer-friendly implementations, and once you&#x2019;ve understood these, you can pass onto newer protocols like <strong>OSPF, BGP</strong>, etc.</p><hr><p>Well well well dear readers, this is the <strong>final article of the INTERNET EDUCATIONAL SERIES</strong> which I&#x2019;ve been writing about for the past winter. I hope you enjoyed it and learnt something, and in case you want to discuss in the topics explained here, or just want to chat a little bit, do not doubt on contacting me at <a href="mailto:akakush19@protonmail.com">akakush19@protonmail.com</a>, I&#x2019;ll be more than happy to answer.</p><hr>]]></content:encoded></item><item><title><![CDATA[Internet Educational Series #9: Multicast]]></title><description><![CDATA[How to reach multiple destinations from the same source sender?]]></description><link>https://blog.lares21.xyz/internet-educational-series-9-multicast/</link><guid isPermaLink="false">665ee4afd242c72c9151c1aa</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Wed, 14 Jul 2021 07:07:45 GMT</pubDate><media:content url="https://blog.lares21.xyz/content/images/2024/06/0-pxcxj4mmgsz_y5xs.jpg" medium="image"/><content:encoded><![CDATA[<img src="https://blog.lares21.xyz/content/images/2024/06/0-pxcxj4mmgsz_y5xs.jpg" alt="Internet Educational Series #9: Multicast"><p>Today we will talk about the <strong>Multicast</strong> technology, how do we send the same datagrams to a certain group of devices without having to send them to everyone (broadcast).</p><p>To understand Multicasting we first need to understand <strong>Unicasting</strong>.</p><p>In unicasting, there is a <strong>single sender (source)</strong> and a <strong>single receiver (destination)</strong>.</p><p>When unicast routing, the router forwards the received packet through <strong>only one</strong> of its interfaces.</p><p>On the other hand, multicasting is when there is a single sender and multiple receivers. The several receivers form part of a <strong>multicast group</strong>.</p><p>When multicast routing, the router forwards the received packets through <strong>several of its interfaces</strong>.</p><p>However, we did already know what broadcasting was (sending to everyone reachable), so how do we differentiate between them?</p><p><strong>Receivers need to request forwarding to be part of the multicast group</strong>.</p><p>This way routers know where they need to send their multicast packets.</p><p>When we want to use Multicast and <strong>send</strong> a packet from a source, the packet must include the normal source address, and a <strong>specific multicast address</strong> specified as the destination.</p><p>Moreover, the outgoing network interface and the TTL of that packet need to be specified too.</p><p>If we are one of the <strong>receivers</strong> of the multicast group, we must indicate that we want to get inside that group until we do not want to be part of it no more.</p><p>We can do so with some commands that we will see later on, but the actions that need to be performed for all multicast receivers are the following:</p><ul><li>Join-IP-Multicast-Group (group-address, interface)</li><li>Leave-IP-Multicast-Group (group-address, interface)</li></ul><p>Before digging deeper into the protocol, this are some examples of Applications of Multicasting:</p><p><strong>One to many</strong></p><ul><li>Scheduled audio-video distribution (TV, meetings, lectures&#x2026;)</li><li>File distribution and caching (website contents, file-based updates&#x2026;)</li><li>Monitoring (stock prices, telemetry)</li></ul><p><strong>Many to many</strong></p><ul><li>Multimedia conferencing (whiteboards, audio/video)</li><li>Concurrent processing (distributed parallel processing)</li><li>Collaboration (shared document editing)</li><li>Distance learning (one-to-many + feedback)</li><li>Chat groups</li><li>Multiplayer games</li></ul><h4 id="multicast-addressing">Multicast Addressing</h4><p><strong>Link-Layer Transmission/Reception</strong></p><p>How are <strong>Transmissions</strong>?</p><ul><li>An IP multicast packet is transmitted as a link-layer multicast, on those links that support multicast.</li><li>The link-layer destination address is determined by an algorithm specific to the type of link.</li></ul><p>How are <strong>Receptions</strong>?</p><ul><li>Necessary steps are taken to receive desired multicasts on a particular link, such as modifying address reception filters on LAN interfaces</li><li>Multicast routers must be able to receive all IP multicasts on a link, without knowing in advance which groups will be used.</li></ul><p>So, we need to modify certain fields to be able to use multicast. Let&#x2019;s see which ones and how do we modify them.</p><p><strong>Address Structure</strong></p><p>As you know, IP addresses have 32 bits. These 32 bits are splitted into two parts:</p><ul><li>NetID</li><li>HostID</li></ul><p>If the <strong>destination @IP</strong> has the same NetID as mine, we know that this host is in my same data-link network, and the HostID identifies the host within each network.</p><p>Additionally, you know that IPv4 addresses have 5 possible divisions:</p><ul><li>Class A: 0.0.0.0 &#x2192; 127.255.255.255 (Network 10 is private and Network 127 is internal)</li><li>Class B &#x2192; 128.0.0.0&#x2013;191.255.255.255 (Private addresses 172.16.0.0&#x2013;172.31.255.255)</li><li>Class C &#x2192; 192.0.0.0&#x2013;223.255.255.255 (Private addresses 192.168.0.0&#x2013;192.168.255.255)</li><li><strong>Class D</strong> &#x2192; 224.0.0.0&#x2013;239.255.255.255 <strong>MULTICAST ADDRESSES</strong></li><li>Class E &#x2192; 240.0.0.0&#x2013;255.255.255.254 (Reserved for future use)</li></ul><p>So yeah, until now we did talk only about classes from A to C, but of course the remaining ones are important, and in today&#x2019;s article <strong>Class D</strong> takes the podium place.</p><p>Multicast addresses are inside the range 224.0.0.0 to 239.255.255.255.</p><p>However it is impossible to add all the hosts inside this range, so to solve this, hosts <strong>join</strong> multicast groups, and then they are identified inside that groups.</p><p>How are hosts identified inside a multicast group? By <strong>SIMPLE MAPPING</strong>.</p><p>The devices are identified with their MAC address, and to indicate that these hosts have joined a multicast group, we do MAP directly the <strong>multicast identifier</strong> onto the <strong>23 least significant bits of the MAC address</strong>. Take a look at the following picture:</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-8khxdbfdebukubov3pdwlg.png" class="kg-image" alt="Internet Educational Series #9: Multicast" loading="lazy" width="543" height="212"></figure><p>When a router fins a destination address that forms part of a multicast group, it will know that it has to send the packet to that specific group.</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-u8an1ef-r7ynanwq8sz7yg.png" class="kg-image" alt="Internet Educational Series #9: Multicast" loading="lazy" width="453" height="283"></figure><p>To identify how/where to send a certain packet when it is received, the MAC layer (Ethernet interface) works as follows:</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-seiutc9isewzumw5gsccsw.png" class="kg-image" alt="Internet Educational Series #9: Multicast" loading="lazy" width="453" height="309"></figure><p>As you can see, there are several steps that need to be executed before checking if the packet is part of a multicast group.</p><h4 id="igmp">IGMP</h4><p>How do hosts tell the multicast group that they want to join it?</p><p>This is when <strong>IGMP (Internet Group Management Protocol)</strong> comes into play.</p><p>When hosts want to either join, leave or indicate that they want to continue being part of a certain group, they must use IGMP messages.</p><p>Routers also use this messages to discover group members.</p><p>The different types of IGMP messages are the following:</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-av7vhcqa_dk1fxiakewvhw.png" class="kg-image" alt="Internet Educational Series #9: Multicast" loading="lazy" width="571" height="215"></figure><h4 id="membership-report">Membership Report</h4><p>Used when a host or router can join a group.</p><p><strong>Each host maintains a list of processes that have interest in a group</strong>.</p><p>Join operation:</p><ul><li>When a process wants to join a new group, it sends its request to the host.</li><li>The host then adds the name of the process and the name of the requested group to its list.</li><li>The host sends the membership report to the router (for fiability purposes it can be sent twice).</li></ul><h4 id="leave-report">Leave Report</h4><p>When a host sees that no process is interested in a specific group, it sends a leave report.</p><p>If a router receives a leave report it will not purge the list if there are still other hosts interested in that group.</p><p>For that purpose, routers send a special query message with a specified response time for the group in question to see if there is anyone interested in that group.</p><p>If there is no response, it purges the list.</p><h4 id="general-query-message">General Query Message</h4><p>Membership report and leave report are not enough to maintain the membership information.</p><p>To keep a host inside a group, hosts and routers periodically send general query messages.</p><p>Then hosts and routers respond by sending membership reports if they still have interest in those groups.</p><p><strong>But be careful!</strong>To keep the traffic low, the response to a general query message must be done by only one host for a given group.</p><p>When a hosts receives a general query message, <strong>it delays the response</strong>: It sets a timer for each group to a different random value between 0 and 10 seconds.</p><p>If the host receives a response from another host, whose time for that group has expired earlier, the host cancels its response.</p><p><em>Note: Only one router on the LAN is designated for sending the query messages (the querier router).</em></p><p>Finally it is worth mentioning that IGMP messages are encapsulated inside IP datagrams.</p><p>To identify if an IP datagram is a multicast one, we must take a look at the <strong>PROTOCOL NUMBER</strong> field, if it is a <strong>2</strong>, it means that it is using IGMP, multicasting.</p><h4 id="mbone-multicast-backbone">MBONE (Multicast Backbone)</h4><p>As the internet has been growing bigger and bigger, so have done applications that need to use multicasting. Multimedia and real-time applications have been the ones that needed to use it the most.</p><p>However, only a small fraction of the Internet routers support multicasting.</p><p>The solution is to use <strong>tunneling</strong>, as it provides a logical connection of multicast routers through non-multicast routers, called <strong>multicast backbone</strong>.</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-azptc1vtm7dutkqsvze8iq.png" class="kg-image" alt="Internet Educational Series #9: Multicast" loading="lazy" width="426" height="245"></figure><h4 id="unicast-vs-multicast">Unicast vs Multicast</h4><p>To finish this article, let&#x2019;s take a look at the main differences between unicast and multicast routing.</p><p><strong>Unicast</strong>:</p><ul><li>Unicast routing is concerned about where the packet is going</li><li>The destination IP address directly indicates where to forward the packet</li><li>Forwarding is done hop-by-hop</li><li>The routing table determines the interface and the next-hop router to forward the packet</li></ul><p><strong>Multicast</strong>:</p><ul><li>Multicast routing is concerned about where the packet came from</li><li>The destination IP address (group) does not directly indicate where to forward the packet</li><li>Receivers must be &#x201C;connected&#x201D; to the tree before the traffic begins to flow</li></ul><p>Note that the multicast trees are <strong>spanning trees</strong>, where the source is located at the root of the tree, and the group members are the leaves of the tree.</p><p>The basic requirements that a group must fulfill to use multicast are the following:</p><ul><li>Every group member should receive only one copy of the multicast packet</li><li>Non member must not receive a copy.</li><li>A multicast packet must not be received by a router more than once (no loops)</li><li>Paths from the source to each destination must be optimal (shortest path)</li></ul><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-h8pzcfbyh_unnrvr9-o5sg.png" class="kg-image" alt="Internet Educational Series #9: Multicast" loading="lazy" width="559" height="245"></figure><hr><p>As you see, multicast is a technology with a HUGE amount of possibilities, almost every streaming service uses multicast nowadays.</p><p>I hope you liked this brief explanation about the topic.</p><p>In case you want to learn more about other Internet related topics, <strong>feel free to check my previous articles</strong>:</p><ul><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-1-ethernet-switching-vlans-9fc667595d1e?ref=blog.lares21.xyz" rel="noopener">Chapter 1: Ethernet, Switching &amp; VLANs</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-2-ip-basics-a8a11c24e644?ref=blog.lares21.xyz" rel="noopener">Chapter 2: IP Basics</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-3-network-applications-5c9be0c63eef?ref=blog.lares21.xyz" rel="noopener">Chapter 3: Network Apps</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-4-dns-domain-name-system-630600a75d2b?ref=blog.lares21.xyz" rel="noopener">Chapter 4: DNS</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-5-dhcp-dynamic-host-configuration-protocol-a35e09a0d263?ref=blog.lares21.xyz" rel="noopener">Chapter 5: DHCP</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-6-www-html-http-s-cookies-167d498f4378?ref=blog.lares21.xyz" rel="noopener">Chapter 6: WWW (HTTP(S), HTML, Cookies&#x2026;)</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-7-firewalls-nat-2b6440e0d2dc?ref=blog.lares21.xyz" rel="noopener">Chapter 7: Firewalls &amp; NAT</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-8-ip-tunnels-c19bbb92717?ref=blog.lares21.xyz" rel="noopener">Chapter 8: IP Tunnels</a></li></ul><p>Finally, this series will reach to the 10th episode, so if you&#x2019;ve liked my content please leave a clap, <strong>it makes a huge difference </strong>for me and keeps me motivated to write more articles!</p><hr>]]></content:encoded></item><item><title><![CDATA[Internet Educational Series #7: Firewalls & NAT]]></title><description><![CDATA[How can we protect our computers from hackers while browsing the Internet without exposing ourselves?]]></description><link>https://blog.lares21.xyz/internet-educational-series-7-firewalls-nat/</link><guid isPermaLink="false">665ee4afd242c72c9151c1ae</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Sat, 10 Jul 2021 05:09:54 GMT</pubDate><media:content url="https://blog.lares21.xyz/content/images/2024/06/1-zhpsc3_5oga6zgmqx2alja.png" medium="image"/><content:encoded><![CDATA[<figure class="kg-card kg-image-card kg-width-wide kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/0-h_gmloiti6dbz9b7.jpg" class="kg-image" alt="Internet Educational Series #7: Firewalls &amp; NAT" loading="lazy" width="1200" height="800" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/0-h_gmloiti6dbz9b7.jpg 600w, https://blog.lares21.xyz/content/images/size/w1000/2024/06/0-h_gmloiti6dbz9b7.jpg 1000w, https://blog.lares21.xyz/content/images/2024/06/0-h_gmloiti6dbz9b7.jpg 1200w" sizes="(min-width: 1200px) 1200px"><figcaption><span style="white-space: pre-wrap;">Photo by </span><a href="https://unsplash.com/@comparefibre?utm_source=medium&amp;utm_medium=referral" target="_blank" rel="photo-creator noopener"><span style="white-space: pre-wrap;">Compare Fibre</span></a><span style="white-space: pre-wrap;"> on&#xA0;</span><a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral" target="_blank" rel="photo-source noopener"><span style="white-space: pre-wrap;">Unsplash</span></a></figcaption></figure><img src="https://blog.lares21.xyz/content/images/2024/06/1-zhpsc3_5oga6zgmqx2alja.png" alt="Internet Educational Series #7: Firewalls &amp; NAT"><p>You know the internet uses IP addresses to identify the devices where it has to send the packets and overall data. However, as time has passed, the number of available IP (version 4) addresses is almost exhausted and something had to be done to reuse or at least optimize the use of addresses.</p><p>Additionally, as more people learnt about the internet, and more and more files were uploaded to the net, serious threats appeared which had to be addressed.</p><p>In this article we&#x2019;re gonna talk about how do our home devices (the ones connected to our home network, which is supposed to be secure) are connected to external networks such as the Internet (which are supposed to be &#x201C;insecure&#x201D;), and how do we protect our networks and devices from bad actors.</p><h4 id="firewalls">Firewalls</h4><p>Usually routers distribute traffic according to a <strong>set of rules</strong> that only accounts for the destination address.</p><p>They do forward packets through a specific gateway (the default one, or another one that we must indicate) to the destination device.</p><p>But what if the traffic needs to be controlled according to other parameters?</p><p>For example imagine we are implementing the network of a certain company, and they ask for the following requirements:</p><ul><li>Equipment in the external network can only access the public web server.</li><li>However, the marketing department can access the private web server, BUT not the public one.</li><li>Traffic from one, <strong>and only one</strong>, specific device in the external network can reach the marketing network.</li><li>Traffic going out the intranet network cannot reach the external network.</li></ul><p>A possible solution would be to configure each single device to receive and send only the desired packets.</p><p>However this is not at all a scalable solution, and so another method had to be used. And this method are the <strong>FIREWALLS</strong>.</p><p>A firewall can be understood as a toll for control access.</p><p>It splits the network topology into an <em>internal network</em>, which should be secure and trusted, and an <em>external network</em>, which is somehow untrusted.</p><h4 id="goals-of-firewalls">Goals of Firewalls</h4><p>Firewalls are implemented generally for the following points, however they can have multiple other use cases.</p><ul><li><strong>Single choke point for network traffic</strong>. This gives a solution to the scaling problem, and minimizes the risk.</li><li><strong>Access control rules</strong>. Only authorized traffic will be allowed to pass the firewall. This eases the administrative work.</li><li><strong>Secured Devices</strong>.</li></ul><h4 id="types-of-firewalls">Types of Firewalls</h4><h4 id="1-packet-filtering-firewalls">1. Packet Filtering Firewalls</h4><p>Packet filters inspect the IP packets reaching the Firewall and apply a <strong>set of rules</strong> to decide if they are forwarded or discarded.</p><ul><li><strong>ACCEPT/FORWARD</strong></li><li><strong>REJECT</strong></li><li><strong>DROP</strong></li></ul><p>Filtering rules are based on information contained inside a packet, such as the <strong>network source/destination addresses</strong>, the <strong>transport source/destination addresses</strong> (TCP/UDP ports), the <strong>protocols used</strong> and the <strong>incoming/outgoing network interface</strong>.</p><p><strong>Advantages:</strong></p><ul><li>Simplicity</li><li>Fast Evaluation</li><li>Doesn&#x2019;t change the traffic flow or characteristics</li></ul><p><strong>Weaknesses:</strong></p><ul><li>Limited auditing</li><li>Vulnerable to several (simple) attacks (spoofing attacks, source routing attacks, tiny fragment attacks&#x2026;)</li></ul><h4 id="2-stateful-filtering-firewalls">2. Stateful Filtering Firewalls</h4><p>Also called <em>Dynamic Packet Filtering</em>, it takes into account the context, i.e. it maintains a history of previously seen packets to make better decisions about future packets.</p><p>It tracks open connections, maintains a table of them, and associates new connections requests with existing legitimate connections.</p><p>When tracking the open connections, the firewall maintains the following attributes (among others):</p><ul><li>IP addresses</li><li>Ports</li><li>Sequence numbers</li><li>Connection Status</li></ul><p><strong>Advantages:</strong></p><ul><li>More secure</li><li>Defense against spoofing and DoS attacks</li><li>Prevents TCP sequence-numbers attacks</li></ul><p><strong>Weaknesses:</strong></p><ul><li>Rules are harder to write</li><li>Still limited auditing capabilities</li></ul><h4 id="3-proxy-firewalls">3. Proxy Firewalls</h4><p>Proxy firewalls, or <strong>Application layer gateways (ALG)</strong> are devices that act as a relay for <em>application-level traffic</em>.</p><p>This means they can &#x201C;understand&#x201D; certain traffic application protocols. They are able to detect:</p><ul><li>If an unwanted protocol is attempting to bypass the firewall on an allowed port.</li><li>If a protocol is being abused in any harmful way.</li><li>If user credentials are enough to use some protocol.</li></ul><p><strong>Advantages:</strong></p><ul><li>Even more secure</li><li>Full auditing capabilities</li><li>Hides the internal addressing scheme</li><li>Harmful applications can be blocked</li></ul><p><strong>Weaknesses:</strong></p><ul><li>Usually slower as they require much more resources</li><li>A comprehensive knowledge of the protocol is needed</li><li>Not available for all the application protocols</li><li>Application protocols update frequently, and so the proxy has to be updated too</li><li>Sometimes some extra client configuration is required</li></ul><h4 id="nat">NAT</h4><p>So now that we know how to protect ourselves from &#x201C;external insecure networks&#x201D;, we should know how to reach them.</p><p>But, you already told us that to reach a device we only need to know its IP address isn&#x2019;t it? Yeah, that&#x2019;s it.</p><p>However, you may have seen that MANY devices have really similar addresses between them, like the typical 192.168.1.1 (usually your home router).</p><p>This is because as the Internet grows bigger and bigger, the different networks which form the whole net had to find a way to differentiate between them.</p><p>There are <strong>PUBLIC networks</strong> and <strong>PRIVATE networks</strong>, being the first ones accessible for everyone, but the latest ones only for the ones who are inside that network.</p><p>Note how everyone can access directly the public addresses, but not the private ones.</p><p>For this exact reasons, almost ALL private networks use the same range of addresses (usually C class range, 192.168.0.0/16), as each and every private network is just accessible from its inside hosts, and they don&#x2019;t need to have a different address from an unreachable host, as they are not connected from the first place.</p><p>Let&#x2019;s put an example: We have 2 companies, A and B.</p><p>All the devices from network A can only access other devices from its internal network, but not the ones from B. This way, we can assign the same exact address to a device from network A and network B, as there will be no confusion between them.</p><p>That sounds legit, but what if now we need to connect from a certain device from network A to network B? Or maybe we want to send something from a private address to a public one.</p><p>We must know how to reach all this addresses.</p><p>This is when the <strong>NAT</strong> comes into play. It stands for <strong>Network Address Translation</strong>, and it is a mechanism that translates IP addresses (and port numbers), and allows to connect public and private networks, saving public IP addressing this way.</p><p>When we use NAT, two address translations are performed:</p><ul><li>One when the packet departs the <strong>NAT router</strong>.</li><li>The reverse translation when the packet returns to the NAT router.</li></ul><h4 id="nat-types">NAT Types</h4><p>To do so, we use <strong>two main types of NAT</strong>.</p><p><strong>Source NAT (SNAT)</strong>:</p><ul><li>The router translates the source address <strong>after routing</strong>, just before the packet leaves the router.</li><li>When response packets arrive, the router will perform the reverse operation (translation of destination address).</li></ul><p><strong>Destination NAT (DNAT)</strong>:</p><ul><li>The router translates the destination address <strong>before routing</strong>, just when the packet arrives to the router.</li><li>When response packets arrive, the router will perform the reverse operation (translation of source address).</li></ul><h4 id="consequences-of-nat-usage">Consequences of NAT usage</h4><p>If IP addresses change, the checksums must be recalculated.</p><p>When a NAT is used, response packets should return to the same NAT router (to perform the reverse translation).</p><p>For this reason, in most cases there is only one NAT router to manage the Internet access.</p><h4 id="nat-limitations">NAT Limitations</h4><p>For the above reasons, when using NAT, the Internet becomes a pseudo-connection-oriented network.</p><p>Furthermore, each NAT router becomes a bottleneck, as it must manage the translation of all ingoing and outgoing connections.</p><p>In case the router does also need to use a proxy firewall (ALG), it will have to do a whole bunch of tasks before sending each packet.</p><h4 id="nat-conclusions">NAT conclusions</h4><p>So forth, NAT has been extending the lifetime of IPv4, delaying IPv6 deployment. However, this is far from being an optimal solution, as there can be different behaviors for different NAT implementations, and new applications will need extra NAT support.</p><hr><h3 id="firewalls-nat-in-linux-ip-tables">Firewalls &amp; NAT in Linux (IP tables)</h3><p>Alright, now you know the theoretical approach to how we connect to external devices, and how we protect ourselves from malicious actors.</p><p>Let&#x2019;s take that into practice and see how we can implement NAT in Linux systems.</p><h4 id="netfilter">Netfilter</h4><p>Netfilter is the packet filtering framework used in Linux platforms.</p><p>It contains <strong>chains of rules</strong> for the treatment of packets.</p><p>Each chain is associated with a different &#x201C;role&#x201D; of the host when processing packets.</p><p>Each network packet arriving at or leaving from the computer goes through at least one chain.</p><p>The five predefined chains are the following ones:</p><ul><li><strong>PREROUTING</strong>: First chain that a packet finds when it comes from the network. It is located before the routing decision.</li><li><strong>INPUT</strong>: This chain applies when the packet is going to be <strong>locally delivered</strong> (the host is the destination), and it must perform some action in the host itself.</li><li><strong>FORWARD</strong>: the packet will enter this chain if it comes from the network, but the host is not the destination.</li><li><strong>OUTPUT</strong>: this chain applies when packets are sent by the host after having performed some action, and they need to be sent to another host.</li><li><strong>POSTROUTING</strong>: The packet will enter this chain after the routing decision has been made, and it will send the packet further.</li></ul><h4 id="netfilter-syntax">Netfilter syntax</h4><p>When a packet enters a chain, the kernel verifies if the rules inside the chain match this packet to know how to proceed.</p><p>Each rule contains some specifications to decide if the packets match it.</p><p>If a packet reaches the end of the chain without matching any rule, the default chain policy is applied (for example <strong>DROP</strong>).</p><p><strong>How to configure the netfilter chains in the Linux Kernel?</strong> Using the <code>iptables</code> command.</p><p><strong>Syntax:</strong></p><pre><code>iptables &lt;table&gt; &lt;op&gt; &lt;chain&gt; &lt;pkt-match-condition&gt; &lt;action&gt;</code></pre><ul><li><strong>table</strong>: Selects the table to work with</li></ul><p><code>-t filter</code>: selects packet filtering</p><p><code>-t nat</code>: selects NAT table</p><ul><li><strong>op</strong>: Rule operations within a chain</li></ul><p>(<code>-A</code>) APPEND a new rule to the chain</p><p>(<code>-I</code>) INSERT a new rule in a position within a chain</p><p>(<code>-D</code>) DELETE a rule in a position within a chain</p><p>(<code>-R</code>) MOVE a rule from a position to another one</p><ul><li><strong>chain</strong>: the chain name to operate with</li></ul><p>Packet filtering: INPUT, OUTPUT and FORWARD</p><p>NAT: PREROUTING, POSTROUTING and OUTPUT</p><ul><li><strong>Packet Matching Condition</strong>: The set of conditions that a packet must satisfy. There are 3 types of conditions:</li></ul><p>Physical/link layer conditions: network interface where the packet is received/transmitted.</p><p>Network layer conditions: fields in the IP header</p><p>Transport layer conditions: fields in the transport header</p><ul><li><strong>Action</strong>: The verdict is applied to the packet if all the rule conditions are satisfied.</li></ul><p><strong>Conditions:</strong></p><ul><li>for the PHYSICAL/LINK layer:</li></ul><pre><code>-i, --in-interface [!] name 
-o, --out-interface [!] name</code></pre><p>names of the interface via which packets will be received/sent</p><ul><li>for the NETWORK layer</li></ul><p><code>-p, &#x2014;protocol [!] protocol</code> The protocol of the packet to check. It can be <code>tcp</code>, <code>udp</code>, <code>icmp</code>, or <code>all</code></p><p><code>-s, &#x2014;source [!] address[/mask]</code> Source specification (network name, hostname, @IP&#x2026;)</p><p><code>-d, --destination [!] address [/mask]</code> Destination specification.</p><ul><li>for ICMP (if <code>--protocol icmp</code> is specified in the conditions of the network layer)</li></ul><p><code>--icmp-type [!] typename</code> This allows specification for the ICMP type</p><ul><li>for TRANSPORT layer (if <code>--protocol tcp</code> is specified in the conditions of the network layer)</li></ul><p><code>--source-port [!] port[:port]</code></p><p><code>--destination-port [!] port[:port]</code></p><p><code>--tcp-flags [!] mask comp</code></p><p>As you can see there are many options available for the &lt;condition&gt; field, as the above ones are not all of them yet, but the main ones.</p><h4 id="examples">Examples</h4><p>Finally I&#x2019;ll show you some example of the <code>iptables</code> command and its use:</p><ul><li>Adding a rule in the INPUT chain to drop packets whose source IP address is 192.168.1.1 and transport protocol is TCP:</li></ul><pre><code>iptables -t filter -A INPUT -s 192.168.1.1 -p tcp -j DROP</code></pre><ul><li>Adding a rule in FORWARD to drop packets whose source IP addresses are in range 192.168.1.0/24, the protocol ICMP and icmp type echo-request, and received in the eth0 network interface:</li></ul><pre><code>iptables -t filter -A FORWARD -i eth0 -s 192.168.1.0/24 -p ICMP --icmp-type echo-request -j DROP</code></pre><ul><li>Adding a rule in OUTPUT to avoid outgoing http connections towards the <a href="http://www.google.com/?ref=blog.lares21.xyz" rel="noopener">www.google.com</a> server:</li></ul><pre><code>iptables -t filter -A OUTPUT -d www.google.com -p tcp --dport 80 --syn -j DROP</code></pre><ul><li>Adding a rule to do SNAT for all packets that leave the router using the eth1 interface, translating to the IP address 172.16.1.1:</li></ul><pre><code>iptables -t nat -A POSTROUTING -o eth1 -j SNAT --to 172.16.1.1</code></pre><hr><p>I know at first the rules used in our computers to filter the traffic can be a little hard to grasp, however once you have an overall understanding of how the whole Internet works, everything becomes much more clear.</p><p>In case you want to learn more about this topics, <strong>feel free to check my previous articles</strong>:</p><ul><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-1-ethernet-switching-vlans-9fc667595d1e?ref=blog.lares21.xyz" rel="noopener">Chapter 1: Ethernet, Switching &amp; VLANs</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-2-ip-basics-a8a11c24e644?ref=blog.lares21.xyz" rel="noopener">Chapter 2: IP Basics</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-3-network-applications-5c9be0c63eef?ref=blog.lares21.xyz" rel="noopener">Chapter 3: Network Apps</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-4-dns-domain-name-system-630600a75d2b?ref=blog.lares21.xyz" rel="noopener">Chapter 4: DNS</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-5-dhcp-dynamic-host-configuration-protocol-a35e09a0d263?ref=blog.lares21.xyz" rel="noopener">Chapter 5: DHCP</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-6-www-html-http-s-cookies-167d498f4378?ref=blog.lares21.xyz" rel="noopener">Chapter 6: WWW (HTTP(S), HTML, Cookies&#x2026;)</a></li></ul><p>Finally, this series will reach to the 10th episode, so if you&#x2019;ve liked my content please leave a clap, <strong>it makes a huge difference </strong>for me and keeps me motivated to write more articles!</p><hr>]]></content:encoded></item><item><title><![CDATA[Internet Educational Series #8: IP Tunnels]]></title><description><![CDATA[Time travel may be still be pure fiction, but what space travelling?]]></description><link>https://blog.lares21.xyz/internet-educational-series-8-ip-tunnels/</link><guid isPermaLink="false">665ee4afd242c72c9151c1ad</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Fri, 09 Jul 2021 17:27:12 GMT</pubDate><media:content url="https://blog.lares21.xyz/content/images/2024/06/1-b8npgze4yadankaadaurbw-jpeg.jpg" medium="image"/><content:encoded><![CDATA[<img src="https://blog.lares21.xyz/content/images/2024/06/1-b8npgze4yadankaadaurbw-jpeg.jpg" alt="Internet Educational Series #8: IP Tunnels"><p>In previous articles we talked about the different protocols used to configure the net and devices, how we protect from malicious behaviors, how to identify devices inside a network and route packets between them, and how we use browsers to access different files from the Internet.</p><p>However, we&#x2019;ve been talking about <strong>public and private networks</strong> all this time, and we still don&#x2019;t know how to connect between them. We know how to translate addresses using NAT, but this new addresses should be able to connect to other private networks, or at least find an &#x201C;intermediary&#x201D; network to route the packets through.</p><p><strong>The tunneling solution</strong></p><p>A tunnel is essentially a network communications channel between two networks.</p><p>Tunnels are used to transport another network protocol by encapsulating its packets.</p><p>They can be seen as <strong>Source Routes</strong> that circumvent conventional routing mechanisms.</p><p>If the tunnel is built at IP layer it is named <strong>IP tunnel</strong>.</p><p>To implement them, some routers must have <strong>two IP addresses to identify themselves, a public (outer) and a private (inner) one</strong>.</p><p>The outer router IP addresses identify the &#x201C;endpoints&#x201D; of the tunnel.</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-1vpbb6-slapp_itqatiqga.png" class="kg-image" alt="Internet Educational Series #8: IP Tunnels" loading="lazy" width="800" height="272" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-1vpbb6-slapp_itqatiqga.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-1vpbb6-slapp_itqatiqga.png 800w" sizes="(min-width: 720px) 720px"></figure><p>The image above represents a certain type of tunnel (GRE), which we will talk about it later, but just for understanding the general picture, take a look at the different IP addresses that appear in it.</p><p>We can see first of all two Class C addresses that identify the router inside each one of their private networks (192.168.1.0/24 for R1 and 192.168.2.0/24 for R2), and another IP address that identifies them in the public network, Internet (1.1.1.1/30 for R1 and 2.2.2.2/30 for R2).</p><p>Additionally note that we do also have <strong>2 more IP addresses</strong>. These correspond to the tunnel, where we want to send the packets through.</p><p>When we use an IP tunnel, we may want to send other types of datagrams through that tunnel, and that&#x2019;s why we <strong>encapsulate packets</strong> inside another packet, whose format is native to the public network.</p><p>There are several encapsulation protocols, to accomplish this.</p><ul><li>IP as encapsulation protocol itself (ipencap, 6in4, 4in6&#x2026;)</li><li>Other encapsulation protocols (SSH, TLS, IPsec&#x2026;)</li></ul><h4 id="ip-encapsulation-protocol">IP encapsulation protocol</h4><p>Here we will analyze the first encapsulation protocol, as the other ones are quite different and made for a specific purpose.</p><p>To use the IP encapsulation method, <strong>each router creates a new network pseudo-device</strong>, which is associated to the outer IP address (take a look at the the &#x201C;tunnel addresses&#x201D; we mentioned with the previous image).</p><p>When a packet is sent through this pseudo-device, it is encapsulated on a IP packet and sent to the other remote border router.</p><p>Then, when a packet is received through this pseudo-device, the payload is extracted and treated as an incoming real IP packet.</p><p><em>Note: This network pseudo-device ONLY accepts IP packets from the other border router.</em></p><p>When we want to use the IP encapsulation method, we must include a new entry to the routing table to indicate which packets will be sent through the IP tunnel.</p><p>P.ex:</p><pre><code>Destination		Gateway		Genmask			Iface 
...  ... 
192.168.2.0		0.0.0.0		255.255.255.0	tunnel0 
...  ...</code></pre><p>This entry would tell the router that any packet towards 192.168.2.0/24 will be sent through the <code>tunnel0</code> network pseudo-device, encapsulated in another IP packet, and sent to the other remote border router.</p><p><strong>The outer IP packet</strong></p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-pddtdqb4h9wllj5xunmfoa.png" class="kg-image" alt="Internet Educational Series #8: IP Tunnels" loading="lazy" width="167" height="309"></figure><ul><li>Outer IP Header &#x2192; Includes:</li><li>IP source and destination addresses (&#x201C;endpoints&#x201D; of the tunnel)</li><li>IP protocol field: <strong>type of encapsulation</strong> used</li><li>Tunnel Header: some encapsulation types define a specific tunnel header to introduce extra parameters.</li><li>The encapsulated inner IP packet</li></ul><p>Let&#x2019;s see some of the encapsulation types:</p><ul><li>IP in IP encapsulation</li></ul><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-uy3p8npq4dsxl8gluuxcha.png" class="kg-image" alt="Internet Educational Series #8: IP Tunnels" loading="lazy" width="540" height="308"></figure><p>(does not have tunnel headers)</p><ul><li>GRE (Generic Routing Encapsulation)</li></ul><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-fx5dfg6whtxk2kvxornirq.png" class="kg-image" alt="Internet Educational Series #8: IP Tunnels" loading="lazy" width="342" height="158"></figure><p>Inside the IP payload we find the Inner IP Header and the Inner IP Payload.</p><p>The &#x201C;Delivery Header&#x201D; includes the Outer IP Header and the Tunnel Headers.</p><ul><li>IPsec (Internet Protocol Security)</li></ul><p>This one is an encapsulation method worth mentioning because it can provide <strong>authentication</strong> by using Authentication Headers (AH), <strong>encryption</strong> by using Encapsulating Security Payloads (ESP), and finally <strong>mutual authentication</strong> at the beginning of the session and <strong>negotiation of cryptographic keys</strong> to be used during the session (Security Associations, SA).</p><h4 id="configuration-of-tunnels">Configuration of Tunnels</h4><p>To configure tunnels in Linux systems, we will use the command <code>ip tunnel</code>.</p><p>Command options:</p><p><code>ip tunnel show</code> - lists tunnels</p><p><code>ip tunnel add</code> - add a new tunnel</p><p><code>ip tunnel change</code> - change an existing tunnel</p><p><code>ip tunnel delete</code> - destroy a tunnel</p><p><code>name NAME</code> - select the tunnel device NAME</p><p><code>mode MODE</code> - select the tunnel mode (modes for ipv4: <code>ipip</code>, <code>sit</code>, <code>isatap</code> and <code>gre</code>)</p><p><code>remote ADDRESS</code> - set the remote endpoint of the tunnel</p><p><code>local ADDRESS</code> - set the fixed local address for tunneled packets. It must be an address on another interface of the local host.</p><p><code>ttl N</code> - set a fixed TTL &#x201C;N&#x201D; on tunneled packets. N must be in the range 1-255. 0 means that the packets inherit the TTL value, which is the default value.</p><p><code>dev NAME</code> - bind the tunnel to the device NAME so that tunneled packets will only be routed via this device and will not be able to escape to another device when the route to endpoints changes.</p><p><code>nopmtudisc</code> - disable Path MTU Discovery on this tunnel. It is enabled by default. Note that a fixed TTL is incompatible with this option (tunneling with a fixed ttl always makes pmtu discovery).</p><hr><p>Despite being one of the shortest articles of the series, understanding how tunnels work on the Internet is a really powerful tool. I hope you got at least a first glimpse on what they are, and this article encourages you to do more research about the topic, as it is continuously being developed, and a lot more information can be found out there about tunneling.</p><p>In case you want to learn more about this topics, <strong>feel free to check my previous articles</strong>:</p><ul><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-1-ethernet-switching-vlans-9fc667595d1e?ref=blog.lares21.xyz" rel="noopener">Chapter 1: Ethernet, Switching &amp; VLANs</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-2-ip-basics-a8a11c24e644?ref=blog.lares21.xyz" rel="noopener">Chapter 2: IP Basics</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-3-network-applications-5c9be0c63eef?ref=blog.lares21.xyz" rel="noopener">Chapter 3: Network Apps</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-4-dns-domain-name-system-630600a75d2b?ref=blog.lares21.xyz" rel="noopener">Chapter 4: DNS</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-5-dhcp-dynamic-host-configuration-protocol-a35e09a0d263?ref=blog.lares21.xyz" rel="noopener">Chapter 5: DHCP</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-6-www-html-http-s-cookies-167d498f4378?ref=blog.lares21.xyz" rel="noopener">Chapter 6: WWW (HTTP(S), HTML, Cookies&#x2026;)</a></li></ul><p>Finally, this series will reach to the 10th episode, so if you&#x2019;ve liked my content please leave a clap, <strong>it makes a huge difference </strong>for me and keeps me motivated to write more articles!</p><hr>]]></content:encoded></item><item><title><![CDATA[Internet Educational Series #6: WWW (HTML, HTTP(S), Cookies…)]]></title><description><![CDATA[How does the Internet provide websites to our home computers? Learn about the protocols used in the web, browsers, and the methods used to…]]></description><link>https://blog.lares21.xyz/internet-educational-series-6-www-html-http-s-cookies/</link><guid isPermaLink="false">665ee4afd242c72c9151c1a0</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Fri, 07 May 2021 01:30:17 GMT</pubDate><media:content url="https://blog.lares21.xyz/content/images/2024/06/1-4tu_wf3hz4cuq1vc0imasw-jpeg.jpg" medium="image"/><content:encoded><![CDATA[<h4 id="how-does-the-internet-provide-websites-to-our-home-computers-learn-about-the-protocols-used-in-the-web-browsers-and-the-methods-used-to-access-resources-from-around-the-world">How does the Internet provide websites to our home computers? Learn about the protocols used in the web, browsers, and the methods used to access resources from around the world.</h4><img src="https://blog.lares21.xyz/content/images/2024/06/1-4tu_wf3hz4cuq1vc0imasw-jpeg.jpg" alt="Internet Educational Series #6: WWW (HTML, HTTP(S), Cookies&#x2026;)"><p>In this chapter you&#x2019;ll find an introduction to the protocols &amp; languages used in the <strong>World Wide Web</strong>.</p><p>Content:</p><ul><li>History</li><li>HTML</li><li>HTTP Motivation</li><li>URL/URI</li><li>HTTP 1.0</li><li>Cookies</li><li>HTTP Proxies</li><li>Dynamic Web</li><li>HTTP 1.1</li><li>Related RFCs</li><li>Practical HTTP with <strong>nginx</strong></li><li>HTTPS (Secure HTTP)</li></ul><hr><h4 id="history">History</h4><p>Tim Berners-Lee is credited with having created the initial World Wide Web (WWW) during 1985&#x2013;1991, while he was a researcher at the European High-Energy Particle Physics lab at <a href="http://home.cern/?ref=blog.lares21.xyz" rel="noopener">CERN</a> (Centre Europ&#xE9;en de Recherche Nucl&#xE9;aire).</p><p>In this context, a multi-platform tool was needed to enable sharing documents between physicists and other researchers in the high energy physics community.</p><p>Tim Berners-Lee wrote a proposal that was a solution for enabling such</p><p>collaboration.</p><p><strong>Four basic technologies</strong> were part of his proposal:</p><ul><li><strong>HTML </strong>(HyperText Markup Language): a language to write documents.</li><li><strong>HTTP</strong> (HyperText Transfer Protocol): a protocol to transmit resources (like HTML documents).</li><li>A <strong>WEB server</strong>: a software that serves resources like HTML documents.</li><li>A <strong>WEB browser</strong>: a software that acts as client to send requests and process responses for resources available on a WEB server (like HTML documents).</li></ul><hr><h4 id="html">HTML</h4><p>HTML (Hyper Text Markup Language) is not a programming language like C or Java, but it is a <strong>markup language</strong>. This means that it is used to describe how content (text, images, etc) should be displayed <em>(normally in a web browser)</em>.</p><p>HTML files are just text files that you can edit with any editor. There are also available &#x201C;HTML editors&#x201D; specially designed for writing it.</p><p>Let&#x2019;s analyze a HTML fragment:</p><pre><code>&lt;html&gt; 
    &lt;head&gt; 
    &lt;title&gt; Hello World&lt;/title&gt; 
    &lt;meta http&#x2212;equiv=&quot;content&#x2212;type&quot; content=&quot;text/html; charset=UTF&#x2212;8&quot;&gt; 
    &lt;/head&gt; 
    &lt;body&gt; 
        Hello &lt;b&gt;World&lt;/b&gt;!!!!!!! 
    &lt;/body&gt; 
&lt;/html&gt;</code></pre><p>As you can see, HTML is pure text. However some of this text is considered <strong>hypertext</strong> which is the text enclosed between &#x2018;&lt;&#x2019; and &#x2018;&gt;&#x2019;.</p><p>This hypertexts are called <strong>HTML tags</strong>, and they tell the browser to do something special with that text.</p><p>Some HTML tags have an opening tag and an ending tag. This is marked as <code>&lt;tag&gt; ... &lt;/tag&gt;</code> .</p><p>Other tags however, are just composed of a single tag.</p><hr><p>The HTML document is delimited by <code>&lt;html&gt;</code> and <code>&lt;/html&gt;</code>. In addition, the HTML</p><p>document is divided in two parts:</p><ul><li><code>&lt;head&gt;</code>. This part is optional. If &lt;head&gt; exists, it can contain several labels like &lt;title&gt;, &lt;meta&gt;, etc.</li><li><code>&lt;body&gt;</code>. Inside the body is where the whole HTML document is specified. All text, images, etc. are contained between &lt;body&gt; and &lt;/body&gt;.</li></ul><p>On the other hand, we can also use tags to create hyperlinks to other resources (like other HTML documents).</p><p>This is a fundamental feature in HTML. The <strong>hyperlink tag is <code>&lt;a&gt;... &lt;/a&gt;</code>.</strong></p><p>Example from an HTML code:</p><pre><code>&lt;html&gt; 
    &lt;head&gt; 
        &lt;title&gt; Hello World&lt;/title&gt; 
        &lt;meta http&#x2212;equiv=&quot;content&#x2212;type&quot; content=&quot;text/html; charset=UTF&#x2212;8&quot;&gt; 
    &lt;/head&gt; 
    &lt;body&gt; 
        Hello &lt;b&gt;World&lt;/b&gt;!!!!!!! 
        Go to &lt;a href=docs/otherdoc.html&gt; another document &lt;/a&gt; 
    &lt;/body&gt; 
&lt;/html&gt;</code></pre><p><em>You can see how it is displayed in the browser simply by copying and pasting the previous code into an HTML document and dragging it into your browser. Of course it will not link you to any other document, as the path points to a document which does not exist.</em></p><p><strong>Final HTML remarks:</strong></p><p>On the other hand, blank spaces and new lines are called &#x201D;whites&#x201D;. You can add as many &#x201D;whites&#x201D; as you like to make your HTML file easier to read but browsers display consecutive whites as a single space. If you need to create a paragraph, you have to use the labels <code>&lt;p&gt; ... &lt;/p&gt;</code>. For paragraphs, the browser will adjust the text lines correctly based on the window width. If you really want to force a new line, you have to use the <code>&lt;br&gt;</code> tag. <br>HTML has many tags but with a few of these tags, we can have an idea about how HTML works.</p><p>Some other useful tags are:</p><ul><li><code>&lt;i&gt; &lt;/i&gt;</code> Sets text in italics.</li><li><code>&lt;tt&gt; &lt;/tt&gt;</code> Sets text in teletype.</li><li><code>&lt;h1&gt; &lt;/h1&gt;</code> Sets text in type &#x201C;header 1&#x201D;. You can use numbers of headers in descending order of importance (size):</li><li><code>&lt;h2&gt;:</code> &lt;h2&gt;This is h2 &lt;/h2&gt; . . . <code>&lt;h6&gt;</code>: &lt;h6&gt;This is h6 &lt;/h6&gt;</li><li><code>&lt;hr&gt;</code> Prints an horizontal line.</li><li><code>&lt;center&gt; &lt;/center&gt;</code> Centers text and images.</li><li><code>&lt;blockquote&gt; &lt;/blockquote&gt;</code> Indents text.</li><li><code>&lt;pre&gt; &lt;/pre&gt;</code> Pre-formatted text, i.e. spaces and line breaks between these tags are maintained.</li><li><code>&lt;!-- text comments... --&gt;</code> Comments in the HTML file.</li><li>and many more tags&#x2026;</li></ul><hr><h4 id="http-motivation">HTTP Motivation</h4><p>Initially, HTTP (Hypertext Transfer Protocol) arised from the necessity of creating hyperlinks in HTML documents to resources that are not on the same host.</p><p>HTTP is a text protocol and it is based on a client/server model that can be used over a TCP/IP network to deliver virtually any resource of the World Wide Web (WWW). For now, we will consider that a resource is just an HTML document. An HTTP server or WEB server is a network daemon that uses by default the well-known <strong>TCP port 80</strong>.</p><p><strong>HTTP clients</strong>, generically called WEB Browsers (e.g. firefox or lynx), send HTTP requests to the HTTP servers asking for a resource and the server responds with the requested resource.</p><h4 id="url-uri">URL / URI</h4><p>The first issue to implement HTTP is to define <strong>how to identify resources.</strong></p><p>The identifiers used in HTTP were initially defined by Tim Berners in 1991. They were called URLs (Uniform Resource Locators) and they were first used to allow authors of HTML documents to establish hyperlinks in the WWW.</p><p>An URL is just a text string with a standard format that allows you to name a resource based on its location on the WWW. In 1994, the URL concept was incorporated into a more general concept called URI (Uniform Resource Identifier).</p><p>URI is the standard name for resource identifiers in the Internet, but the term URL is still widely used. The simplest URL/URI format is as follows:</p><p><code>protocol :// hostname / directory / resource</code></p><p>But other information can also be present in the URL:</p><p><code>protocol :// username : password@hostname : port / directory / resource</code></p><p><em>Important note:</em> If in the URL there is not any resource (filename) specified, it is assumed that the client is asking for a file called <strong>index.html</strong> or <strong>index.htm</strong>.</p><p>As its name suggests, this file contains an HTML file with the website index.</p><p>On the other hand, we can use absolute or relative paths in HTTP hyperlinks. In an HTTP server, absolute paths are related to a directory called DocumentRoot.</p><p>This parameter is defined in the configuration file of the HTTP server.</p><p>For example, a typical DocumentRoot when using Linux is <strong>/var/www</strong>. In this case, the URL <a href="http://www.example.com/images/upc1.gif?ref=blog.lares21.xyz" rel="noopener">http://www.example.com/images/upc1.gif</a> refers to a file called upc1.gif that is stored in the HTTP server in the directory <strong>/var/www/images</strong>.</p><p>We can see the difference between absolute and relative paths in the following piece of code:</p><pre><code>&lt;html&gt; 
    &lt;head&gt; 
        &lt;title&gt; Hello World&lt;/title&gt; 
    &lt;/head&gt; 
    &lt;body&gt; 
        &lt;p&gt;Hello &lt;b&gt;World&lt;/b&gt;!!!!!!!&lt;/p&gt; 
        &lt;p&gt;Go to &lt;a href=docs/otherdoc.html&gt; another document &lt;/a&gt;&lt;/p&gt; 
        &lt;p&gt;You can visit the UPC home page at &lt;a href=&quot;http://www.upc.edu&quot;&gt;UPC home&lt;/a&gt;. &lt;/p&gt; 
        &lt;img src=&quot;/images/upc1.gif&quot;&gt; 
        &lt;img src=&quot;/images/upc2.gif&quot;&gt; 
        &lt;img src=&quot;http://www.example.com/images/upc1.gif&quot;&gt; 
    &lt;/body&gt; 
&lt;/html&gt;</code></pre><hr><h4 id="http-10">HTTP 1.0</h4><p>As we already said, HTTP is a protocol that uses the client-server model.</p><p>To start using it, we do need the client to know the server port and include it in the URL.</p><p><em>How does it work?</em></p><p>First the HTTP client opens a TCP connection and sends an <strong>HTTP request</strong> to an HTTP server. If everything is correct, HTTP server returns a response which contains the requested resource.</p><p>Once the response is delivered, HTTP server closes the TCP connection.</p><p><em>Note:</em> HTTP is a stateless protocol. It does not maintain information between different requests.</p><h4 id="http-requests">HTTP Requests</h4><p>When we do have an HTTP request, the first line is the ONLY mandatory one. It contains:</p><ul><li><strong>&#x201C;Request method&#x201D;</strong></li><li><strong>Path to the resource</strong></li><li><strong>HTTP version</strong></li></ul><p>Then it follows a blank line (to tell the protocol it&#x2019;s the request end).</p><p>The minimal HTTP 1.0 request is something like the following:</p><pre><code>GET / HTTP/1.0 
[blank line]</code></pre><p><strong>GET</strong> is the most commonly used <strong>request method</strong> and it means &#x201C;give me the resource X&#x201D;. After the GET we find a &#x201C;/&#x201D; and this means the resource we are requesting is the index file of the WEB server.</p><p>Another example requesting another file would be like this:</p><pre><code>GET /images/upc1.gif HTTP/1.0 
[blank line]</code></pre><p>In this case the client is requesting a file called <em>upc1.gif</em> that is stored in the HTTP server in the <em>images</em> directory.</p><h4 id="headers">Headers</h4><p>Request &amp; Responses can have header lines.</p><p>This Headers are text lines that provide additional information or functionality in requests/responses.</p><p>The usual format for Headers is: &#x201C;Header-Name: value1, value2&#x201D; , ending with CR+LF (blank line). The header name is NOT case-sensitive.</p><p>Examples of Headers (the both are equivalent) would be something like this:</p><pre><code>Header1: some-long-value-1a, some-long-value-1b 
 
Header1: some-long-value-1a 
    some-long-value-1b</code></pre><p>HTTP 1.0 defines 16 headers, though <strong>none is required</strong>. Typical headers included in the requests are:</p><ul><li>From (email adresses of the user who makes the request)</li><li>User-Agent (name of the browser and OS)</li></ul><p>An example of a request with headers would be the following:</p><pre><code>GET /path/file.html  HTTP/1.0 
From: user@example.net 
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0 
[blank line]</code></pre><h4 id="http-responses">HTTP Responses</h4><p>HTTP Responses are also composed of text lines. The first text line of an HTTP response is the <strong>status</strong>.</p><p>Typical status lines are:</p><pre><code>HTTP/1.0 200 OK 
HTTP/1.0 404 Not Found</code></pre><p>Let&#x2019;s explain <strong>what do the numbers mean</strong>:</p><p>The <strong>first digit</strong> identifies the general category of the status:</p><ul><li><strong>1xx</strong> indicates and <strong>informational message</strong> only</li><li><strong>2xx</strong> indicates <strong>success</strong> of some kind</li><li><strong>3xx</strong> <strong>redirects</strong> the client <strong>to another URL</strong></li><li><strong>4xx</strong> indicates an <strong>error in the client side</strong></li><li><strong>5xx</strong> indicates an <strong>error in the server</strong></li></ul><p><em>Examples</em></p><ul><li>200 OK</li><li>301 Moved Permanently</li><li>302 Moved Temporarily</li><li>303 See Other</li><li>404 Not Found</li><li>500 Server Error</li><li>503 Not Available</li></ul><p>Furthermore we can also add Headers to the responses. The headers typically included in responses are:</p><ul><li>Server (identifies the server software)</li><li>Date</li><li>Last-Modified (date of last modification of the resource being returned) &#x2190; Used for caching</li></ul><h4 id="final-http-10-example">Final HTTP 1.0 example</h4><p>Imagine we want to retrieve the file <a href="http://www.example.com/path/file.html?ref=blog.lares21.xyz" rel="noopener"><em>http://www.example.com/path/file.html</em></a> using HTTP 1.0, the first step is to open a TCP connection with the server using the default port 80.</p><p>Then through this connection, the client can send a request like the following:</p><pre><code>GET /path/file.html HTTP/1.0 
From: user@example.net 
[blank line]</code></pre><p>And the server would respond with something like the following:</p><pre><code>HTTP/1.0 200 OK 
Date: Mon, 21 Oct 2013 22:29:59 GMT 
Content-Type: text/html 
Content-Length: 50 
[blank line] 
&lt;html&gt; 
    &lt;body&gt; 
        &lt;h1&gt;It works!&lt;/h1&gt; 
    &lt;/body&gt; 
&lt;/html&gt;</code></pre><p>Once the response is received, <strong>the client closes</strong> the TCP socket.</p><hr><h4 id="cookies">Cookies</h4><p>As we explained previously, HTTP is a <strong>stateless</strong> protocol.</p><p>A <strong>cookie</strong> is a piece of information (<a href="https://en.wikipedia.org/wiki/UTF-8?ref=blog.lares21.xyz" rel="noopener">UTF8 text</a>) sent from an HTTP server and that is stored by the browser <strong>in the client&#x2019;s filesystem</strong>.</p><p>Sometimes cookies are also called &#x201C;footprints&#x201D;.</p><p>These cookies <strong>provide a state</strong> (memory of previous events) into otherwise stateless HTTP transactions.</p><p>Without cookies, <strong>each retrieval</strong> of a webpage, or even a single component, is an <strong>isolated event</strong>.</p><p>The most common uses of cookies are:</p><ul><li>User Control (For ex: when a user enters his username and pwd, a cookie can store this information so there is no need to enter them again in a later visit to the web server).</li><li>Getting information about user&#x2019;s browsing habits.</li></ul><h4 id="how-do-cookies-work">How do cookies work?</h4><p>The HTTP server sends lines with the <strong>Set-Cookie header</strong> if the server wishes the browser to store these cookies.</p><p>Set-Cookie is a directive for the browser to store the cookie and send it back in future requests to the server (subject to expiration time or other cookie attributes).</p><p>Let&#x2019;s see a visual example:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-fmq7qdhwqaksv55oy4y9mq.png" class="kg-image" alt="Internet Educational Series #6: WWW (HTML, HTTP(S), Cookies&#x2026;)" loading="lazy" width="800" height="424" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-fmq7qdhwqaksv55oy4y9mq.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-fmq7qdhwqaksv55oy4y9mq.png 800w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Cookies</span></figcaption></figure><p>We can describe the process going on in the above picture:</p><ol><li>The client sends a regular request.</li><li>The server asks the client to store that cookie.</li><li>The client sends the cookie in a subsequent request, when it is needed.</li></ol><p>It is worth knowing that the cookies do have more fields, like path and domain, which help in deciding when to send it or not.</p><p>As you can imagine, cookies can cause (and are actually causing) privacy problems.</p><hr><h4 id="http-proxies">HTTP Proxies</h4><p>An HTTP <strong>proxy</strong> is a program that acts as an <strong>intermediary between a browser and a Web Server</strong>.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-ni8bfrmo9p02q1tr3rfbpg.png" class="kg-image" alt="Internet Educational Series #6: WWW (HTML, HTTP(S), Cookies&#x2026;)" loading="lazy" width="800" height="600" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-ni8bfrmo9p02q1tr3rfbpg.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-ni8bfrmo9p02q1tr3rfbpg.png 800w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Proxy example (provided by wikipedia)</span></figcaption></figure><p>HTTP proxies are commonly used for <em>security</em> (a single point of control) and <em>efficiency</em> (caching).</p><p>There are two basic types of proxies (from users point of view):</p><ul><li><strong>Tranparent</strong>: A transparent proxy intercepts normal communication at the network layer without requiring any special client configuration. Clients do not need to be aware of this proxy existence.</li><li><strong>Non Tranparent</strong>: This types of proxies receive requests from the clients and sends the requests to the servers. The responses go the same way back also using the proxy. Therefore, a proxy must have functions of either client &amp; server. A non-tranparent proxy can use another transparent or non-transparent proxy to reach the final server.</li></ul><p>Clients send their requests to the proxy instead of the real server specified in the URL. &#x2190; <em>The proxy IP address and port is defined in the browser</em></p><p>HTTP requests using a non-transparent proxy must include the full URL of the resource (not only relative path), as the proxy has to know which server it must send the HTTP request.</p><p>A request using a non-transparent proxy would be something like this:</p><pre><code>GET http://www.somehost.com/path/file.html HTTP/1.0 
[blank line]</code></pre><p>Lastly, it is nice to know there are many Open Source Proxies used widely.</p><hr><h4 id="dynamic-web">Dynamic Web</h4><p>In today&#x2019;s Web, the content is not static, but documents are generated on the fly by servers with information provided by clients.</p><p>As a result, WWW is not a huge database of documents, but a platform to implement services &amp; applications.</p><p>Common applications of the dynamic web are searching engines, remote access to corporate applications and databases, etc.</p><h4 id="cgis">CGIs</h4><p><em>Note: We do have several ways of implementing the dynamic Web. In this document, we will only explain CGIs, as they are easier to understand, and they were the first method used for that specific purpose.</em></p><p><strong>CGIs</strong> or <strong>Common Gateway Interfaces</strong> are a standard procedure through which HTTP servers can use external applications to dynamically generate content.</p><p>When we want to use a CGI, in the URL we must identify:</p><ul><li>An executable program (the CGI itself)</li><li>The <strong>parameters</strong> with which the CGI has to be executed.</li></ul><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-nu4q_qluzmmvk3emjrmiaw.png" class="kg-image" alt="Internet Educational Series #6: WWW (HTML, HTTP(S), Cookies&#x2026;)" loading="lazy" width="800" height="352" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-nu4q_qluzmmvk3emjrmiaw.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-nu4q_qluzmmvk3emjrmiaw.png 800w" sizes="(min-width: 720px) 720px"></figure><p>However, when we use CGIs we find some issues we need to solve.</p><p>The first one is <em>how a web server knows that is has to execute a program instead of sending a resource</em>. &#x2192; A usual solution is to <strong>store all the CGIs in a special directory</strong>, typically called <strong>/cgi-bin/</strong>. In this way, if a client asks for <a href="http://www.examplecom/cgi-bin/program?ref=blog.lares21.xyz" rel="noopener"><em>www.examplecom/cgi-bin/program</em></a> the server knows that it must execute <em>program</em> instead of sending it.</p><p>The second is how to send the parameters to the <em>program</em>. When we use GET, the parameters are encoded in the URL. These parameters are added to the URL after a <strong>&#x201C;?&#x201D;</strong> character, and separated by the character <strong>&#x201C;&amp;&#x201D;</strong>.</p><p>Example:</p><pre><code>http://www.example.com/cgi-bin/program?param1=value1&amp;param2=value2...</code></pre><p><em>Note: Spaces are translated into the &#x2018;+&#x2019; character, and ASCII characters can also be sent in the %NNN format</em>.</p><p>Finally, before executing the CGI, the Web server establishes a special context for the <em>program</em> using environment variables, to ensure a correct execution of it.</p><p>These variables are:</p><p><strong>CONTENT_LENGTH, CONTENT_TYPE, REMOTE_HOST, REMOTE_USER, REQUEST_METHOD, SERVER_NAME, QUERY_STRING, GATEWAY_INTERFACE, HTTP_&#x2019;VERSION&#x2019;</strong></p><p>For GET requests, the QUERY_STRING variable takes the value of the parameters and the CGI can use them as the client has specified.</p><p>For the response, the CGI writes it to the <strong>STDOUT</strong>. Then the server reads this answer and sends it to the client through the socket.</p><p>Depending on the type of web server, the CGI application can act in two different ways:</p><ul><li><strong>NPH Server</strong> (No Parse Headers) &#x2192; The CGI writes the complete response <strong>including the HTTP headers</strong>.</li><li><strong>PH Servers</strong> (Parse Headers) &#x2192; The CGI writes the complete response <strong>without the HTTP headers</strong>, and it must pass information on how to form them.</li></ul><p>The most common web servers are NPH.</p><p>Finally, it should be remarked that CGIs are not the most efficient solution because <strong>a process is created per request</strong>, and nowadays there are too many requests to be handled in this way.</p><p>Today&#x2019;s more efficient solutions to create dynamic websites are languages like Javascript, Python, PHP, Java servlets, etc.</p><hr><h4 id="other-common-methods-in-requests-head-and-post">Other (common) methods in Requests: <strong>HEAD</strong> and <strong>POST</strong></h4><ul><li>The <strong>HEAD</strong> method is used when we want a response only with the status line and headers (without a body).</li></ul><p><em>HEAD is useful when the resources from the server are not actually needed. This can be the case in which we need to make some tests but we do not want to download a resource (which can be heavy)</em></p><ul><li>The <strong>POST</strong> request is used for dynamic Web. The difference between POST and GET is that POST requests use the body of the request to send parameters instead of coding the parameters directly into the URL.</li></ul><p><em>CGIs with POST use the STDIN to receive the request body (program&#x2019;s parameters) instead of using the QUERYSTRING variable</em></p><hr><h4 id="html-forms">HTML Forms</h4><p>An HTML form <em>allows a client to send parameters to a WEB server</em>.</p><p>The tag to declare a form is <strong>&lt;form&gt; &#x2026; &lt;/form&gt;</strong> where different elements can be inserted inside, like text input elements, codes, images, checkboxes&#x2026;</p><p>These elements are inserted into the form using the tag <strong>INPUT</strong>. All items of the form have a &#x201C;type&#x201D; attribute and they might have a &#x201C;name&#x201D; attribute.</p><p>There are 2 special elements in forms: RESET, which clears the form to its initial state, and SUBMIT, which presents a button to send the form to the server.</p><p>Example of an HTML form, and how it is displayed in the browser:</p><pre><code>&lt;html&gt; 
    &lt;head&gt; 
        &lt;title&gt; Website title &lt;/title&gt; 
    &lt;/head&gt; 
    &lt;body&gt; 
        Form to select parametres to send to the server. 
        &lt;form ACTION=&quot;/cgi&#x2212;bin/process&quot; METHOD=&quot;GET&quot;&gt; 
            Enter a name: &lt;INPUT NAME=&quot;a&quot; TYPE=&quot;text&quot;&gt; &lt;br&gt; 
            Enter a password: &lt;INPUT TYPE=&quot;password&quot; NAME=&quot;b&quot; 			MAXLENGHT=&quot;8&quot;&gt; &lt;br&gt; 
            Checkbox: &lt;INPUT TYPE=&quot;checkbox&quot; NAME=&quot;c&quot;&gt; &lt;br&gt; 
            &lt;INPUT TYPE=&quot;reset&quot;&gt; &lt;INPUT TYPE=&quot;submit&quot;&gt; 
        &lt;br&gt; 
        &lt;/form&gt; 
    &lt;/body&gt; 
&lt;/html&gt;</code></pre><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-kfrao8l21witcng2qhwntg.png" class="kg-image" alt="Internet Educational Series #6: WWW (HTML, HTTP(S), Cookies&#x2026;)" loading="lazy" width="800" height="533" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-kfrao8l21witcng2qhwntg.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-kfrao8l21witcng2qhwntg.png 800w" sizes="(min-width: 720px) 720px"></figure><p>When the form is submitted, the client generates an HTTP request using the method showed in the METHOD attribute (GET in this case), to execute the script or application indicated in the ACTION attribute.</p><hr><p>The most common question regarding Dynamic Web is: <strong>Should I use GET or POST?</strong></p><p>Each method has its advantages and drawbacks.</p><p><strong>GET</strong></p><p>When using GET, the parameters are encoded in the URL. This can be useful in many cases, but if we want to protect some sensible information, the GET method could cause <strong>security vulnerabilities</strong>, because the parameters will be shown to everyone in the URL.</p><p>Another drawback of GET is that it does not allow to send binary files in the body of the request.</p><p>However, GET is useful to perform requests and store the results together with the associated URL.</p><p>GET also allows to use the <strong>back buttons</strong> to go to previous results.</p><p><strong>POST</strong></p><p>With POST, the parameters are sent in the body of the request, so the parameters <strong>are not visible</strong> in the browser as a query string.</p><p>In general, GET is useful for operations which always give the same results (idempotent).</p><p>POST means &#x201C;carry out&#x201D; an action with a &#x201C;side effect&#x201D; or a <em>change of state</em> (non-idempotent operations).</p><hr><h4 id="http-11">HTTP 1.1</h4><h4 id="introduction">Introduction</h4><p>The main difference between protocols 1.0 and 1.1 is that on 1.1 it is compulsory to add a <strong>HOST header</strong></p><p>The most important improvements made to the protocol are the following ones:</p><h4 id="host-header">Host Header</h4><p>Provides (a more) efficient use of IP addresses. With 1.1, <strong>multiple domains can be served from a single IP address</strong>.</p><p>For example, we could have <a href="http://www.example.com/?ref=blog.lares21.xyz" rel="noopener">www.example.com</a> and <a href="http://www.example.net/?ref=blog.lares21.xyz" rel="noopener">www.example.net</a> on the same server. Thus, HTTP1.1 must specify in the header to which host the request is destined. A minimal HTTP 1.1 request with the hostname would be something like:</p><pre><code>GET / HTTP/1.1 
Host: www.example.com:80 
[blank line]</code></pre><p>Where we can see the domain name (or IP) of the WEB server, and the port number (in this case <strong>80</strong>, as it&#x2019;s the <strong>default port for HTTP</strong>).</p><h4 id="chunked-encoding">Chunked Encoding.</h4><p>Allows a faster response for dynamically generated pages. Pages are divided and sent in chunks (fragments). This way, responses can be sent before its total content or length is known.</p><p>When we use HTTP 1.1, it does send the body of the message as several fragments, followed by a line with a &#x201C;0&#x201D;. Optionally followed by the page footer.</p><p>Each chunk consists of two parts:</p><ol><li>A line with the size of the chunk in hexadecimal + CR + LF</li><li>Data + CR + LF</li></ol><p><em>(CR + LF == blank line)</em></p><p><strong>Example WITHOUT chunks:</strong></p><p>HTTP/1.1 200 OK<br>Content-Type: text/plain<br>Content-Length: 42<br>[blank line]<br>abcdefghijklmnopqrstuvwxyz1234567890abcdef</p><p><strong>Same example WITH CHUNKED DATA:</strong></p><p>HTTP/1.1 200 OK<br>Content-Type: text/plain<br>Transfer-Encoding: chunked<br>[blank line]<br>1a<br>abcdefghijklmnopqrstuvwxyz<br>10<br>1234567890abcdef<br>0<br>[blank line]</p><h4 id="persistent-connections">Persistent Connections</h4><p>A TCP connection <em>is not opened/closed for each request</em>. By allowing multiple HTTP transactions in every TCP connection, we can reduce the total transmission delay.</p><p>In HTTP 1.0, TCP connections are closed after each request/response by default.</p><p>As we know, opening/closing TCP connections requires a substantial amount of CPU time, bandwidth, and memory. In practice, most web pages consist of several files (linked HTML documents, images, etc.) that are located on the same server.</p><p>Consecutive requests (and their associated responses) can be more efficiently transmitted by allowing multiple requests/responses to be sent over a single connection.</p><p><strong>In HTTP 1.1, persistent connections are used by default</strong>.</p><p>Once the client decides it doesn&#x2019;t want to send any more requests, it sends a request with a Header which includes: <strong>&#x201C;<em>Connection: close</em>&#x201D;.</strong></p><p>Then the server has to close the connection after the reply.</p><p>If the server is the one who sends the header with &#x201C;Connection: close&#x201D; then the client cannot send more requests, and it must close the connection after the response is received.</p><p>*Note that a server may close a connection before it answers all the requests.</p><p>The HTTP 1.1 client can also send multiple requests through a single connection without having received any response (pipelining).</p><p>On its side, an HTTP 1.1 server must store queued requests while it cannot process them, and it must send the responses in the same order as it received the requests. If a request includes the header &#x201D;Connection: close&#x201D; , the server must interpret this as that the request is the latest and it must close after sending the corresponding response.</p><p>Finally, it is worth to mention that typically, clients (browsers) open several simultaneous persistent TCP connections with each server.</p><h4 id="caching">Caching</h4><p>Headers to implement caching are provided with HTTP 1.1.</p><p>This allows a <strong>faster response and bandwidth saving</strong>.</p><p>All the responses (including errors) except the &#x201C;Continue&#x201D; ones (status 100) should include the header &#x201D;date&#x201C;. This header provides a time stamp which is used by HTTP 1.1 to implement caching. These time stamps use the Greenwich Mean Time (GMT).</p><p>There are two headers called <strong>&#x201D;If-Modified-since&#x201C;</strong> and <strong>&#x201D;If-Unmodified-Since&#x201C;</strong> that can be included in HTTP requests.</p><h4 id="continue">Continue</h4><p>When we want to send a message with a big body (big file), we can use the &#x201C;Continue&#x201D; (status 100) mechanism.</p><p>This mechanism is used to determine if we do really want to receive a message or not, as if we cannot process it, we can save time and resources by rejecting the message.</p><p>To use the Continue mechanism, clients must include the header: <strong>&#x201C;Expect: 100-continue&#x201D;</strong>. Then if the server is going to process the request must respond with 100 (Continue) status.</p><p><em>Note: A client should not send the Expect header if it&#x2019;s not going to send any body in its request.</em></p><hr><p>As a final remark, it is worth mentioning that</p><p><strong>HTTP 1.1 clients</strong> should:</p><p>&#x2022; Include host header in each request.</p><p>&#x2022; Accept responses with chunked data.</p><p>&#x2022; Accept persistent connections or include the header &#x201D;Connection: close&#x201D;.</p><p>&#x2022; Manage the response &#x201D;100 Continue&#x201D;.</p><p><strong>HTTP 1.1 servers</strong> should:</p><p>&#x2022; Require the host header in requests.</p><p>&#x2022; Accept absolute URLs.</p><p>&#x2022; Accept &#x201D;chunked&#x201D; requests.</p><p>&#x2022; Manage persistent connections (or use the header &#x201C;Connection: close&#x201D;)</p><p>&#x2022; Properly use the status &#x201D;100 Continue&#x201D;.</p><p>&#x2022; Include the date in the header &#x201D;date&#x201D; in each response (except Continue).</p><p>&#x2022; Manage requests with headers &#x201C;If-Modified-Since&#x201D; or &#x201C;If-Unmodified-Since&#x201D;</p><p>&#x2022; At least, support the methods GET and HEAD.</p><p>&#x2022; Support HTTP 1.0 requests.</p><hr><h4 id="nginx">NGINX</h4><h4 id="introduction-1">Introduction</h4><p>NGINX (pronounced &#x201C;engine x&#x201D;) was born as a reverse proxy with minimal HTTP WEB server functions.</p><p>It addresses most of the server activities performed in the web world, such as:</p><ul><li><strong>Serving static content</strong> (i.e. static web pages, files, etc.).</li><li><strong>Dynamic content provisioning</strong> (e.g. using FastCGI)</li><li><strong>Caching content</strong> to speed up service provisioning.</li><li><strong>Load balancing</strong> for any TCP or UDP service (e.g. HTTP requests, DNS resolution requests, etc.).</li><li><strong>Securing channels</strong> for applications not supporting HTTPS connections.</li></ul><p>NGINX can run in several platforms, including Linux, FreeBSD, Windows and MacOS. Without going into the technical details, developers and network engineers tend to prefer <strong>nginx over Apache as</strong>:</p><ul><li>It&#x2019;s easier to configure.</li><li>It scales better in terms of resources and performance as the load increases.</li><li>It is extremely flexible: provides load balancing, cache, web server, etc. in a single piece of software.</li></ul><p>Debian-based distros store the nginx configuration files in the directory <strong><code>/etc/nginx</code>.</strong></p><p><strong>NOTE: if you change the configuration of the daemon you have to stop and start it to apply the changes.</strong></p><p>To stop nginx type:</p><p><code># /etc/init.d/nginx stop</code></p><p>To start the daemon:</p><p><code># /etc/init.d/nginx start</code></p><h4 id="virtual-hosts">Virtual Hosts</h4><p>A virtual Host is a web site served by the HTTP server. Each virtual host has it&#xA1;s on configuration file, which can be found at:</p><p><code>/etc/nginx/conf.d</code> folder.</p><p>Apart we can find a list of available virtual hosts at <code>/etc/nginx/sites-available</code></p><p>The <strong>default</strong> virtual host is (unless we modify it) the first configuration file, but we can also specify a virtual host by including the <code>default_server</code> keyword next to the listening port inside its configuration file.</p><h4 id="cgis-with-nginx">CGIs with nginx</h4><p>CGIs are not directly supported by nginx, but we can use the <code>FastCGI</code> library to provide the CGIs functionality along with nginx.</p><h4 id="load-balancing">Load Balancing</h4><p>One of the most useful features of the nginx server is the capability to balance the load.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-boyq0qye7l4my7orowayng.png" class="kg-image" alt="Internet Educational Series #6: WWW (HTML, HTTP(S), Cookies&#x2026;)" loading="lazy" width="800" height="438" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-boyq0qye7l4my7orowayng.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-boyq0qye7l4my7orowayng.png 800w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">nginx</span></figcaption></figure><p>We can achieve load balancing just by creating and upstream configuration as:</p><pre><code>upstream tcgi&#x2212;app { 
    server www1.example.com; 
    server www2.example.com; 
} 
server { 
    listen 80; 
    server_name www.example.com ; 
    location / { 
        proxy_set_header X &#x2212;Real&#x2212;IP $remote_addr ; 
        proxy_set_header X &#x2212;Forwarded&#x2212;For $remote_addr ; 
        proxy_set_header Host $host ; 
        proxy_pass http://tcgi-app$request_uri; 
    } 
}</code></pre><p>The nginx server provides several approaches to balance the traffic:</p><ol><li>Round Robin: The default approach</li><li>Least busy: NGINX will try not to overload a busy server with excessive requests, distributing the new request to a less busy server instead.</li><li>Session Persistance: The clients are tied to a particular application server per session.</li><li>Weights: It is also possible to assign a certain weight to a server. This is interesting when using the Round Robin approach, and we can use the <code>weight</code> parameter next to the server configuration to weight the traffic addressed to that server.</li></ol><hr><h4 id="https">HTTPS</h4><p>Up to this point, we&#x2019;ve been seeing how does the HTTP protocol work, but we&#x2019;ve encountered many times the same problem&#x2026; <strong>Security</strong>.</p><p>To solve this issue, a new protocol had to be implemented, and as you may have guessed, the protocol was <strong>HTTPS</strong>.</p><p>To implement this security layer on top of HTTP, different cryptographic methods have been used.</p><p>The main algorithms used to implement HTTPS are the following ones:</p><h4 id="1-symmetric-cryptography">1. <strong>SYMMETRIC Cryptography</strong></h4><p>What does that even mean? It just means that either the sender and the receiver use the same key both to encrypt and decrypt the message.</p><p>It does NOT mean that same algorithms are used, nor that the messages are encrypted in a symmetric way, simply that the same key is shared.</p><p>That&#x2019;s why it&#x2019;s also called <strong>Symmetric key cryptography</strong>, or <strong>shared secret cryptography</strong>.</p><p>The most used algorithm en symmetric cryptography has been the DES (and triple DES), until the AES was invented, which can have longer keys than DES.</p><p>Using this cryptographic systems we won confidentiality in our message sharing process through the internet, but <em>another problem is detected when using symmetric cryptography</em>, and it is the fact of sharing keys between participants, as they should know each other and share they key between them before initiating the data transmission.</p><h4 id="2-asymmetric-cryptography">2. <strong>Asymmetric Cryptography</strong></h4><p>Brought by the problem that we just described, another type of Cryptography appeared, where sender and receiver do NOT need to share any secret nor key. This is called <strong>Public Key Cryptography</strong>.</p><p>In this type of cryptography, each user has <strong>a pair of keys</strong>:</p><ul><li>A <strong>public</strong> key (everyone can see it)</li><li>A <strong>private</strong> key (only the user knows it)</li><li>One of them will be used to encrypt the message (public), and the other one to decrypt it (private).</li></ul><p><strong>Asymmetric algorithm example</strong><br>Alice wants to send an encrypted message to Bob. To do it using asymmetric cryptography she does the following:</p><ul><li>Alice uses <strong>Bobs Public key</strong> to encrypt her message.</li><li>The message is encrypted thanks to Bobs Public key, and it is send to Bob (now only Bob&#x2019;s key can decrypt that message, no one else, not even Alice)</li><li>Bob receives the encrypted message and he uses its <strong>Private key</strong> to decrypt it, and this way he can read the message.</li><li><em>The most used algorithms in Asymmetric Cryptography </em>are RSA, DSA (Digital Signature), ECDSA&#x2026;</li></ul><h4 id="3-hash-function">3. <strong>HASH Function</strong></h4><p>The Hash function appeared due to the <em>performance</em> problem we had when searching for data inside DataBases, which were usually alphabetically sorted.</p><p>It was seen that using the hash function was MUCH more efficient as:</p><ul><li>A number is assigned to each message&#x2019;s character.</li><li>All this numbers are added.</li><li>The 100 module is applied to the result of the previous step.</li><li>We obtain the HASH value.</li></ul><p>This HASH value is much easier to fins inside a DB.</p><p>One of the main characteristics of the Hash function is that it doesn&#x2019;t matter the variable inputs that it gets, but the <strong>output is always fixed</strong>.</p><p>A problem that this may cause is that <strong>multiple inputs can produce the same output</strong>, and so collisions appear.</p><p>So how can we reduce the collision probability?</p><ol><li>Increment the module operation (mod10000)</li><li>Use a different codification (p.ex. ASCII)</li></ol><p>But <strong>is there a way to achieve a virtually impossible collision probability?</strong></p><p>&#x2014; &gt; Using the <strong>CRYPTOGRAPHIC HASH</strong></p><p>This algorithm uses <strong>SHA256</strong>, which works like this:</p><ul><li>We introduce a variable Input</li><li>Returns 256 bits (output)</li></ul><p>The difference is that now is <em>practically</em> impossible to guess which is the original message only from the output (only with brute force attacks).</p><p>So as we cannot return to the original message, it is possible that collisions appear, but we won&#x2019;t know where this collisions come from.</p><h4 id="4-digital-signatures">4. <strong>Digital Signatures</strong></h4><p>Digital Signatures generation:</p><ol><li>Alice calculates the message hash (HASH FUNCTION)</li><li>Alice encrypts the hash with her private key (RSA)</li><li>Alice sends the message and the signed hash to Bob.</li></ol><p>(<em>Note: The 256 bit hash identifies univocally the message, and the private key identifies Alice univocally</em>)</p><ol><li>Bob receives the encrypted message &#x2192; He calculates the message&#x2019;s hash.</li><li>He decrypts the signed hash using Alice&#x2019;s public key.</li><li>If both keys coincide, the signature is valid, and Bob can access the message.</li></ol><h4 id="5-hybrid-cryptography">5. <strong>Hybrid Cryptography</strong></h4><p>We can divide the message that we want to send in blocs, encrypting each block with the public key from the destiny.</p><p><strong>Asymmetric cryptography is more secure, but Symmetric cryptography is faster.</strong></p><p>With a combination of them both we can achieve much better performance.</p><p>To use them together we can do it like this:</p><ul><li>Asymmetric Cryptography is used to exchange <strong>a session key</strong></li><li>Then Symmetric Cryptography is used to share the encrypted data.</li></ul><h4 id="6-digital-certificates">6. <strong>Digital Certificates</strong></h4><p>The Digital Certificates contain:</p><ul><li>Camps to <strong>describe the identity</strong></li><li>Serial Number</li><li>Validation Period</li><li>The Public Key algorithm</li><li>The CA Public Key</li><li>The algorithm used to sign the certificate</li><li>Camps with the certificate&#x2019;s purpose and additional information</li></ul><h4 id="7-openssl">7. <strong>OpenSSL</strong></h4><p>OpenSSL is the most used implementation to <strong>create and manage keys and certificates</strong></p><h4 id="8-https">8. <strong>HTTPS</strong></h4><p>Finally, after doing a quick cryptography introduction we can get back to HTTPS.</p><p>This protocol is implemented with the security that our data cannot be intercepted while it is traveling through the internet.</p><p>WebApps use Hybrid Cryptography and Digital Certificates to secure their transactions.</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-nycqolkg729zehkclc_wig.png" class="kg-image" alt="Internet Educational Series #6: WWW (HTML, HTTP(S), Cookies&#x2026;)" loading="lazy" width="800" height="319" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-nycqolkg729zehkclc_wig.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-nycqolkg729zehkclc_wig.png 800w" sizes="(min-width: 720px) 720px"></figure><p>To secure the transactions, the browser does various security checks to make sure that we are connected to the correct server:</p><ol><li>Is the Digital Certificate well signed?</li><li>Do I know the CA public key?</li><li>Has the certificate expired?</li><li>Is the URL the same as the certificate&#x2019;s one?</li></ol><p><em>Note: Browsers have lists of Public Keys from CAs, to be able to comply with point 2.</em></p><h4 id="tls-tunnel"><strong>TLS Tunnel:</strong></h4><p>To prove that we are connected to the correct server the following steps need to be checked:</p><h4 id="from-the-browser"><strong>From the Browser</strong></h4><ul><li>A Symmetric Session Key is generated (Ks) and sent to the server.</li><li>The Session Key is encrypted with the Public key that appears on the certificate.</li></ul><h4 id="from-an-honest-server"><strong>From an HONEST Server</strong></h4><ul><li>It will have the corresponding <strong>Private Key (Kp)</strong> to our Public Key (Ku) (if the server was not the correct one, it would not have the Private Key).</li><li>The message is decrypted using the corresponding Private Key, and we send the Session Key back to the browser to demonstrate that we are the correct server, and that we have the Private Key that is needed.</li></ul><p>And this would be an introduction on how does <strong>HTTPS</strong> work, and the methods used to secure or communications online.</p><hr><p>This is not at all everything that the HTTP protocol involves, as other versions like HTTP 2.0 and 3.0 exist, but we&#x2019;ll not cover them here.</p><p>However, I hope this article provides a solid basis to understand an overall picture on this protocol, and if you still have any doubts, hit me up at <a href="mailto:akakush19@protonmail.com">akakush19@protonmail.com</a>, I&#x2019;ll be happy to share thoughts with you!</p><hr><p>If you want to check my previous articles to understand some other <strong>Internet concepts</strong> feel free to do so!</p><ul><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-1-ethernet-switching-vlans-9fc667595d1e?ref=blog.lares21.xyz" rel="noopener">Chapter 1: Ethernet, Switching &amp; VLANs</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-2-ip-basics-a8a11c24e644?ref=blog.lares21.xyz" rel="noopener">Chapter 2: IP Basics</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-3-network-applications-5c9be0c63eef?ref=blog.lares21.xyz" rel="noopener">Chapter 3: Network Apps</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-4-dns-domain-name-system-630600a75d2b?ref=blog.lares21.xyz" rel="noopener">Chapter 4: DNS</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-5-dhcp-dynamic-host-configuration-protocol-a35e09a0d263?ref=blog.lares21.xyz" rel="noopener">Chapter 5: DHCP</a></li></ul><hr><p><strong>Leave a clap if you enjoyed this post, you&#x2019;ll support my work and help me keep myself motivated to write more! Knowledge is power!</strong></p>]]></content:encoded></item><item><title><![CDATA[Internet Educational Series #5: DHCP (Dynamic Host Configuration Protocol)]]></title><description><![CDATA[How can the Internet have millions of devices connected between them? Does each device have always the same IP?]]></description><link>https://blog.lares21.xyz/internet-educational-series-5-dhcp-dynamic-host-configuration-protocol/</link><guid isPermaLink="false">665ee4afd242c72c9151c1a1</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Thu, 29 Apr 2021 17:13:08 GMT</pubDate><media:content url="https://blog.lares21.xyz/content/images/2024/06/1-1kiknnlkxpxptcyvrf6kcq.png" medium="image"/><content:encoded><![CDATA[<img src="https://blog.lares21.xyz/content/images/2024/06/1-1kiknnlkxpxptcyvrf6kcq.png" alt="Internet Educational Series #5: DHCP (Dynamic Host Configuration Protocol)"><p>In the last article, we talked about DNS, how does the internet know where each host is allocated, and translates each host name to its IP address.</p><p>However, <strong>having a static IP address for each host is not at all scalable</strong>.</p><p>That&#x2019;s why nowadays we use <strong>DHCP</strong>. This protocol automates the process of configuring the <strong>network parameters</strong> of <strong>network devices</strong>.</p><blockquote>This means that each time a device opens, and connects itself to the Internet, it uses the DHCP protocol to configure its parameters, and to be able to be properly connected to the rest of the world (public) devices.</blockquote><p>These parameters include the <strong>assigned IP</strong>, the <strong>network mask</strong>, the <strong>IP address of one or more DNS servers</strong> and the <strong>IP address of the default router</strong>.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-k7pzywuu-8l08yhhylkesw.png" class="kg-image" alt="Internet Educational Series #5: DHCP (Dynamic Host Configuration Protocol)" loading="lazy" width="568" height="270"><figcaption><span style="white-space: pre-wrap;">DHCP example</span></figcaption></figure><p>DHCP consists of two components:</p><ul><li>A <strong>mechanism</strong> for allocation of network addresses (IPs) to devices.</li><li>A <strong>protocol</strong> for delivering network addresses and other host-specific configuration parameters from the DHCP server to the device being configured.</li></ul><h4 id="dhcp-allocation-mechanisms">DHCP Allocation Mechanisms</h4><p>DHCP supports 3 mechanisms for IP address allocation:</p><ol><li><strong>Manual Allocation</strong>: A particular IP address is pre-allocated to a network device by an administrator. The network device is typically identified by its MAC address (but other methods like secret keys can be used).</li><li><strong>Automatic Allocation</strong>: DHCP automatically assigns an IP address <strong>permanently</strong> to a device, <strong>selecting it from a pool of available addresses</strong>.</li><li><strong>Dynamic Allocation</strong>: DHCP automatically assigns an IP address to a client <strong>for a limited period of time</strong> (or until the client explicitly relinquishes the address).</li></ol><p>The 3d mechanism (<strong>dynamic</strong>) is by far the most widely used, as it is the most scalable of them all.</p><p>It allows automatic reuse of addresses, as the huge majority of internet hosts will just connect temporarily, or they won&#x2019;t need a static IP address.</p><p>The period of time over which a network address is allocated to a client is called the <strong>lease</strong>.</p><p>The dynamic allocation mechanism works as follows:</p><ul><li>A client requests the use of an address for X period of time (lease time).</li><li>The allocation mechanism guarantees that the assigned address will not be reallocated to any other device during the requested time.</li><li>Later, the client may <strong>extend its lease</strong> with subsequent requests.</li><li>Each time the client requests an address, it <strong>usually includes the previous assigned address</strong> and the allocation mechanism attempts to assign the same network address.</li><li>If the client does not need the address anymore, it can issue a message to release the address back to the server.</li><li>Finally, the client may ask for a <strong>permanent assignment</strong> by asking for an <strong>infinite lease</strong>.</li></ul><p>Obviously the DHCP server needs a database or <strong>persistent storage</strong> of network parameters for network clients, as it has to know the state of the configured hosts to operate properly.</p><p>DHCP servers usually store a <em>key-value entry</em> for each client, which is a unique identifier, and contains the configuration parameters for the client.</p><h4 id="dhcp-protocol">DHCP Protocol</h4><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-gwoswsgkih_es2uisdowtg.png" class="kg-image" alt="Internet Educational Series #5: DHCP (Dynamic Host Configuration Protocol)" loading="lazy" width="774" height="437" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-gwoswsgkih_es2uisdowtg.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-gwoswsgkih_es2uisdowtg.png 774w" sizes="(min-width: 720px) 720px"></figure><p>DHCP messages use <strong>ports 67 and 68</strong>.</p><p>The messages that are sent from client &#x2192; server use the <strong>server port 67</strong>.</p><p>The messages that are sent from server &#x2192; client use the <strong>client port 68</strong>.</p><p><strong>Process to allocate network addresses:</strong></p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-tfirwhxjm_ut8kt018namw.png" class="kg-image" alt="Internet Educational Series #5: DHCP (Dynamic Host Configuration Protocol)" loading="lazy" width="453" height="421"><figcaption><span style="white-space: pre-wrap;">DHCP allocation process</span></figcaption></figure><ol><li>The client <em>broadcasts</em> a <strong>DHCPDISCOVER</strong> message from the port 68, to the port 67 of the server.</li><li>Then, each DHCP server available in the network may respond from its port 67 to the port 68 of the client with a <strong>DHCPOFFER</strong> message, which includes an available network address and other configuration parameters.</li><li>Then the client selects a server, and broadcasts a <strong>DHCPREQUEST</strong> message to request a specific IP address. It does also do this from its own port 68, to the port 67 (still broadcasting).</li><li>The server responds with a <strong>DHCPACK</strong> message with the requested parameters, from its port 67 to the port 68 of the client, who will now have an assigned IP with a lease time.</li></ol><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-bmki1cki9zq8vr0h0re_rg.png" class="kg-image" alt="Internet Educational Series #5: DHCP (Dynamic Host Configuration Protocol)" loading="lazy" width="425" height="632"><figcaption><span style="white-space: pre-wrap;">DHCP message&#xA0;exchange</span></figcaption></figure><p>There are other DHCP messages that servers and clients can use, such as <strong>DHCPNAK</strong> (server to client indicating network address is incorrect), <strong>DHCPDECLINE</strong> (client to server indicating network adress is already in use), <strong>DHCPRELEASE</strong> (client to server relinquishing network address and cancelling remaining lease) and <strong>DHCPINFORM</strong> (client to server asking only for local configuration parameters).</p><h4 id="using-dhcp-in-linux">Using DHCP in Linux</h4><h4 id="dchp-server-dhcpd">DCHP server (<strong>dhcpd</strong>)</h4><p>You can start, stop, get the status or restart the DHCP server with:</p><pre><code>server# /etc/init.d/dhcp3-server start/stop/status/restart</code></pre><h4 id="dhcp-client-dhclient">DHCP Client (dhclient)</h4><p>You can start/stop the DHCP client for Linux with the command:</p><pre><code>client# dhclient3</code></pre><p>The previous command sends a <strong>DHCP discover</strong> through all the interfaces of the host.</p><p>However, it is typical to start the client only in some interfaces of your network, for example:</p><pre><code>client# dhclient3 eth1</code></pre><p>And now we would only be looking for dhcp servers through eth1 interface.</p><p>If you want to release a certain interface (eth1 in this case) lease:</p><pre><code>client# dhclient3 -r eth1</code></pre><p>When the DHCP client is started, it reads a configuration file to know what to do, which is typically located in <code>/etc/dhcp3/dhclient.conf</code>.</p><h4 id="dhcp-commands-summary">DHCP Commands Summary</h4><p><strong>Server</strong></p><ul><li>Script to start/stop the DHCP server: <code>/etc/init.d/dhcp3-server</code></li><li>Configuration file for ISC DHCP server: <code>/etc/dhcp3/dhcpd.conf</code></li><li>Current leases of the DHCP server: <code>/var/lib/dhcp3/dhcpd.leases</code></li></ul><p><strong>Client</strong></p><ul><li>Start, stop, restore the DHCP client: <code>dhclient3</code></li><li>Configuration file for the DHCP client: <code>/etc/dhcp3/dhclient.conf</code></li><li>Current leases of the DHCP client: <code>/var/lib/dhcp3/dhclient.leases</code></li></ul><p>Other important commands:</p><pre><code>/var/log/syslog</code></pre><p>This is the file where is stored the DHCP event log.</p><hr><p>This is reaching to an end, DHCP itself is not the most complex protocol used in the Internet, but it is by far one of the most used of them all.</p><p>I hope this article helped in clarifying some ideas, and if you still have any doubts, hit me up at <a href="mailto:akakush19@protonmail.com">akakush19@protonmail.com</a>, I&#x2019;ll be happy to share thoughts with you!</p><hr><p>If you want to check my previous articles to understand some other Internet concepts feel free to do so!</p><ul><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-1-ethernet-switching-vlans-9fc667595d1e?ref=blog.lares21.xyz" rel="noopener">Chapter 1: Ethernet, Switching &amp; VLANs</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-2-ip-basics-a8a11c24e644?ref=blog.lares21.xyz" rel="noopener">Chapter 2: IP Basics</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-3-network-applications-5c9be0c63eef?ref=blog.lares21.xyz" rel="noopener">Chapter 3: Network Apps</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-4-dns-domain-name-system-630600a75d2b?ref=blog.lares21.xyz" rel="noopener">Chapter 4: DNS</a></li></ul><hr><p><strong>Leave a clap if you enjoyed this post, you&#x2019;ll support my work and help me keep myself motivated to write more! Knowledge is power!</strong></p>]]></content:encoded></item><item><title><![CDATA[Internet Educational Series #4: DNS (Domain Name System)]]></title><description><![CDATA[But… you told us computers use numbers to identify themselves, how can I connect to medium.com then?]]></description><link>https://blog.lares21.xyz/internet-educational-series-4-dns-domain-name-system/</link><guid isPermaLink="false">665ee4afd242c72c9151c1a3</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Tue, 27 Apr 2021 03:41:04 GMT</pubDate><media:content url="https://blog.lares21.xyz/content/images/2024/06/1-llu5wxg91qu1teusctwssa.png" medium="image"/><content:encoded><![CDATA[<img src="https://blog.lares21.xyz/content/images/2024/06/1-llu5wxg91qu1teusctwssa.png" alt="Internet Educational Series #4: DNS (Domain Name System)"><p>When we want to send data through the internet, we must know the IP address of the destination device to send an IP datagram.</p><blockquote>However, IP addresses (IPv4) are something like 192.168.0.1, or 172.16.255.255, and for humans those numbers are hard to remember. We tend to remember easier names than numbers, and that&#x2019;s why the DNS was invented.</blockquote><p>DNS stands for Domain Name System, and it links names with IP addresses in the Internet.</p><h4 id="how-does-it-work">How does it work?</h4><p>Now, the question is how to implement the DNS. How can our computer know which IP corresponds to each name?</p><p>The first time the DNS was implemented, the Internet was so small that simply having a local file of translations in each computer was enough.</p><p>In Unix-like systems, such file is the <code>/etc/hosts</code>, and it contains lines of text with name translations in the form &#x201C;address&#x201D;, &#x201C;long name&#x201D; and &#x201C;short name&#x201D;.</p><p>If we take a look at our file:</p><pre><code>$ cat /etc/hosts                                        
## 
# Host Database 
# 
# localhost is used to configure the loopback interface 
# when the system is booting.  Do not change this entry. 
## 
127.0.0.1	localhost 
255.255.255.255	broadcasthost 
::1             localhost</code></pre><p>We can see our localhost and broadcast addresses.</p><p>However, the Internet continued evolving, and it became so huge so quickly that another system had to be thought.</p><p>Take a look at the figure below, note that it is displayed logarithmically</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-pwjns1oqzrx2w-bhzglnqw.png" class="kg-image" alt="Internet Educational Series #4: DNS (Domain Name System)" loading="lazy" width="606" height="283" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-pwjns1oqzrx2w-bhzglnqw.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-pwjns1oqzrx2w-bhzglnqw.png 606w"><figcaption><span style="white-space: pre-wrap;">Internet Hosts 1981&#x2013;2012</span></figcaption></figure><p>The first proposed solution was to store all the translations in a server and only use the &#x201C;hosts&#x201D; file for specific local translations, that&#x2019;s why we can only see my localhost and broadcast address.</p><p>The file and the centralized server were maintained by an organization called InterNIC.</p><p>Obviously they realized that this wasn&#x2019;t either a good idea, and that a more decentralized approach should be clearly taken, as more and more users joined the network.</p><h4 id="decentralized-solution">Decentralized Solution</h4><p>To provide efficient name translations and delegation is best to use a <strong>distributed database</strong> (multiple servers) with a <strong>variable depth hierarchical name space</strong>.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-h8hzizdszjm_rg2jbq6m0w-jpeg.jpg" class="kg-image" alt="Internet Educational Series #4: DNS (Domain Name System)" loading="lazy" width="561" height="373"><figcaption><span style="white-space: pre-wrap;">Variable depth hierarchy</span></figcaption></figure><p>This literally means that the names can have different lengths and that they are ordered in a hierarchy.</p><p>This hierarchy allows name delegation and name uniqueness. With this solution we can have several devices with the same short name or <strong>unqualified name</strong> (such as www) but each device can have a different long name or <strong>Fully Qualified Domain Name (FQDN)</strong>, such as sales.microsoft.com.</p><h4 id="domains">Domains</h4><p>The name space of the DNS tree is divided into <strong>domains</strong>. A domain includes all the names ending with that domain suffix. For example, the domain .com includes all the names ending with .com, like medium.com, github.com, and a long long list of names.</p><p>Domains are classified according to their level or depth inside the DNS hierarchy.</p><p>First level domains are managed by governmental organizations, countries or special agencies related with Internet.</p><p>Second level domains are managed by private entities. An example of second level domain is medium.com.</p><p>Additionally, there is a top level or root domain. This domain is the <strong>dot domain</strong>: &#x201C;<strong>.</strong>&#x201D;, and it is managed by InterNIC.</p><p>Take a look at the following picture</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-dhiryk1lbdeoqforwb3mkg.png" class="kg-image" alt="Internet Educational Series #4: DNS (Domain Name System)" loading="lazy" width="667" height="344" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-dhiryk1lbdeoqforwb3mkg.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-dhiryk1lbdeoqforwb3mkg.png 667w"><figcaption><span style="white-space: pre-wrap;">7 domains</span></figcaption></figure><p>If we count the number of domains in this picture we can see there are 7: &#x201C;dot&#x201D;, .com, example.com, .net, example.net, left.example.net, right.example.net.</p><p>Each domain has one or more network devices connected to it. We will refer to this network devices as the &#x201C;tree leaves&#x201D;.</p><p>We can see how the domain .com has 2 leaves: bob.com and nsc.com.</p><h4 id="zones">Zones</h4><p>When we want to delegate petitions of name translations, the DNS tree is administratively divided into <strong>zones</strong>. A zone is an administration point, that contains a <strong>configuration file</strong> containing a set of translations that is managed by a master or primary name server.</p><p>Each zone can have multiple servers, and a server can serve multiple zones, but to make it easier to understand, we are going to assume that each zone is implemented with just one server and that each server just serves that zone.</p><p>Take a look at the possible zones that we could have with the previous tree:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-jzeuiuccov_kmlroqgdvfq.png" class="kg-image" alt="Internet Educational Series #4: DNS (Domain Name System)" loading="lazy" width="632" height="423" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-jzeuiuccov_kmlroqgdvfq.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-jzeuiuccov_kmlroqgdvfq.png 632w"><figcaption><span style="white-space: pre-wrap;">6 zones</span></figcaption></figure><p>As you can see we&#x2019;ve separated the 7 domains into 6 zones. The server <strong>root</strong> is in charge of the zone dot (&#x201C;.&#x201D;), and it has translations of all the names except the ones that it has delegated. In our case, the root server delegates .com and .net, so in case there are no more devices it will just know the translation of <strong>nsc</strong> and <strong>nsn</strong> to delegate all the names ending with .com and .net.</p><p>The domain .com is managed by <strong>nsc</strong> and the .net by <strong>nsn</strong>.</p><p>The server <strong>nsc</strong> manages all the names ending with .com except those ending with example.com.</p><p>The domain example.com has been delegated to a server called <strong>nsce</strong>, thus the translation of bob.com is stored in <strong>nsc</strong> but the translation of alice.example.com is stored in <strong>nsce</strong>.</p><p>In the <strong>nsn</strong> branch we could see similar zones except the <strong>left</strong> one, which we chose to make a single zone for either example.net and left.example.net. Why did we choose to do that? Because there is only one device that hangs from the left branch, and it can be already managed by <strong>nsne</strong>, there is no need to add another server there to store the information of bob.left.example.com. Of course we could have divided that into two different zones, one for example.net and another one for left.example.net, but they both would have been served by <strong>nsne</strong>.</p><p>The network addressing is done orthogonally respect to the hierarchy of the domain.</p><p>In our example, we have a single IP network 10.0.0.0/24, which is addressed as follows:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-hzw2y5cjczonzz_dwrupjw.png" class="kg-image" alt="Internet Educational Series #4: DNS (Domain Name System)" loading="lazy" width="657" height="415" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-hzw2y5cjczonzz_dwrupjw.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-hzw2y5cjczonzz_dwrupjw.png 657w"><figcaption><span style="white-space: pre-wrap;">IP addressing</span></figcaption></figure><p>Obviously in the &#x201C;real&#x201D; Internet we have many different IP networks connected with routers.</p><hr><h4 id="implementation-with-rrs">Implementation with RRs</h4><p>The DNS database in each server is implemented with <strong>Resource Records (RRs)</strong>. RRs are text lines that define the configuration of the DNS tree nodes.</p><p>The general format of the RR is the following:</p><pre><code>Owner	[TTL]	Class	Type	RDATA</code></pre><ul><li>Owner: RR owner, a name.</li><li>TTL: the time that a RR may be cached by any resolver (optional).</li><li>Class: Resource records belong to a class. Typically the class is IN (Internet)</li><li>Type: The RR type.</li><li>RDATA: Record information.</li></ul><h4 id="resource-record-%E2%80%9Ca%E2%80%9D">Resource Record &#x201C;A&#x201D;</h4><p>The most common RR. It contains the IPv4 address associated with a name.</p><p>For example:</p><pre><code>alice.example.com	30	IN	A	10.0.0.22</code></pre><p>The A RR for the name alice.example.com with a TTL for caching of 30 seconds.</p><h4 id="resource-record-%E2%80%9Csoa%E2%80%9D">Resource Record &#x201C;SOA&#x201D;</h4><p>The <strong>Source of Authority</strong> record is always the first record of a zone and it contains administrative information. Each zone must have a different SOA.</p><p>Each SOA contains the following RDATA:</p><ul><li>Origin: name of the zone&#x2019;s primary server.</li><li>Person: e-mail of the zone&#x2019;s administrator.</li><li>Serial: Integer (YYYY/MM/DD/XX) that must be increased after any modification of the zone data.</li><li>Refresh: time between zone transfer requests by secondary servers (usually days).</li><li>Retry: time between requests whenever a zone transfer fails (usually hours).</li><li>Expire: time a secondary server keeps the data if the connection to the master fails (usually months).</li><li>Negative cache: the time that an inexistent translation may be cached.</li></ul><p>If we execute the following command <code>dig @IP</code> to know the RR of our router:</p><pre><code>$ dig 192.168.1.1 
 
; &lt;&lt;&gt;&gt; DiG 9.10.6 &lt;&lt;&gt;&gt; 192.168.1.1 
;; global options: +cmd 
;; Got answer: 
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NXDOMAIN, id: 58217 
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1 
 
;; OPT PSEUDOSECTION: 
; EDNS: version: 0, flags:; udp: 512 
;; QUESTION SECTION: 
;192.168.1.1.			IN	A 
 
;; AUTHORITY SECTION: 
.			3483	IN	SOA	a.root-servers.net. nstld.verisign-grs.com. 2021041600 1800 900 604800 86400 
 
;; Query time: 147 msec 
;; SERVER: 192.168.1.1#53(192.168.1.1) 
;; WHEN: Fri Apr 16 16:52:20 CEST 2021 
;; MSG SIZE  rcvd: 115</code></pre><p>We can see either a type A RR and a SOA, with the following information:</p><p>serial: 2021041600</p><p>refresh: 1800</p><p>retry: 900</p><p>expire: 604800</p><p>negative cache: 86400</p><p>It says that the primary server of the zone is <strong>a.root-servers.net</strong> and the email of the admin of the zone is <strong>nstld.verisign@grs.com</strong>.</p><h4 id="resource-record-%E2%80%9Cns%E2%80%9D">Resource Record &#x201C;NS&#x201D;</h4><p>This RR stands for Name Server. NS RRs are used for delegation, they link a domain name with the name of an authoritative name server for that domain.</p><p>The configuration file of the zone will have as many NS records as domains being delegated in that specific zone.</p><p>It tells us which are the servers that serve the other zones that are delegated from the actual zone.</p><h4 id="glue-records">Glue Records</h4><p>When we are in a certain zone, and we want to delegate to another one, we must indicate which is the name server of that zone with the NS record, as we&#x2019;ve just seen. The problem is that the NS record does not contain any IP address, and if we are in root, and we want to reach nsc.com, and supposedly the one who knows the IP address of all devices from the zone .com is nsc.com, we will get in a loop.</p><p>Thats why we include another &#x201C;A&#x201D; record here, called <strong>glue record</strong>, to indicate the IP address of the server who serves that zone.</p><p>Notice that glue records <strong>are only necessary if the child zone has a name within the delegated domain</strong>, such as .com and nsc.com, then we would need to add a glue record to the <em>.com zone configuration file</em>.</p><p>Otherwise, we would only need a NS record (no extra &#x201C;A&#x201D; record) if the delegated zone is not related to the parent zone, because it will just send it to root, and it will later delegate it to the correct zone.</p><h4 id="resource-record-%E2%80%9Ccname%E2%80%9D">Resource Record &#x201C;CNAME&#x201D;</h4><p>When there are several names that translate to the same IP address, we use the CNAME Resource Record. It creates an alias to a canonical name (CNAME).</p><p>This RR associates a name with another name of the DNS tree.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-qdx88gb3hakumx5i6_mrpw.png" class="kg-image" alt="Internet Educational Series #4: DNS (Domain Name System)" loading="lazy" width="548" height="388"><figcaption><span style="white-space: pre-wrap;">CNAME RR</span></figcaption></figure><h4 id="resource-record-%E2%80%9Cmx%E2%80%9D">Resource Record &#x201C;MX&#x201D;</h4><p>The MX (Mail eXchanger) records designate the mail servers for a given domain. We can add more than one MX record to each mail server for a certain email destination, just keep in mind that they will be contacted by priority order (low number first).</p><hr><h4 id="configuration-of-dns-servers-with-bind">Configuration of DNS servers with BIND</h4><p>In Linux, we use an implementation of the DNS called BIND (Berkeley Internet Name Domain (BIND), which is maintained by <a href="http://www.isc.org./?ref=blog.lares21.xyz" rel="noopener">http://www.isc.org.</a></p><p>We will use bind to implement the configuration of our example DNS tree, which emulates a &#x201C;mini&#x201D; Internet. In Linux, you can start, stop or restart bind using the command <code>$ /etc/init.d/bind9 stop/start/restart</code>.</p><p><strong>Each time you change the configuration of bind, you have to restart it so that changes take effect.</strong></p><p>It is also worth knowing that BIND writes its logs by default in a Debian distribution in the file <code>/var/log/daemon.log</code>.</p><h4 id="root-servers">ROOT Servers</h4><p>To send properly messages between different parts of the DNS tree, we must be able to go &#x201C;up&#x201D; the tree, and move to other zones that are not directly connected to the current zone.</p><p>That&#x2019;s why any DNS server must have information about how to reach the root servers of the DNS tree. This informations is called <strong>root hints</strong> and, in our configuration, they are specified in the file <strong>/etc/bind/db.root</strong>.</p><p>We have configured it this way:</p><pre><code>.				IN	NS	ROOT-SERVER 
ROOT-SERVER		IN	A	10.0.0.1</code></pre><h4 id="configuration-of-root">Configuration of ROOT</h4><p>The root server contains the configuration of the dot zone, which can generally be found at <code>/etc/bind</code>.</p><p>When the bind service wants to consult something, the first file it looks at is /etc/bind/named.conf. In root, the contents of this file are the following:</p><pre><code>$ cat /etc/bind/named.conf 
 
options { 
directory &quot;/var/cache/bind&quot;; };</code></pre><pre><code>zone &quot;.&quot; { 
type master ; 
file &quot;/etc/bind/db.root&quot;; 
};</code></pre><pre><code>zone &quot;localhost&quot; { 
type master ; 
file &quot;/etc/bind/db.local&quot;; 
};</code></pre><pre><code>zone &quot;0.0.10.in&#x2212;addr.arpa&quot; { type master ; 
file &quot;/etc/bind/db.10.0.0&quot;; };</code></pre><p>We can see that for the &#x201C;.&#x201D; zone it tells us that the information to reach the &#x201C;.&#x201D; zone is inside <code>/etc/bind/db.root</code></p><p>If we take a look at that file, we can see the following:</p><pre><code>$ cat /etc/bind/db.root 
 
TTL 60000 ; 16h40m default Time to Live of the 
DNS records . IN SOA ROOT&#x2212;SERVER. admin&#x2212;mail .ROOT&#x2212;SERVER.( 
2006031201 ; serial 
28800 ; refresh 
14400 ; retry 
3600000 ; expire 
0 ; negative cache ttl  
) 
 
.			IN	NS	ROOT-SERVER 
ROOT-SERVER.	        IN	A	10.0.0.1 
 
com. 			IN	NS	nsc.com 
nsc.com.		IN	A	10.0.0.11 
 
net.			IN	NS	nsn.net 
nsn.net.		IN	A	10.0.0.111</code></pre><p>Notice that all names end with a dot &#x201C;.&#x201D;, that means that all those names are <strong>FQDN</strong>.</p><p>It also tells us which are the name servers that it delegates, and how to reach their zone.</p><p>Regarding our example, we can see how this file shows us the different NS and glue records for the three possible delegated zones (&#x201C;.&#x201D;, .com and .net).</p><h4 id="configuration-of-nsccom">Configuration of nsc.com</h4><p>To take a look at the configuration of the server nsc.com, remember that we must look at the file <code>/etc/bind/named.conf</code> of that server.</p><p>We have the following in this file:</p><pre><code>$ cat /etc/bind/named.conf 
 
options { 
directory &quot;/ var / cache / bind &quot;; 
min&#x2212;roots 1; 
};</code></pre><pre><code>zone &quot;.&quot; { 
type hint ; 
file &quot;/etc/bind/db.root&quot;; }; 
.... 
// add entries for other zones below here</code></pre><pre><code>zone &quot;com&quot; { 
type master ; 
file &quot;/etc/bind/db.com&quot;; 
};</code></pre><p>See how it indicates that we&#x2019;ve got a <strong>hint</strong> to reach root at &#x201C;<code>/etc/bind/db.root</code>&#x201D;? Exactly how it is supposed to be!</p><p>Also notice how it says: &#x201C;// add entries for other zones below here&#x201D;, where we can add other child zones that can be connect to this server.</p><h4 id="configuration-a-zone">Configuration a zone</h4><p>Let&#x2019;s imagine now that we want to observe the configuration of one of the zones connected to the server <strong>nsc.com</strong>. The <strong>.com</strong> zone in this case.</p><p>To do so, we need to look inside the file <strong>/etc/bind/db.&#x201D;ZONE&#x201D;</strong>, in our case it would be <code>/etc/bind/db.com</code>.</p><p>This is what it says:</p><pre><code>$ cat /etc/bind/db.com 
 
TTL 60000 ; 16h40m default Time to Live of the DNS records 
com. IN SOA nsc .com. admin&#x2212;mail . nsc .com. ( 
2006031201 ; serial 
28800 ; refresh 
14400 ; retry 
3600000 ; expire 
0 ; negative cache ttl  
) 
com. 			        IN	NS			nsc.com ; ns of .com</code></pre><pre><code>nsc.com.			IN	A		10.0.0.11 ; leaf of .com</code></pre><pre><code>bob.com.		30	IN	A		10.0.0.12 ; leaf of .com</code></pre><pre><code>example.com.		      IN	NS		nsce.example.com ; delegation of example.com</code></pre><pre><code>nsce.example.com	      IN	A		10.0.0.21 ; glue record of example.com</code></pre><p>The file contains the TTL, and then the various RRs:</p><ul><li><strong>SOA</strong> record with all it&#x2019;s source of authority information</li><li><strong>NS</strong> record <strong>of .com</strong> zone, indicating who is the name server of .com</li><li><strong>Glue Record of nsc.com</strong> telling where nsc.com is</li><li><strong>A</strong> record for <strong>bob.com</strong></li><li><strong>NS</strong> record of the <strong>example.com</strong> zone, indicating that nsce.example.com is the name server of example.com</li><li><strong>Glue record of nsce.example.com</strong> telling where nsce.example.com is found.</li></ul><p>If we now take a look at the same file, but from the <strong>example.com</strong> zone, in the file <code>/etc/bind/db.com.example</code>:</p><pre><code>$cat /etc/bind/db.com.example  
 
$ORIGIN example.com. 
$TTL 60000 
@ IN SOA nsce admin&#x2212;mail . nsce (  
2006031201 ; serial 
28 ; refresh 
14 ; retry 
3600000 ; expire 
20 ; 20 secs of negative cache ttl  
)</code></pre><pre><code>@				IN	NS	nsce;	unqualified name</code></pre><pre><code>nsce				IN	A	10.0.0.21</code></pre><pre><code>david				IN	CNAME	david.example.net.</code></pre><pre><code>@				IN	MX	10	mailserver1 
@				IN	MX	20 mailserver2.example.com.</code></pre><pre><code>alice				IN	A	10.0.0.22</code></pre><pre><code>mailserver1			IN	A	10.0.0.25</code></pre><pre><code>mailserver2			IN	A	10.0.0.26</code></pre><pre><code>;alice.example.com	        IN	A	10.0.0.22</code></pre><p>Let&#x2019;s take a closer look at this configuration file. The first thing that is different from the previous example is the <code>$ORIGIN</code> line. This is just to indicate that everywhere that a <code>@</code> appears, it should be substituted by the ORIGIN value, in this case example.com.</p><p>Next on we find some RRs that we haven&#x2019;t seen before, such as <strong>CNAME</strong>, which creates an alias from another point of the DNS tree, and links this two names to the same IP address, and also <strong>MX</strong>, which indicates who are the mail servers for example.com.</p><p>Finally take a look at the last line&#x2026; It is commented, but if we uncomment (delete the semicolon) from that line, we are creating another A resource, and it renames the zone that is found at the IP address 10.0.0.22 to alice.example.com instead of alice.</p><hr><h4 id="dns-queries-responses">DNS Queries &amp; Responses</h4><p>When a Linux device tries to find a translation for a name, the first thing it does is looking at the local translations file located at <code>/etc/hosts</code>.</p><p>If there is not any translation in this file, the client has to use the DNS service.</p><p>To do so, we need to know at least one name server. In Linux, the file <code>/etc/resolv.conf</code> is where the addresses of the name servers are stored.</p><p>The contents of the file are something like this:</p><pre><code>nameserver 147.83.2.3 
nameserver 147.83.2.10</code></pre><p>They are pointing to different name servers, to which the client will ask for DNS translations. In the <code>resolv.conf</code> you can set up to 3 name servers that will be contacted in order.</p><p>Obviously, the name servers to which you ask, must be configured to accept client queries.</p><p><em>Additional note: The name server is typically provided by your ISP or your organization.</em></p><h4 id="queries">Queries</h4><p>In Linux we have 2 commands to perform DNS queries: <strong>host</strong> and <strong>dig</strong>.</p><p>Each query specifies the domain name, class and type of the queried RR. For example we can ask for <code>klasea.es IN A</code>.</p><p>There are 2 types of queries: <strong>iterative</strong> and <strong>recursive</strong>.</p><ul><li>In an iterative query, the queried name server returns the address of the next name server that you must consult to obtain the response.</li><li>In a recursive query, the name server tries to find the final response, making several queries to different name servers if necessary. To use the recursive queries, we must activate the flag &#x201C;<strong>recursion flag</strong>&#x201D; on the request.</li></ul><p><em>Be careful! <strong>Not all servers support recursion</strong>.</em></p><h4 id="responses">Responses</h4><p>Name servers usually use a cache memory to improve the DNS performance. The time that a response is cached is configured by the original Source Administrator.</p><p>When we use cache, we have to possible types of responses:</p><ul><li><strong>Authoritative</strong>: Authoritative name servers provide authoritative responses (not cached) because it is the original source.</li><li><strong>Non-authoritative</strong>: Non-authoritative name servers provide cached responses (with a valid TTL).</li></ul><hr><h4 id="dns-protocol">DNS Protocol</h4><p>DNS servers use by default <strong>UDP port 53 </strong>, and DNS messages can have five parts:</p><ul><li>Header: here we can find if the message is a query or a reply, if recursion is desired or not, if the response is authoritative or not, etc.</li><li>Questions: They are tuples with Name, Type and Class.</li><li>Answers: Contain the registers that match the Name, Type and Class asked in the questions part.</li><li>Authority: It typically contains NS records pointing to name servers closer to the target name in the hierarchy.</li><li>Additional information: It contains additional records that the name server believes may be useful to the client. The most common use for this field is to supply A address records for the name servers listed in the Authority section.</li></ul><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-2vdem97qhwnyvlbpykhwjw.png" class="kg-image" alt="Internet Educational Series #4: DNS (Domain Name System)" loading="lazy" width="614" height="400" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-2vdem97qhwnyvlbpykhwjw.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-2vdem97qhwnyvlbpykhwjw.png 614w"><figcaption><span style="white-space: pre-wrap;">DNS protocol&#xA0;camps</span></figcaption></figure><hr><h4 id="practical-name-resolutions">Practical Name Resolutions</h4><h4 id="querying-an-authoritative-server">Querying an Authoritative Server</h4><p>Normally clients will be asking queries to authoritative servers.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-zlxdejpo5bz538z5sj-gww.png" class="kg-image" alt="Internet Educational Series #4: DNS (Domain Name System)" loading="lazy" width="707" height="400" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-zlxdejpo5bz538z5sj-gww.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-zlxdejpo5bz538z5sj-gww.png 707w"><figcaption><span style="white-space: pre-wrap;">Query to authoritative server</span></figcaption></figure><p>In our example let&#x2019;s consider that Alice has <strong>nsce</strong> as her resolver (can be found in /etc/resolv.conf) and that she wants to know its own IP address.</p><p>To do so Alice will send a recursive query for the A register of alice.example.com to <strong>nsce</strong>.</p><p>Then <strong>nsce</strong> will send directly the response to Alice, as it already knows the answer.</p><p>The command Alice had to use to know her own IP address is: <code>alice$ dig alice.example.com</code>, and the response she obtains is the following:</p><pre><code>; &lt;&lt;&gt;&gt; DiG 9.6-ESV-R4 &lt;&lt;&gt;&gt; alice.example.com 
;; global options: +cmd 
;; Got answer: 
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 49052 
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: 
;alice.example.com. IN A 
;; ANSWER SECTION: 
alice.example.com. 60000 IN A 
;; AUTHORITY SECTION: 
example.com. 60000 IN NS 
;; ADDITIONAL SECTION: 
nsce.example.com. 60000 IN A 
;; Query time: 289 msec 
;; SERVER: 10.0.0.21#53(10.0.0.21) 
;; WHEN: Tue Mar 26 11:29:34 2013 
;; MSG SIZE rcvd: 86</code></pre><p>Let&#x2019;s examine the output, if we take a closer look at the flags it has we can see:</p><ul><li>aa: authoritative response</li><li>rd: recursion desired</li><li>ra: response available</li></ul><p>If we now made a dig to a non-existent target:</p><pre><code>alice$ dig alan.example.com 
; &lt;&lt;&gt;&gt; DiG 9.6-ESV-R4 &lt;&lt;&gt;&gt; alan.example.com 
;; global options: +cmd 
;; Got answer: 
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NXDOMAIN, id: 39136 
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0 ;; QUESTION SECTION: 
;alan.example.com. IN A 
;; AUTHORITY SECTION: 
example.com. 20 IN SOA nsce.example.com. ...</code></pre><p>As you can see the server returns a response with status <strong>NXDOMAIN</strong>, which means that a translation for that name was not found. It also returns a SOA RR, because it contains the negative TTL, which tells us how long we must store this information in the cache. In this case 20 seconds.</p><h4 id="non-authoritative-server">Non authoritative server</h4><p>Until now we&#x2019;ve seen how a server reacts when it is the authoritative server of the client who asked the query.</p><p>But what happens when a client wants to know the information of a host, who is not in the same zone, and so the previous server is not the authoritative server of the new zone?</p><p>Taking our example back, let&#x2019;s imagine that from Alice, we want to find information about <strong>bob.com</strong>. The authoritative server of bob is <strong>nsc</strong>, in this case <strong>nsce</strong> does not know where it is.</p><p>We will test what happens using the dig command from alice, and capturing the traffic with wireshark (we will use the option <em>Statistics -&gt; Flow Graph</em>).</p><pre><code>$alice dig bob.com</code></pre><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-lyptryodofebv7ne3brmaq.png" class="kg-image" alt="Internet Educational Series #4: DNS (Domain Name System)" loading="lazy" width="611" height="343" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-lyptryodofebv7ne3brmaq.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-lyptryodofebv7ne3brmaq.png 611w"><figcaption><span style="white-space: pre-wrap;">wireshark flow&#xA0;graph</span></figcaption></figure><p>Let&#x2019;s analyze what happens here.</p><ul><li>(1) First alice sends the query to its server, <strong>nsce</strong>, asking only for the A record.</li><li>(2) nsce doesn&#x2019;t know where to find bob.com, so it sends the query to it&#x2019;s root server. In this case it asks for either the A record and the NS.</li><li>(3) root responds with the NS and A records from either <strong>nsc</strong> and its own.</li><li>(4) Now nsce knows that the NS of bob.com is nsc, and so forth it sends the query to <strong>nsc.com</strong> asking for the A record from bob.com.</li><li>(5) nsc responds to nsce sending the A record of bob.com</li><li>(6) nsce can tell now to alice where <strong>bob.com </strong>is located.</li></ul><p>Take a look at the following image for a visual representation of the previous steps:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-9uj6lidjljmgxp77thgr6g.png" class="kg-image" alt="Internet Educational Series #4: DNS (Domain Name System)" loading="lazy" width="764" height="428" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-9uj6lidjljmgxp77thgr6g.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-9uj6lidjljmgxp77thgr6g.png 764w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">querying non-authoritative servers</span></figcaption></figure><h4 id="dns-caching">DNS caching</h4><p>Name servers use caching to enhance the performance of the DNS system by storing the RRs obtained during the resolution process. These RRs are kept in cache until their TTL expires. A non authoritative server can use its cached RRs with valid TTL to answer its clients queries without contacting any other name servers.</p><p>Imagine that alice (or another user) asks again <strong>nsce</strong> for the A record of bob.com. As it still has it in its cache, then nsce can directly respond the query with its cached record.</p><p>Take into account that different RRs have different TTL, so maybe the A resource of bob.com is already expired, but the NS record that tells nsce that nsc is the name server of bob.com has not, and so nsce could ask directly to nsc for the A record of bob, without need to go to the root server.</p><h4 id="non-recursive-questions">Non Recursive Questions</h4><p>If we try an iterative query with the dig command from alice to nsce, about bob.com, the input will be the following:</p><pre><code>alice$ dig +noquestion +norecurse bob.com 
; &lt;&lt;&gt;&gt; DiG 9.6-ESV-R4 &lt;&lt;&gt;&gt; +noquestion +norecurse bob.com 
;; global options: +cmd 
;; Got answer: 
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 30988 
;; flags: qr ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0 ;; AUTHORITY SECTION: 
. 0 IN NS ROOT-SERVER.</code></pre><p>As you can see, nsce returns the NS record of the ROOT-SERVER, which is the next server you have to contact to resolve bob.com.</p><p>If alice now asks root for bob.com:</p><pre><code>alice$ dig +noquestion +norecurse @10.0.0.1 bob.com 
; &lt;&lt;&gt;&gt; DiG 9.6-ESV-R4 &lt;&lt;&gt;&gt; +noquestion +norecurse @10.0.0.1 bob.com ; (1 server found) 
;; global options: +cmd 
;; Got answer: 
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 23767 
;; flags: qr ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1 ;; AUTHORITY SECTION: 
com. 60000 IN NS nsc.com. 
;; ADDITIONAL SECTION: 
nsc.com. 60000 IN A 10.0.0.11</code></pre><p>We obtain the NS and A records of <strong>nsc</strong> which is the next server to resolve bob.com.</p><p><em>Great! Up to this point, we&#x2019;ve been explaining all the basics to know how the DNS service resolves queries, and goes from one server to another.</em></p><p><em>The following sections are just extra information that imo are worth to mention, but in case you already found what you were looking for, or you just wanted to understand the DNS protocol, maybe you won&#x2019;t need them, though I recommend you to take a look if you already reached this far!</em></p><hr><h4 id="reverse-lookups">Reverse Lookups</h4><p>As you know, DNS allows to translate a FQDN to an IP address.</p><p>Reverse lookups allow exactly the opposite, translating IP addresses into FQDNs.</p><p>Some applications use the reverse translations as a measure of security, but the majority do not use them, as it is not compulsory.</p><p>The RR used for reverse lookups is called <strong>PTR (pointer)</strong>, and as you may have guessed, it points to the corresponding FQDN.</p><p>If you want to ask for a reverse translation, you can use the <strong>dig</strong> command with the <strong>-x</strong> option: <code>dig -x 147.83.2.135</code>, and it will answer all the FQDNs that correspond to this IP address.</p><hr><h4 id="other-rrs">Other RRs</h4><p>In this article I&#x2019;ve explained the most common and compulsory RRs that the DNS uses. However, there are other ones that you may find</p><p>I&#x2019;ve not went in depth with them because they are not as common as the ones we&#x2019;ve seen, but just keep in mind that you may find additional RRs like:</p><ul><li>TXT: plaintext record containing optional information.</li><li>HINFO: contains informative plain text about the server hardware and OS.</li><li>LOC: contains geographical location of the server.</li><li>AAAA: RR for IPv6 indicating the whole v6 address.</li><li>SRV: allows specifying the location of the servers of a certain service.</li></ul><hr><h4 id="real-root-servers-administration-authorities">Real Root Servers &amp; Administration Authorities</h4><p>In our example we&#x2019;ve been using a &#x201C;mini Internet&#x201D; with only one root server. Obviously the real Internet does not have only one root server.</p><p>Initially there were 13 root-servers located in different countries.</p><p>Nowadays we still have 13 names for root servers which are specified in the form <strong>letter.root-servers.net</strong>, where letter ranges from A to M.</p><p>However this does not mean that we have only 13 physical servers. For reliability and performance, each name server is implemented using redundant computer equipment to be able to provide DNS service even if failure of hardware or software happens in one of the physical servers.</p><p>Finally, after talking about the different servers that we have around the world, it is worth mentioning the Internet Corporation for Assigned Names and Numbers (<strong>ICANN&#xB3;</strong>), who is the responsible of managing different network parameters such as:</p><ul><li>Root and first level name servers</li><li>Assignment of IP addresses</li><li>Delegation of zones to RIRs (Regional Internet Registries)</li></ul><hr><p>Well, I guess this is a good starting point to understand the overall picture on how does DNS work. I hope you understood everything, and found it useful.</p><p>If you want to take a look at a practical exercise step by step on how to use DNS, using the same pictures and situations of this article, you can do it <a href="https://github.com/akaKush/Internet-Basics/tree/main/DNS%26DHCP?ref=blog.lares21.xyz" rel="noopener">here</a>!</p><hr><p>For any doubts, hit me up at <a href="mailto:akakush19@protonmail.com">akakush19@protonmail.com</a>, I&#x2019;ll be happy to share thoughts with you!</p><hr><p>If you want to check my previous articles to understand some other Internet concepts feel free to do so!</p><ul><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-1-ethernet-switching-vlans-9fc667595d1e?ref=blog.lares21.xyz" rel="noopener">Chapter 1: Ethernet, Switching &amp; VLANs</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-2-ip-basics-a8a11c24e644?ref=blog.lares21.xyz" rel="noopener">Chapter 2: IP Basics</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-3-network-applications-5c9be0c63eef?ref=blog.lares21.xyz" rel="noopener">Chapter 3: Network Apps</a></li></ul><hr><p><strong>Leave a clap if you enjoyed this post, you&#x2019;ll support my work and help me keep myself motivated to write more! Knowledge is power!</strong></p>]]></content:encoded></item><item><title><![CDATA[Internet Educational Series #3: Network Applications]]></title><description><![CDATA[SSH, FTP, TELNET, Netcat… Learn how to use Linux devices like a pro with these Networking Tools]]></description><link>https://blog.lares21.xyz/internet-educational-series-3-network-applications/</link><guid isPermaLink="false">665ee4afd242c72c9151c1a5</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Mon, 26 Apr 2021 01:08:26 GMT</pubDate><media:content url="https://blog.lares21.xyz/content/images/2024/06/0-itixutujgrtmmjyw.jpg" medium="image"/><content:encoded><![CDATA[<img src="https://blog.lares21.xyz/content/images/2024/06/0-itixutujgrtmmjyw.jpg" alt="Internet Educational Series #3: Network Applications"><p>Welcome to the third chapter of the Internet Educational Series.</p><p>Here you&#x2019;ll learn all the basics from the Internet, how does it work, why does it work, the protocols used, and many more you&#x2019;ll discover as you read through my articles.</p><p>I hope you like them, and enjoy them as much as I&#x2019;m doing when writing them.</p><p>Let&#x2019;s get into it! Today we are talking about the Basic Network Applications, how are they built from scratch, and some examples on how to use them.</p><p>I&#x2019;ll start from the beginning, trying to make everything understandable for everyone, even if you haven&#x2019;t got a tech background.</p><hr><p>If you want to check my previous articles to understand some other Internet concepts feel free to do so!</p><ul><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-1-ethernet-switching-vlans-9fc667595d1e?ref=blog.lares21.xyz" rel="noopener">Chapter 1: Ethernet, Switching &amp; VLANs</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-2-ip-basics-a8a11c24e644?ref=blog.lares21.xyz" rel="noopener">Chapter 2: IP Basics</a></li></ul><hr><h4 id="transport-layers">Transport Layers</h4><h4 id="transport-layer-motivation">Transport Layer Motivation</h4><p>The network layer is a scalable way of interconnecting data link layer technologies.</p><p>Basic IP provides an interface (NIC-to-NIC) best effort service for delivering datagrams, which means that a correct delivery of datagrams is <strong>not guaranteed</strong>, there might be lost datagrams, incorrect datagrams or disordered datagrams.</p><p>The main goal was to implement communications between processes that run generally in different systems, commonly known as <strong>end-to-end communications</strong>.</p><p>Here the concept of PORT was introduced, for multiplexing and demultiplexing this communications.</p><p>The port concept led to working in <strong>client-server</strong> models for each once a communication was established. This means that there is a server who is running a daemon in the background, executing the process continuously, and users, who act as clients, make requests to this servers to access the information they want.</p><p>To identify the different processes that are running, Unix-like systems use the <strong>Process Identifier (PID)</strong>, however for multiplexing transport communications we want a generic identifier, which is the actual <strong>PORT</strong>.</p><p>So, a port is just a parameter for multiplexing that is dynamically assigned to any running process that requires a transport communication with another process.</p><p>Each transport PDU carries:</p><ul><li>A source Port (SPort) that identifies the process sending the PDU</li><li>A destination Port (DPort) that identifies the process in the destination host</li></ul><p>We are now going to see the main transport protocols used on the Internet.</p><p><strong>User Datagram Protocol (UDP)</strong></p><ul><li>UDP is the simplest transport protocol</li><li>It is a <strong>message-oriented</strong> protocol (datagram protocol)</li><li>Each UDP message is encapsulated over an IP datagram</li><li>UDP only offers multiplexing capabilities (using ports) and a checksum for discarding wrong data</li><li>UDP does NOT provide error, flow or congestion control</li></ul><p><strong>Transport Control Protocol (TCP)</strong></p><ul><li>TCP provides applications with a full-duplex communication, encapsulating its data over IP datagrams</li><li>TCP is <strong>connection-oriented</strong> because there is a handshake of three messages before data can be sent</li><li>Apart from multiplexing capabilities, TCP is a reliable protocol because it adds support to detect errors or lost data and retransmit them (<strong>ARQ end-to-end error control</strong>)</li><li>TCP also supports <strong>end-to-end flow control</strong> and <strong>congestion control</strong></li></ul><p>With this two protocols, we can make sure that our data is properly sent, and check that the channels where we want to send the data are accessible before sending it.</p><h4 id="clientserver-model">Client/Server model</h4><p>As we have seen previously, the client/server model is the most widely used model for communication between processes. Clients make requests to the servers, and servers respond and they can generally support numerous clients.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-hnmucqzs7b4kogzefhfwpw.png" class="kg-image" alt="Internet Educational Series #3: Network Applications" loading="lazy" width="800" height="480" srcset="https://blog.lares21.xyz/content/images/size/w600/2024/06/1-hnmucqzs7b4kogzefhfwpw.png 600w, https://blog.lares21.xyz/content/images/2024/06/1-hnmucqzs7b4kogzefhfwpw.png 800w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">client/server model</span></figcaption></figure><p>In Unix-like systems, servers processes are also called daemons. In general a daemon is a process that runs in the background, and typically they have names that end with the letter &#x201C;d&#x201D; (e.g: telnetd, ftpd, httpd&#x2026;)</p><p>Clients initiate the interprocess communication, so they must know the address of the server.</p><p>Luckily, there are a list of <strong>well-known ports</strong>.</p><p>The client usually knows the IP of the server, and there is a well-known transport protocol and port determined by the application used.</p><p>For example, HTTP servers (for the Web) use TCP/80, DNS servers use UDP/53 for name queries, and the DHCP servers use UDP/67.</p><p>The command <code>netstat</code> (network statistics) shows established or listening sockets and several related statistics.</p><h4 id="socket-api">Socket API</h4><p>TCP/IP communications were developed in the context of Unix systems. One of the main ways of implementing TCP/IP communications is to use the &#x201C;socket&#x201D; API.</p><p>An <strong>application programming interface</strong> (API) is an interface implemented by a software program to enable interaction with other software.</p><p>It may include specifications for routines, data structures, object classes and protocols used to communicate between the consumer and implementer of the API.</p><h4 id="netcat">Netcat</h4><p>The <code>netcat</code> application can be used to create a process that opens a raw TCP or UDP socket as a client or server.</p><p>It is so useful for testing networks, that it even is known as the &#x201C;Swiss Army Knife of networking&#x201D;.</p><ul><li>If we want to use netcat as a client: <code>nc hostname port</code></li><li>If we want to use it as a server: <code>nc -l -p port</code> &#x2014;&gt; we add the -l parameter, which stands for &#x201C;listening&#x201D;.</li></ul><p><em>Note that a netcat server is NOT multiclient.</em></p><p>We can use netcat too to transfer files, create remote terminals, take a look at open files, etc.</p><p>Let&#x2019;s see an example:</p><p>If we want to transfer files, we can create a netcat server in the device we have the files stored, and then run a client connection in the device we want to transfer the data to:</p><pre><code>server# cat file.txt | nc -l -p 12345 -q 0</code></pre><p>The -q 0 option closes the connection once the file has been transferred.</p><p>Now we can create a client connection by tiping:</p><pre><code>client# nc hostname 12345</code></pre><hr><h4 id="basic-network-applications">Basic Network Applications</h4><p>Great, now you know how the transport layers work and how we can establish connections between clients and servers, so let&#x2019;s dive into some of the basic applications that use this technologies.</p><p>In this section we will be talking about:</p><ul><li>TELNET</li><li>FTP</li><li>SSH</li><li>Super Servers</li></ul><h4 id="telnet">TELNET</h4><p>What is TELecommunication NETwork?</p><p>TELNET is a standard Internet protocol for emulating a terminal in a remote host using an IP network.</p><p>The TELNET service uses TCP, and it is a well-known port, that uses <strong>port 23</strong>.</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*-wLrkI3_XHPlZwrdqXbyMA.png" class="kg-image" alt="Internet Educational Series #3: Network Applications" loading="lazy" width="359" height="180"></figure><p>To use the client, you just need to open a terminal and type <code>telnet</code>. After you type the command, you will enter the telnet &#x201C;sub-shell&#x201D;, where you&#x2019;ll be able to type specific commands of telnet.</p><p>The most used and useful subcommand is <strong><code>open hostname</code></strong>, which starts a connection with the specified IP address or hostname with the port 23 (this is the default port, but you can specify a different port after the IP address).</p><p>You can also type the subcommand <code>help</code> to obtain a list of possible subcommands.</p><p>Let&#x2019;s see a practical example on how to open a TELNET connection.</p><pre><code>$ telnet 
telnet &gt; open 192.168.0.1</code></pre><p><em>Note that you need to be in the same network as your server to be able to access it.</em></p><p>You can also use the parameters directly in the command line:</p><pre><code>$ telnet 192.168.0.1 23</code></pre><p>You can exit the remote terminal when you want by typing &#x201C;exit&#x201D;.</p><p><strong>Things to keep in mind with TELNET</strong>:</p><p>Many times telnet clients are used to establish an interactive raw TCP connection. Despite most of the times there will be no problems with this, it mush be taken into account that the telnet client can alter the data sent, as the value 255 is altered. If you want a pure raw TCP connection, you should use the <code>netcat</code> tool.</p><p>Finally, it is worth to mention that because of security issues with telnet, its use for the purpose of having a remote terminal has waned in favor of SSH.</p><h4 id="ftp">FTP</h4><p>What is a FTP (File Transfer Protocol)?</p><p>FTP is a standard Internet protocol for transmitting files between computers (hosts) on the Internet. FTP uses IP and it is based on a client-server model.</p><p>FTP uses separate <strong>control</strong> and <strong>data connections</strong> between the client and server.</p><p>The <strong>default server port for control data is 21</strong>, and the <strong>default server port for data exchanging is 20.</strong></p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*CowfEWE8dkdGQ4O0KBw2Zw.png" class="kg-image" alt="Internet Educational Series #3: Network Applications" loading="lazy" width="369" height="249"></figure><p>The control connection remains open for the whole duration of the session, and it is used for session management (commands, parameter negotiations, passwords, etc.) exchanged between the client and the server.</p><p>Due to this 2-port structure, FTP is considered an out-of-band, as opposed to in-band protocols such as TELNET.</p><p>The server responds to control connection with three digit status codes in ASCII, with an optional text message, for example &#x201C;200 OK&#x201D; means that the last command was successful.</p><h4 id="active-and-passive-modes">Active and Passive modes</h4><p>The mode FTP is run, determines how te <strong>data connection</strong> is established.</p><ul><li>In <strong>active mode</strong> the client sends the server the IP address and port number on which the client will listen, and the server initiates the data connection.</li><li>In <strong>passive mode</strong> the client sends a <strong>PSAV</strong> command to the server, and receives an IP address and port number in return.</li></ul><h4 id="data-transfer-modes">Data transfer modes</h4><p>Data transfer can be done in any of three modes:</p><ul><li><strong>Stream</strong> mode: Data is sent to a continuous stream, relieving FTP from doing any processing. All processing is left to TCP.</li><li><strong>Block</strong> mode: FTP breaks the data into several blocks (block header, byte count and data field) and then passes it to TCP.</li><li><strong>Compressed mode</strong>: Data is compressed using an algorithm</li></ul><h4 id="practical-ftp">Practical FTP</h4><p>Next we discuss the <code>ftp</code> command line client and <code>ftpd</code> server for Linux.</p><p>The <code>ftp</code> client supports active and passive mode, and only stream mode.</p><p>To connect to a <code>ftpd</code> server we can use one of the following options:</p><pre><code>$ ftp name 
$ ftp 192.168.0.1 
$ ftp user@192.168.0.1</code></pre><p>To establish an FTP session you must know the ftp username and password. In case the session is anonymous, typically, you can use the word &#x201C;anonymous&#x201D; as both username and password.</p><p>When you enter your own login name and password, it returns the prompt <code>ftp&gt;</code>, which is a subshell where you can type several subcommands.</p><p>Finally, it is worth to mention that you can also use FTP through a Browser, like:</p><pre><code>ftp://ftp.upc.edu 
ftp://ftpusername@ftp.upc.edu 
ftp://ftpusername:password@ftp.upc.edu</code></pre><h4 id="ssh">SSH</h4><p>Secure SHell is a protocol used to obtain an encrypted end-to-end TCP connection between a client (<code>ssh</code>) and a server (<code>sshd</code>) over a TCP/IP network. The <code>sshd</code> daemon listens to <strong>port 22 TCP</strong> by default. SSH encrypts all traffic, which ultimately eliminates eavesdropping, connection hijacking, and other attacks.</p><h4 id="services-with-ssh">Services with SSH</h4><p><strong>Remote Terminal</strong></p><p>The first example is to use <code>ssh</code> client to connect to a <code>sshd</code> server to obtain a remote terminal. The same idea as TELNET, but secure.</p><p>You can achieve this by typing: <code>user1$ ssh 192.168.0.1</code></p><p>The previous command will try to establish a SSH session over a TCP socket between the client <code>ssh</code> and <code>sshd</code> server listening on 192.168.0.1:22.</p><p>By default, SSH assumes that you want to authenticate with the user you are currently using.</p><p>If you want to use a different user for login on the remote host, simply use: remoteusername@hostname like this:</p><pre><code>user1$ ssh user2@192.168.0.1</code></pre><p>With SSH we can also transfer files securely between machines on a network.</p><p>We can do this with SCP and SFTP.</p><p><strong>SCP (Secure Copy)</strong></p><p>The command <code>scp</code> is essentially a client program that uses the SSH protocol to send and receive files over and encrypted SSH session. You can transfer files from the client to the server and vice versa.</p><p>Let&#x2019;s see a simple command that copies a file called file.txt <strong>from the client to the server</strong>, to the home directory of the user &#x201C;username&#x201D;:</p><pre><code>$ scp file.txt username@remotehost:</code></pre><p>If you want to specify a new directory and a new name for the file, you can do it this way:</p><pre><code>$ scp file.txt username@remotehost:mydirectory/anothername.txt</code></pre><p>To <strong>recursively</strong> copy a directory to the server, use the &#x201C;-r&#x201D; option:</p><pre><code>$ scp -r Documents username@remotehost:</code></pre><p>And finally, to copy <strong>from the server to the client</strong> just reverse the from and to:</p><pre><code>$ scp username@remotehost:file.txt</code></pre><p><strong>SFTP (Secure FTP)</strong></p><p>SFTP is a secure implementation of the traditional FTP protocol using a SSH session. Let us take a look at how to use the <code>sftp</code> command:</p><pre><code>$ sftp user@hostname</code></pre><h4 id="startstop-sshd">Start/Stop <code>sshd</code></h4><p>Each time you change the configuration of <code>sshd</code> you have to stop and start it to apply the changes.</p><p>You can do it this way in most Linux systems:</p><pre><code># /etc/init.d/ssh stop 
# /etc/init.d/ssh start</code></pre><h4 id="super-servers">Super Servers</h4><p>A way of implementing a network service is to use a <strong>stand-alone daemon</strong>. A stand-alone daemon listens to a port and serves client requests associated with that port.</p><p>However, for simple services that are used not very often it is more efficient to use a &#x201C;<strong>super server</strong>&#x201D; or &#x201C;super daemon&#x201D;.</p><p>A <strong>super-daemon listens to several ports</strong>. They use memory more efficiently.</p><p>On the other hand, a dedicated or stand-alone server that intercepts the traffic directly is preferable for services that have frequent traffic.</p><p>In Linux <code>inetd</code> is the typical super-daemon.</p><p>Each time a client requests a service managed by <code>inetd</code>, the super-daemon uses its configuration file (<strong>/etc/inetd.conf</strong>) to determine which server program should manage the request and executes the corresponding server program.</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*SB2xwMGM5mRm1Qu3RioWZw.png" class="kg-image" alt="Internet Educational Series #3: Network Applications" loading="lazy" width="536" height="291"></figure><ul><li>For each TCP connection, inetd creates a process and connects STDIN and STDOUT of this process to the socket established with the client.</li><li>UDP sockets are generally handled by a single application-specific server instance that handles all packets on that port.</li><li>Some simple services such as &#x201C;daytime&#x201D; are handled directly by <code>inetd</code>, without spawning an external application-specific server.</li></ul><p><strong>Configuration</strong></p><p>The <code>inetd</code> super-daemon is configured using the file /etc/inetd.conf .</p><p>Each line in the file contains the following fields:</p><pre><code>service_name	socket_type	{wait|nowait}	user	server_program	[server_program arguments]</code></pre><p>For example, the configuration line for the TELNET service is something like:</p><pre><code>telnet	stream	tcp	nowait	root	/usr/sbin/in.telnetd</code></pre><p>Otherway, service names and ports are mapped in the configuration file <strong>/etc/services</strong>.</p><p>You can check the default port for the telnet service typing:</p><pre><code>$ cat /etc/services | grep telnet 
 
telnet 		23/tcp 
...</code></pre><p>The last file important to mention is the <strong>/var/log/daemon.log</strong>, where <code>inetd</code> writes its messages.</p><p><strong>Start/Stop inetd</strong></p><p>Each time you change the configuration of <code>inetd</code> you have to <strong>stop and start it to apply the changes</strong>. It can be done as follows:</p><pre><code># /etc/init.d/openbsd-inetd stop 
# /etc/init.d/openbsd-inetd start</code></pre><p><strong>Creating a Service under <code>inetd</code></strong></p><p>Follow this steps to create a service under inetd:</p><ul><li>Create the server program using STDIN and STDOUT.</li><li>Choose a name and a port for the service.</li><li>Set the port/name of the service in the /etc/services file.</li><li>Start and stop <code>inetd</code></li></ul><p>Let&#x2019;s configure the service &#x201C;my-echo&#x201D; following the previous steps:</p><ol><li>Add the configuration file in /etc/inetd.conf</li><li>my-echo stream tcp nowait root /root/my-echo.sh</li><li>Restart <code>inetd</code> and observe the log file where inetd writes its messages:</li><li># tail -f /var/log/daemon.log</li><li>inetd[1173]: my-echo/tcp: unknown service</li><li>Add a port number for our service in the file /etc/services:</li><li>my-echo 12345/tcp</li><li>Restart inetd and try to connect to the service. Let&#x2019;s observe the log file</li><li># tail -f /var/log/daemon.log</li><li>execv /root/my-echo.sh: No such file or directory</li><li>We need to create the file as it indicates in the previous message:</li><li>cat</li></ol><p><em>The command <code>cat</code> without parameters, writes to STDOUT what it reads from STDIN.</em>Let&#x2019;s take a look again at the log file:</p><pre><code># tail -f /var/log/daemon.log 
inetd[1173]: my-echo/tcp: Permission denied</code></pre><ol><li>Give permisions to the script, and get back to the logs file:</li><li>chmod u+x /root/my-echo.sh</li><li>#tail -f /var/log/daemon.log</li><li>inetd[1207]: execv /root/my-echo.sh: Exec format error</li><li>We need a &#x201C;formally correct&#x201D; script, and to do so we need to add the following initial line with the corresponding interpreter</li><li>#!/bin/bash</li><li>cat</li></ol><p>We will now create a <code>netcat</code> client connection to check that the <code>my-echo</code> service is working properly.</p><p>You can observe the connections of the services with the <code>lsof</code> command, and check that the STDIN, STDOUT and STDERR of the processes are connected to the corresponding socket</p><pre><code>virt1# lsof -a -p 1216</code></pre><p>and we see that the 0, 1 and 2 FD are established correctly.</p><p>Voil&#xE0;! We&#x2019;ve got the service configured.</p><hr><p>Alright, I know this has been a long journey, but congrats if you made it up to this point! Take your time to digest everything we&#x2019;ve been seeing so far, and if you still have any doubts, hit me up at <a href="mailto:akakush19@protonmail.com">akakush19@protonmail.com</a>, I&#x2019;ll be happy to share thoughts with you!</p><hr><p>If you want to check my previous articles to understand some other Internet concepts feel free to do so!</p><ul><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-1-ethernet-switching-vlans-9fc667595d1e?ref=blog.lares21.xyz" rel="noopener">Chapter 1: Ethernet, Switching &amp; VLANs</a></li><li><a href="https://medium.datadriveninvestor.com/internet-educational-series-2-ip-basics-a8a11c24e644?ref=blog.lares21.xyz" rel="noopener">Chapter 2: IP Basics</a></li></ul><hr><p><strong>Leave a clap if you enjoyed this post, you&#x2019;ll support my work and help me keep myself motivated to write more! Knowledge is power!</strong></p>]]></content:encoded></item><item><title><![CDATA[Internet Educational Series #2: IP Basics]]></title><description><![CDATA[How does the Internet work? If you ever had this question popping up in your head, you’ve landed in the right place. In today’s article…]]></description><link>https://blog.lares21.xyz/internet-educational-series-2-ip-basics/</link><guid isPermaLink="false">665ee4afd242c72c9151c1a2</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Mon, 22 Mar 2021 10:07:34 GMT</pubDate><media:content url="https://cdn-images-1.medium.com/max/800/0*V3c9Sqysoy7UhncY" medium="image"/><content:encoded><![CDATA[<h4 id="how-does-the-internet-work-if-you-ever-had-this-question-popping-up-in-your-head-you%E2%80%99ve-landed-in-the-right-place-in-today%E2%80%99s-article-we-will-talk-about-internet-protocol-ip">How does the Internet work? If you ever had this question popping up in your head, you&#x2019;ve landed in the right place. In today&#x2019;s article, we will talk about Internet Protocol (IP).</h4><img src="https://cdn-images-1.medium.com/max/800/0*V3c9Sqysoy7UhncY" alt="Internet Educational Series #2: IP Basics"><p>Hello dear reader! And welcome to my Internet Educational Series.</p><p>Here you&#x2019;ll learn all the basics from the Internet, how does it work, why does it work, the protocols used, and many more you&#x2019;ll discover as you read through my articles.</p><p>I hope you like them, and enjoy them as much as I&#x2019;m doing when writing them.</p><p>Let&#x2019;s get into it! Today we are talking about the Internet Protocol Basics, also know as IP.</p><p>I&#x2019;ll start from the beginning, trying to make everything understandable for everyone, even if you haven&#x2019;t got a tech background.</p><h4 id="1-motivation-why-a-network-layer">1. Motivation. Why a Network Layer?</h4><p>When the first Ethernet networks were created, people started thinking on how we could expand, and connect more and more people to those networks.</p><p>That&#x2019;s when the two main problems, that the Internet tries to solve, appeared:</p><ol><li>Universal Interconnection</li><li>Scalability (Up to millions of interconnected devices)</li></ol><p>And today you&#x2019;ll learn how humans have solved this two problems, with the different technologies involved, and how they interact between them to provide the global interconnected network that we know today as <strong>The Internet</strong>.</p><p>The first step to get universal interconnection is to have a global network of <strong>addresses</strong> to identify devices connected to the different data link layers.</p><p>Many different network protocols have been implemented: IP, <a href="https://en.wikipedia.org/wiki/Internetwork_Packet_Exchange?ref=blog.lares21.xyz" rel="noopener">IPX</a> (from Novell), <a href="https://en.wikipedia.org/wiki/NetBIOS?ref=blog.lares21.xyz" rel="noopener">NetBIOS</a> (from Microsoft), etc.</p><p>Fortunately IP (Internet Protocol) has become almost the unique network protocol used.</p><p>IP has 2 versions:</p><ul><li><strong>IPv4</strong> (the one we will talk about today)</li><li>Network addresses of 32 bits</li><li>Addresses are represented with the dot-decimal notation: 192.168.1.0</li><li>Each bytes is represented in decimal with a value between 0 and 255.</li><li><strong>IPv6</strong></li><li>Network addresses of 128 bits.</li></ul><p>To send data using IP to a certain device, you need to know its IP address, but IP addresses are hard to remember.</p><p>That&#x2019;s why we use <strong>DNS (Domain Name System)</strong> to translate addresses to names. But we will talk about this in another article.</p><p>Devices also have <strong>physical addresses</strong>, which are the MAC ones, as we saw in the previous article about Ethernet. Check it out <a href="https://medium.com/p/9fc667595d1e/edit?ref=blog.lares21.xyz">here</a> if you have not read it.</p><p>This MAC addresses are hard-coded by the vendor to identify the device uniquely.</p><p>However, only with the MAC addresses we cannot scale to big networks, and that&#x2019;s why Ethernet cannot be deployed as a universal network, and we need something else.</p><hr><h4 id="2-ip-addressing">2. IP Addressing</h4><p>IP implements a &#x201C;clever way of assigning addresses&#x201D;.</p><p>First of all, it is important to know that IP addresses are <strong>configured</strong>, not hard-coded.</p><p>You can use the <code>ifconfig</code> command to configure an @IP to a NIC (Network Interface Card).</p><p>Example of a configuration of an IPv4 address in Unix Systems:</p><pre><code>ifconfig eth0 192.168.0.1</code></pre><p>The most important features of IP are:</p><ul><li>Devices that are &#x201C;close&#x201D; must have &#x201C;similar addresses&#x201D;, which mean addresses with a <strong>common prefix</strong>.</li><li>IP traffic is routed using prefixes, instead of single addresses, which allows reducing the size of the routing tables.</li></ul><p>It is very usual to get our IP address configured dynamically from a local server with a protocol called <strong>DHCP (Dynamic Host Configuration Protocol)</strong>, though we&#x2019;ll talk about it in later articles.</p><h4 id="21-netid-hostid">2.1 NetID &amp; HostID</h4><p>IP Divides the address in two parts to implement the network addressing plan:</p><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-htyvolrkvntrb6io3j9bga.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="461" height="66"></figure><ul><li>Devices with a <strong>common NetID</strong> are said to be in the <strong>same IP network</strong>.</li><li>Devices in <strong>different IP networks</strong> must have <strong>different NetIDs</strong>.</li><li>The portion of the address that identifies a particular device on the network is called the <strong>HostID</strong>.</li></ul><p>For now we will consider that the address division is 24/8: 24 bits for NetID and 8 bits for the HostID.</p><p>For example if we have the IP address 192.168.0.1:</p><ul><li>NetID: 192.168.0 (24 bits)</li><li>HostID: 1 (8 bits)</li></ul><p><em>Note: There are some addresses that are reserved in each Network that depend on the HostID.</em></p><ul><li>If the HostID = 0s it is reserved for the <strong>network address</strong>.</li><li>If the HostID = 1s it is reserved for the <strong>broadcast address</strong>.</li></ul><p>So in our example, 192.168.0.0 would be the network address, and 192.168.0.255 would be the broadcast address.</p><p>But how do we separate this addresses between them, you may ask?</p><p>The answer is with the devices we all need at home if we want to connect to the Internet. <strong>Routers</strong> are the ones who separate the different IP networks.</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*9NUdfGpA9HPzE-ysZULhGw.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="472" height="193"></figure><p>And this is how we get to understand the next step.</p><hr><h4 id="3-routing">3. Routing</h4><p>Routing is the name we have given at the process that routers do when interconnecting different data link layers.</p><p>Routers transfer IP packets from one DLL to another, but <strong>frames are not transferred</strong>.</p><p>When doing IP Routing, what we are doing is searching all over the Internet the destination device we want to reach.</p><p>To do that, IP users provide the destination IP address or name to the router, and this one tries to find where it is located, to transmit data between the two hosts.</p><p>However, IP does not guarantee a reliable delivery. It provides a <strong>best effort</strong> host to host service, as it uses a <strong>hop by hop</strong> routing mechanism.</p><p>This means that each packet is sent from one router (hop) to another one (next hop) in the path.</p><p>By using this mechanism, we achieve a higher scalability than with Ethernet for various reasons:</p><ul><li>Routing tables group addresses: The amount of information that a router needs to keep is proportional to the number of networks in the Internet, not the number of devices.</li><li>Routers filter Layer 2 traffic: they efficiently forward (route) packets between data link networks.</li></ul><p>Example of IP Routing:</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*gofS_Q_lxvL_XtHVSHNUFw.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="567" height="383"></figure><hr><h4 id="4-internet-applications">4. Internet Applications</h4><p>Many protocols over the Internet use the IP network with a <strong>client/server model</strong>.</p><p>But what is a client/server model exactly?</p><ul><li>Servers are processes or network daemons that are running continuously in the background.</li><li>Clients are the ones who initiate the communication with servers.</li><li>Clients must know the address of the server (but not necessarily otherwise when the communication is initiated).</li></ul><p>When we initiate processes, the address must be composed of 3 parameters:</p><p><strong>IP address, transport protocol and port</strong>.</p><p>The transport protocols (L4) provide multiplexing identifiers for their users. This multiplexing IDs have a size of 16 bits and they are called <strong>ports</strong>.</p><p>There are two transport protocols: <strong>TCP and UDP</strong>.</p><ul><li>User Datagram Protocol (UDP)</li><li>Simplest transport protocol</li><li>Message-oriented</li><li>Each UDP datagram is encapsulated in a IP datagram</li><li>UDP only offers multiplexing and checksum for discarding wrong data</li><li>For multiplexing it uses the source and destination ports</li><li>Transport Control Protocol (TCP)</li><li>TCP provides full-duplex communication, and encapsulates its data over IP datagrams</li><li>Connection-oriented (there is a handshake of three messages before data can be sent)</li><li>The communication is managed as a data flow (not message-oriented)</li><li>TCP is reliable, as it adds support to detect errors or lost data and to trigger retransmission until the data is correctly and completely received</li></ul><p>Over this protocols, we do have the next Layer in the OSI model, which is the <strong>Application Layer</strong>.</p><p>Here we can use the different applications that exist over the Transport protocol layer, like <strong>WHOIS, HTTP, DNS, DHCP&#x2026;</strong></p><p>A nice recap of what we&#x2019;ve seen so far would be the following image:</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*S3hFV--MK5XWUypWRaQbSA.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="551" height="309"></figure><hr><h4 id="5-classful-ip">5. Classful IP</h4><p>Let&#x2019;s get back to the backbone of this article.</p><p>We&#x2019;ve seen before that IP addresses are divided in NetID and HostID, to identify either the network the device is in, and the exact device that we want to establish a communication with.</p><p>Let&#x2019;s now see how does IP solve the problem of finding who is each device in their network.</p><h4 id="51-address-resolution-protocol-arp">5.1 Address Resolution Protocol (ARP)</h4><p>When we want to find who is exactly each device in our network, we use the ARP protocol.</p><p>ARP is a <strong>request/response</strong> protocol for the dynamic resolution of the mapping @IP-@MAC.</p><p>It uses two messages <code>ARP-request</code> and <code>ARP-reply</code>, both encapsulated in MAC frames.</p><p>To figure out the MAC address associated with a certain IP address, ARP does the following process:</p><ul><li>The sender sends an <code>ARP-request</code> to broadcast (ff:ff:ff:ff:ff:ff)</li><li>This request contains the IP address of the host whose MAC address we want to know.</li><li>The device in the L2 network that has been configured with the IP requested, sends an <code>ARP-reply</code>.</li><li>This <code>ARP-reply</code> is <strong>unicast</strong> and it has as destination MAC the @MAC of the station that sent the <code>ARP-request</code>.</li><li>Now, both sender and receiver know the L2 and L3 address mappings of each other.</li></ul><p><strong>ARP Cach&#xE9;</strong>:</p><p>Since Broadcasting is very costly, a local file is used to store the bindings learned with ARP.</p><p>With this cach&#xE9;, we can handle future requests faster or more efficiently.</p><p>However, we need a mechanism to update this cache, because it cannot store all the addresses forever, as some addresses turn obsolete.</p><p>This mechanism is a <strong>timeout</strong>, or <strong>Time To Live (TTL)</strong>. When the TTL expires, the binding is removed from the ARP cache.</p><p>TTL can be manually configured.</p><p>In a Lunix OS, we can use several commands to view the ARP cache and to re-configure it, for example:</p><pre><code>arp -n 						#View the arp cache 
arp del 192.168.1.2 		#Delete mapping 
arping 192.168.1.2			#ARP request 
ifconfig 					#View interfaces configuration 
ifconfig eth0 192.168.1.1	#Configure IP to eth0 
arp set 192.168.1.2 00:23:ae:1c:51:29 [temp] #sets a temporal mapping</code></pre><hr><p>So far, we&#x2019;ve learned how IP packets are exchanged between devices that are on the same data link.</p><p>But we want to exchange packets between devices that are not in the same data link.</p><p>So, how can we know that a device is connected to a certain data link?</p><p>The answer is the 2 parts of the IPv4 addresses, NetID and HostID.</p><p>As you know, the devices that share the same data link, must have the same NetID, so forth, a device only needs to check if the destination @IP has the same NetID to know if the receiver is in the same data link of the sender, or on another one.</p><p>Now we need to introduce a new concept to understand how to route the packets to the correct data link.</p><p><strong>Classes of Addresses</strong>.</p><h4 id="class-a-addresses">Class-A Addresses</h4><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-88x2w8iu_8rudcs6f1ggiw.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="551" height="62"></figure><ul><li>8/24</li><li>NetID: w &#x2192; 0&#x2013;127</li><li>HostID: x.y.z</li><li>Number of Networks: 2&#x2077; = 128 networks</li><li>Number of addresses per network = 2&#xB2;&#x2074; = 16.777.216 addresses</li></ul><h4 id="class-b-addresses">Class-B Addresses</h4><figure class="kg-card kg-image-card"><img src="https://blog.lares21.xyz/content/images/2024/06/1-9pc0hw6wypgc6hobamp7dg.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="551" height="62"></figure><ul><li>16/16</li><li>NetID: w.x. &#x2192; 128&#x2013;191</li><li>HostID: y.z</li><li>Number of Networks: 2&#xB9;&#x2074; = 16384 Class B networks</li><li>Number of addresses per network = 2&#xB9;&#x2076; = 65536 addresses</li><li>Private addresses from 172.16.0.0 to 172.31.0.0</li></ul><h4 id="class-c-addresses">Class-C Addresses</h4><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*Y_9U8Z0CvUkv0_Tu16UBKA.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="551" height="62"></figure><ul><li>24/8</li><li>NetID: w.x.y &#x2192; 192&#x2013;223</li><li>HostID: z</li><li>Number of networks: 2&#xB2;&#xB9; = 2097152 Class C networks</li><li>Number of addresses per network: 2&#x2078; = 256 addresses</li><li>Private network addresses from 192.168.0.0 to 192.168.255.0</li></ul><h4 id="class-d-and-class-e">Class-D and Class-E</h4><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*LY_cXqHWpeLbFSTcJ5yDEw.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="551" height="139"></figure><p>Class D:</p><ul><li>Used for group communications, or <strong>multicast</strong>.</li><li>The first byte of class D goes from 224 to 238.</li></ul><p>Class E: the whole addressing of this class is reserved for future use</p><hr><h4 id="6-types-of-delivery">6. Types of Delivery</h4><p>Great, so now you know how are addresses routed to get to their destination. To classify in an easier way the routing of datagrams, we introduce two more concepts called</p><ul><li>Direct Delivery</li><li>Indirect Delivery</li></ul><h4 id="61-direct-delivery">6.1 Direct Delivery</h4><p>We use direct delivery when either sender and receiver are physically connected to the same L2 network.</p><p>This means the destination IP address has the same NetID than the IP source address.</p><p>Direct deliveries do not require intermediaries (routers).</p><p>We use the ARP cache or the ARP protocol to find out the destination @MAC, which is the only missing parameter to build the MAC frame.</p><h4 id="62-indirect-delivery">6.2 Indirect Delivery</h4><p>The next step is to learn how to make indirect deliveries, which as you may have guessed, are the types of datagram deliveries that are made from one device that is connected to a certain network, to another device that is connected in a different network.</p><p>For this purpose, we use <strong>routing tables</strong> and an intermediate device: an IP router (IP gateway).</p><p>A routing table is a local table (each host or router has one) that is consulted to find the parameters of the next hop, where the packets must be forwarded.</p><p>In Unix-like systems you can view the routing table with the command <code>route -n</code>.</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*tgjG4D0Nhpiyao4AC7-xZw.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="502" height="162"></figure><p>The first thing we need to observe in the previous example, is that our router has <strong>two NICs</strong> and also two IP addresses configured, one to each NIC.</p><p>In general, routing tables contain at least the following entries:</p><ul><li>Destination network address</li><li>Output NIC</li><li>Next Hop (The @IP of the next hop)</li></ul><p>Let&#x2019;s see an example of the previous picture, but with it&#x2019;s corresponding routing tables from each host:</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*Or4KAsvRWnNxhdDMciX4Zg.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="449" height="203"></figure><p>So, once you&#x2019;ve understood the routing tables, and how they are configured into each host, it&#x2019;s much easier to get how indirect deliveries work.</p><p>IP routing is performed <strong>hop by hop</strong>: routers/hosts only take care of finding the parameters of the <strong>next device</strong> where to forward the packet.</p><p>So for this purpose, the routing table provides us with the @IP of the next hop, which has to be directly reachable.</p><h4 id="63-icmp">6.3 ICMP</h4><p>As you may imagine, indirect deliveries have more problems than direct ones.</p><p>That&#x2019;s why ICMP was implemented. This protocol is called <strong>Internet Control Message Protocol (ICMP)</strong>, and its purpose is testing and finding anomalies in networks.</p><p>Let&#x2019;s imagine that a packet arrives to a router that hasn&#x2019;t got any routing entry for the destination.</p><p>In this situation, ICMP defines a message that the routers can send to the source indicating why the packet did not arrive to its destination and why it has been discarded.</p><p>Then we can find another better route to send our packet through, or try to solve the problem.</p><p>If you ever try to do networking tasks, you&#x2019;ll find ICMP very useful to test if the network is working or not, and you&#x2019;ll get very used to the following messages:</p><ul><li>echo-request (ping)</li><li>echo-reply (pong)</li></ul><hr><h4 id="7-classless-ip">7. Classless IP</h4><p>The previously explained IP (classful IP) has two big problems:</p><ol><li>Address Exhaustion</li><li>The class structure is not efficient</li><li>An institution or company that wants to build an IP network of 6 hosts, needs an entire C-class address, which will result in 248 unused addresses. That scales even worse when we need more addresses, as if we need to connect 300 hosts, we would have to ask for a B-class, and would end up in 16082 unused addresses.</li><li>Slow Routing</li><li>Classful addressing generates large and unmanageable routing tables, as we need one entry in the routing table per class.</li><li>This was critical for the routers of the <strong>Internet Backbone</strong> that have to route packets at high speeds.</li></ol><p>That&#x2019;s when people realized that Internet was &#x201C;dying of success&#x201D;, and something had to be done.</p><p>The proposed solutions for this problems were the following ones:</p><ul><li><strong>Subnetting / Supernetting</strong></li><li><strong>CIDR (Classless Inter Domain Routing)</strong> with <strong>geographical</strong> allocation of addresses.</li><li>Dynamic NAT for using less public addresses.</li><li>DHCP for reusing IP addresses</li></ul><p>Moreover, IPv6 is another solution, which we will not cover in this article, but also solves all the previous problems and has an even better scalability.</p><p>It&#x2019;s main difference with IPv4 is the address space, which goes from 32-bit to 128-bit addresses.</p><h4 id="71-subnetting">7.1 Subnetting</h4><p>When dealing the previously seen problems, a new concept appeared: <strong>Net masks</strong>.</p><p>Net masks allow us to split networks in many different parts, and also group them in bigger ones.</p><p>In particular, a <strong>Subnet</strong> is a network smaller than the original class.</p><p>To indicate that a certain network has a net mask, we can use different notations, however the most common one is the CIDR notation.</p><p>This notation is exactly like this: <code>@IP/X</code> where X is a decimal value indication the number of <strong>1s</strong> of the network mask.</p><p>Eg 1: 147.83.0.0/16 is a network number of a class B network.</p><p>Eg 2: 192.168.1.3/24 is an IP address of a host in a class C network.</p><p>Let&#x2019;s see an example of a Class C Division (the most common ones you&#x2019;ll see)</p><p>We want to divide the private Class C <strong>192.168.1.0</strong>, which has room for 256 addresses, into 2 different subnets with 128 addresses each.</p><p>Actually, subtracting the network address and the broadcast address from each one of them, we would end up with 2 networks of 126 hosts each.</p><p>To do so, we need extend the network part in one bit.</p><p>Now I&#x2019;ll show you my way of calculating how to identify the netmask we need to divide our bigger networks.</p><p>As we know in Class C addresses, we have 256 free addresses, which is 2&#x2078;.</p><p>This means we have 8 bits for the HostID (256 hosts), and 24 bits for the NetID.</p><p>If we add one extra bit to the NetID, we end up with 25 bits for the NetID and 7 bits for the HostID.</p><p>If we calculate how many hosts we can have with 7 bits, we just do 2&#x2077; = 128.</p><p>Exactly the number of hosts we needed!</p><p>So now, we can see our 2 subnets, divided thanks to our mask:</p><ol><li>The first one goes from 192.168.1.0/25 &#x2192; 192.168.1.127/25</li><li>The second one goes from 192.168.1.128/25 &#x2192; 192.168.1.255/25</li></ol><hr><p>Masks are also used in the routing tables of routers that are &#x201C;aware of subnetting&#x201D;.</p><p>Let&#x2019;s see an example to understand it better:</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*ygMazgKPLcAk9raTN-CePg.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="548" height="262"></figure><p>Notice that we might have an IP network in which we have classful routers and classless routers (r1 and r2).</p><p>Outside the subnets, the routers can still use classful routing.</p><p>In our example, router 1 still sees 192.168.1.0 as a class C network address, and uses a classful routing table.</p><p>However, the internal router (2), is aware of subnetting and it is able to differentiate between the two subnetworks.</p><p>In this case, to properly route IP packets to each subnet, the router 2 uses a classless routing table, which includes masks for correctly interpreting IP network numbers.</p><hr><p>Until now, we have been using a type of subnetting called <strong>FLSM (Fixed Length Subnet Mask)</strong>, which as it name indicates, it creates fixed subnets, all of them have the same number of hosts.</p><p>But what happens if we want to divide a /24 network (256 addresses) into 3 subnets, one with 120 hosts, and the other 2 with 60 hosts each one?</p><p>Here is when <strong>VLSM (Variable Length Subnet Mask)</strong> comes into play.</p><p>To divide networks into smaller ones, we must always start with the biggest one we want to create. So in this case, we would first need to assign 7 bits for the HostID (120 hosts needs at least 128 addresses, 2&#x2077;) and then we would need at least 2 extra bits to differentiate the 3 networks between them.</p><p>So we would end up with 9 bits needed for this network, which makes it imposible for a /24 network to divide it when using FLSM. We would need at least a /23 network, and the subnets would be like this:</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*9pP3sa09LMXhD6hbSlfSww.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="484" height="165"></figure><p>We can see that we need 9 bits to divide the 3 networks (which will actually create 4 networks, and one of them will be redundant).</p><ul><li>SubnetID == 00 &#x2192; 10.0.0.0 to 10.0.0.127 (/25)</li><li>SubnetID == 01 &#x2192; 10.0.0.128 to 10.0.0.255 (/25)</li><li>SubnetID == 10 &#x2192; 10.0.1.0 to 10.0.1.127 (/25)</li><li>SubnetID == 11 &#x2192; 10.0.1.128 to 10.0.1.255 (/25)</li></ul><p>On the other hand, if we used VLSM, we could have adapted our network with just a /24 mask, as the 8th bit would actually differentiate the bigger network from the smaller ones, and the 7th one would differentiate the two small networks between them.</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*gyZX9LMQlK2VTsVXvANwJw.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="372" height="125"></figure><ul><li>SubnetID == 0 &#x2192; 10.0.0.0 to 10.0.0.127 (/25)</li><li>SubnetID == 10 &#x2192; 10.0.0.128 to 10.0.0.191 (/26)</li><li>SubnetID == 11 &#x2192; 10.0.0.192 to 10.0.0.255 (/26)</li></ul><p>This way we would have room for all the hosts we need, and we would not be occupying redundant space on the network.</p><h4 id="72-supernetting">7.2 Supernetting</h4><p>As you may imagine, supernetting is the opposite of subnetting.</p><p>Grouping smaller networks into a bigger one.</p><p>Let&#x2019;s assume that we need an address block for a network composed of 1000 hosts.</p><p>A class C network provides only 254 addresses, so it is not enough.</p><p>We could ask for a class B address, but we would drop 2&#xB9;&#x2076;&#x200A;&#x2014;&#x200A;2&#x2013;1000 = 64534 addresses.</p><p>So, the solution would be using multiple class C networks.</p><p>A network with 1000 hosts needs at least 4 classes C.</p><p>Example:</p><p>200.45.64.0 &#x2192; 11001000 . 00101101 . 010000 <strong>00</strong> . 00000000</p><p>200.45.65.0 &#x2192; 11001000 . 00101101 . 010000 <strong>01</strong> . 00000000</p><p>200.45.66.0 &#x2192; 11001000 . 00101101 . 010000 <strong>10</strong> . 00000000</p><p>200.45.67.0 &#x2192; 11001000 . 00101101 . 010000 <strong>11</strong> . 00000000</p><p>See that we need at least 10 bits to differentiate the networks, which brings us to a /22 mask to group them all into the same bigger network.</p><p>Finally, it is worth to remark that Internet routers use this idea of classless routing, and so fort, Internet routers abandoned the old scheme of old IP classes.</p><hr><h4 id="8-cidr">8. CIDR</h4><p><strong>Classless Inter-Domain Routing (CIDR)</strong> means that Internet routers do not follow the classes scheme.</p><p>It implies that we can aggregate many networks and route them with just one entry to be effective.</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*HKEr5Y8a5-yCYxvGxKK8vg.png" class="kg-image" alt="Internet Educational Series #2: IP Basics" loading="lazy" width="517" height="303"></figure><p>CIDR is suitable for reducing the <strong>growth of routing tables</strong> and for providing <strong>efficient routing</strong> in the backbone Internet routers.</p><p>It reduces the number of table entries as we can aggregate many blocks of addresses and route according to these supernets.</p><p>With few entries, the processing time due routing is decreased.</p><p>After this idea came into play, classes made no sense anymore inside the Internet, and nowadays the routing tables of the Internet routers are also classless.</p><p>However CIDR, supernetting and subnetting are all compatible.</p><p>Their combined usage provides effective management of address allocation and routing tables.</p><ul><li><strong>Edge routers</strong> use long prefixes for their subnets and short prefixes to describe other networks.</li><li><strong>Core routers</strong> in the Internet backbone try to route packets with the shortest prefix possible (biggest possible supernet).</li></ul><hr><p>We are getting to the end of this article. I hope you found what you were looking for, and wish that you now have a better understanding of the Internet Protocol, and how do we connect and send packets between devices, even if they share the same network, or if they are in another part of the world.</p><p>This is the second episode of a complete series that will guide you through the <strong>Internet Basics</strong>, so in case you want to improve your digital knowledge, and have a solid understanding of <strong>how does the internet work</strong>, keep tuned in to my profile as I&#x2019;ll keep posting articles about this topics.</p><hr><p><strong>Leave a clap if you enjoyed this post, you&#x2019;ll support my work and help me keep myself motivated to write more! Knowledge is power!</strong></p>]]></content:encoded></item><item><title><![CDATA[Internet Educational Series #1: Ethernet, Switching & VLANs]]></title><description><![CDATA[How does the Internet work? If you ever had this question popping up in your head, you’ve landed in the right place.]]></description><link>https://blog.lares21.xyz/internet-educational-series-1-ethernet-switching-vlans/</link><guid isPermaLink="false">665ee4afd242c72c9151c1a6</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Tue, 02 Mar 2021 04:00:36 GMT</pubDate><media:content url="https://cdn-images-1.medium.com/max/800/0*eQ0t_x0Difu4CF7U" medium="image"/><content:encoded><![CDATA[<img src="https://cdn-images-1.medium.com/max/800/0*eQ0t_x0Difu4CF7U" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs"><p>Hello dear reader! And welcome to my Internet Educational Series.</p><p>Here you&#x2019;ll learn all the basics from the Internet, how does it work, why does it work, the protocols used, and many many more you&#x2019;ll get to discover as you read my articles.</p><p>I hope you like them, and enjoy them as much as I&#x2019;m doing when writing them.</p><p>All right, let&#x2019;s get into it!</p><p>I&#x2019;ll start from the beginning, trying to cover all aspects of how the Internet evolved to reach what it is nowadays.</p><h4 id="1-history">1. History</h4><p>The internet history itself starts a long time ago, with an invention called ARPANET with military purposes as many things have done during history, however, my articles won&#x2019;t cover this part, they are solely focused on the actual and &#x201C;true&#x201D; internet as we know it.</p><p>As you may imagine, the internet did not start as the <strong>wireless</strong> network it is nowadays. At the start, communications were made by cable (most of them still are), and the first technology that was invented aimed to propagate information from one place to another, was called <strong>ETHERNET</strong>.</p><p>The first <a href="https://es.wikipedia.org/wiki/Ethernet?ref=blog.lares21.xyz" rel="noopener">Ethernet</a> was designed in 1973 by Bob Metcalfe in Xerox Corporation&#x2019;s Palo Alto laboratory.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/1*HAovGn7SUgi2mRGgVTDyYg.jpeg" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="310" height="162"><figcaption><span style="white-space: pre-wrap;">The first&#xA0;Ethernet</span></figcaption></figure><p>This first version was able to operate at 3Mbps over a shared coaxial cable using <a href="https://en.wikipedia.org/wiki/Carrier-sense_multiple_access_with_collision_detection?ref=blog.lares21.xyz" rel="noopener">CSMA-CD</a>.</p><p>Metcalfe convinced DEC, Intel and Xerox (&#x201C;DIX&#x201D;, Digital Intel and Xerox) to work together to promote Ethernet as a standard. The first DIX standard draft was published on September 30, 1980 by the <strong>Institute of Electrical and Electronics Engineers (</strong><a href="https://www.ieee.org/?ref=blog.lares21.xyz" rel="noopener"><strong>IEEE</strong></a><strong>)</strong> under the standard <a href="https://en.wikipedia.org/wiki/IEEE_802.3?ref=blog.lares21.xyz" rel="noopener">802.3</a>.</p><p>The DIX standard specified the MAC layer of a 10Mbps local area network called Ethernet.</p><h4 id="2-the-ethernet-frame">2. The Ethernet Frame</h4><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/1*QCeh9lPZiOWcZ4_OzscnNQ.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="513" height="177"><figcaption><span style="white-space: pre-wrap;">Ethernet frame</span></figcaption></figure><p>Let&#x2019;s see the general design of IEEE 802.3/DIX frame:</p><ul><li>The medium is a coaxial cable (a single link bus)</li><li>A <a href="https://en.wikipedia.org/wiki/Manchester_code?ref=blog.lares21.xyz#:~:text=In%20telecommunication%20and%20data%20storage,signal%20with%20no%20DC%20component." rel="noopener">Manchester</a> line code is used to transmit each symbol.</li><li>The transmission of frames is asynchronous.</li><li>Multiple stations are allowed to be connected to the link (multi-point) and the MA (medium access) is based on CSMA-CD.</li><li>Each station is identified by a MAC address of 6 bytes (48 bits).</li><li>There is a 2-byte (16 bits) field for multiplexing MAC users.</li></ul><p>As mentioned, the transmission over the coaxial was asynchronous and used the Manchester line coding, thus the <strong>preamble and SDF</strong> were necessary to synchronize the receiver.</p><ul><li><strong>Mac Addresses</strong></li><li>Mac addresses are formed by 48 bits, and it serves as Hardware address, physical address, Ethernet address or layer 2 address.</li><li>It is usually expressed in <strong>Hexadecimal</strong> (12:34:56:78:9A:BC)</li><li>The standard transmission order sends the Most Significant Byte (MSB) first, and inside this byte the least significant bit (lsb) first.</li><li>For example, the MSB of 12:34:56:78:9A:BC is 12. Which in binary, 12 is 00010010, and we start transmitting the lsb: 01001000&#x2026;</li><li>The meaning of the lsb and MSB is:</li><li>0: individual address (unicast)</li><li>1: Group address (Multicast) <em>I&#x2019;ll explain more in depth what is Multicast in a future article</em></li><li>If we find that all 48 bits are 1 (FF:FF:FF:FF:FF:FF) it means that we are transmitting to <strong>broadcast</strong>.</li><li><strong>Mac User Data</strong></li></ul><p>The maximum user data that can be carried in a L2 frame is called the <strong>Maximum Transfer Unit</strong> (MTU).</p><p>For the Ethernet, the MTU is <strong>1500 bytes</strong>. The minimum quantity of bytes of user data is 46 bytes. In case our data is less than 46 bytes, we have to pad the data by adding zeros at the end (zero padding).</p><p>Notice that the MAC user must include a <strong>length field</strong> in its PDU to distinguish its data from the padding.</p><ul><li><strong>Frame Check</strong></li></ul><p>This field is a Cyclical Redundancy Check (CRC) of 4 bytes (32 bits).</p><p>The CRC is used to <strong>detect incorrect frames</strong>.</p><p>The CRC value calculated by the destination, might not match the FCS field value f the frame for 2 reasons:</p><ul><li>Errors</li><li>Collisions</li></ul><p>It is important to know that 802.3 receivers DO NOT implement <strong>error control</strong>, but erroneous frames are silently discarded.</p><p>In case we want to manage errors at layer 2, we have to use the optional <strong>LLC sublayer</strong>, which is defined in the standard IEEE 802.2 (We&#x2019;ll se more about LLC below).</p><p>The MAC layer of the Ethernet MUST be the one who manage collisions.</p><h4 id="3-how-do-we-connect-senders-receivers-with-a-twisted-pair">3. How do we connect senders &amp; receivers? With a <strong>Twisted Pair</strong></h4><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-4uzuw8b8cwt5kzg-apgfta.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="279" height="119"><figcaption><span style="white-space: pre-wrap;">twisted pair</span></figcaption></figure><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/1*sQKoPJiSrC2T_FlnkKjdmQ.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="401" height="162"><figcaption><span style="white-space: pre-wrap;">crossover cable</span></figcaption></figure><p>In the above pictures we can see how two stations are connected via Ethernet with twisted pairs crossover cables.</p><p>But what to do with more stations? We use <strong>HUBS</strong>.</p><p>Let&#x2019;s see some examples to understand better how to connect multiple stations:</p><p>3 stations:</p><figure class="kg-card kg-image-card"><img src="https://cdn-images-1.medium.com/max/800/1*lOKzf80eq1S0nYHlZb0dOg.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="401" height="366"></figure><p>As we can see, the TX cable from the 1st station is connected to RX entries from the other ones.</p><p>And we can even connect hubs with other hubs!</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-ubbtkj482fy8xz0uikmx7g.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="510" height="200"><figcaption><span style="white-space: pre-wrap;">Hubs Interconnection</span></figcaption></figure><p>This way, when hubs are connected between them, we do just have to crossover the cables, and we can send information to every station on the network.</p><p>However, when transmitting with hubs, <strong>collisions</strong> appear, and this led engineers to think of a better way to connect stations between them.</p><h4 id="4-full-duplex-ethernet">4. Full-Duplex Ethernet</h4><h4 id="the-bridge-concept">The BRIDGE concept</h4><p>When trying to connect multiple stations, many collisions were found, and to try to avoid them, engineers came with an idea.</p><p>The idea was to separate collision domains.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/1*VPtbcuhY0KmjtCdmc4s6Mw.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="510" height="170"><figcaption><span style="white-space: pre-wrap;">Bridge</span></figcaption></figure><p>However, this broke the concept of having one MAC per link, thus developers had to develop a data link layer network capable of managing different links.</p><p>Let&#x2019;s see some important features from the Bridges:</p><ul><li>A bridge <strong>is not</strong> a physical device like the hub. The bridge <strong>processes</strong> the frames, and analyses the destination address of each frame.</li><li>If the destination MAC address belongs to the same collision domain of the incoming port, the bridge drops the frame.</li><li>If the destination MAC address belongs to the other collision domains, the bridge sends the frame through the other port.</li></ul><p>But <strong>how does the bridge know which MAC address belongs to each collision domain?</strong></p><p>The answer is called MAC LEARNING, which is an algorithm used by the Ethernet.</p><p>The bridge learns mapping between MAC addresses and collision domains by observing the source address of each received frame.</p><p>Let&#x2019;s see an example:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.lares21.xyz/content/images/2024/06/1-nrnt0quqvpcnntw6733euw.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="450" height="139"><figcaption><span style="white-space: pre-wrap;">MAC learning&#xA0;I</span></figcaption></figure><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/1*5d5Ngww5kozDmbIB3urHHA.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="479" height="158"><figcaption><span style="white-space: pre-wrap;">MAC learning&#xA0;II</span></figcaption></figure><ul><li>When A sent the frame, the bridge learned that the MAC of A is in the west collision domain.</li><li>Later when B sends a frame to A, this frame is not transmitted to the East port because the bridge knows that the MAC of A is in the west domain.</li><li>Notice that when B sends the frame to A, the bridge learns that B is also in the west collision domain.</li></ul><p>The MAC learning algorithm runs as an <strong>uncoordinated process</strong> in each bridge, in the sense that the algorithm does not require any coordination with other network devices.</p><p><em>This makes it not scalable for big networks, as a global coordinated process is necessary for such networks.</em></p><h4 id="the-switch-concept">The Switch Concept</h4><p>When we extend the bridge concept to a device with more than two ports, we arrive to the concept of SWITCHING.</p><p>Simply stated, <strong>a switch is a multi-port bridge</strong>.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/1*ogNDRRcBzeSdAvkoHIvTHg.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="475" height="159"><figcaption><span style="white-space: pre-wrap;">Switch</span></figcaption></figure><p>When the switch receives a frame with an unknown MAC, it maps the MAC to the port and sends the frame <strong>for all its ports except through the incoming port</strong>.</p><p>When a MAC is learned, the frame is sent only to the associated port.</p><p>Let&#x2019;s see what happens when D responds to A sending a new frame:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/1*sz2oj0wNBQt5WA_oaBrA2w.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="475" height="167"><figcaption><span style="white-space: pre-wrap;">Frames sent</span></figcaption></figure><h4 id="implementation-of-a-switch">Implementation of a Switch</h4><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/1*BM5kf-MTd8VLrO4ds4Q0nw.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="482" height="249"><figcaption><span style="white-space: pre-wrap;">Switch Implementation</span></figcaption></figure><p>In this section I&#x2019;ll describe a possible simplified implementation of a switch with 4 ports full-duplex of 10Mbps:</p><ul><li>Queues are used in each port for buffering incoming and outgoing frames.</li><li>The bus we need has to be at least a shared bus of <strong>40 Mbps</strong>.</li><li>This bus is called a <strong>&#x201D;back plane&#x201D;</strong>.</li><li>We manage the back plane bus with TDM deterministic multiplexing using four time slots.</li><li>Using the shared bus, each port is switched with another port (or ports) at a rate of 40 Mbps but only gets 1 slot each 4 time slots (which yields the 10Mbps transmission rate).</li><li>Notice that with this design, finally we obtain a switch of 4 ports without collisions, at a rate of 10Mbps, that can be used for a full-duplex communication.</li></ul><h4 id="data-link-layer-networks">Data Link Layer Networks</h4><p>The next step is to build a &#x201C;data link layer network&#x201D; by interconnecting several switches.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/1*W4Cm7w5omEfvKhUBnhW2qA.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="473" height="284"><figcaption><span style="white-space: pre-wrap;">DLL Networks&#xA0;I</span></figcaption></figure><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/1*OOEf5JgTzrcA0_5G_kT0QQ.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="473" height="268"><figcaption><span style="white-space: pre-wrap;">DLL Networks&#xA0;II</span></figcaption></figure><p>We can see that the same algorithm is applied to the data link layer network.</p><p>Once all the MAC addresses have been learned, broadcasting is not used anymore and the frames are forwarded using the <strong>MAC address table</strong>.</p><p>This way there are no collisions because the frames are always transmitted &#x201C;alone&#x201D;.</p><h4 id="5-broadcast-effects">5. Broadcast Effects</h4><p>Broadcast as you may know is the act of sending a frame to EVERYONE in the network. Not only to all switches but to all stations connected to the switches.</p><p>The broadcast MAC address is <strong>FF:FF:FF:FF:FF</strong>.</p><p>When a switch receives a frame with a broadcast address, it sends the frame through all its port except through the incoming one, idem as in MAC learning.</p><p>However, broadcast <strong>should not be overused</strong> as it can cause <strong>buffer overflows</strong>. It is a limiting factor because it generates traffic in the reception of all the ports of the switch.</p><h4 id="6-redundancy">6. Redundancy</h4><p>One of the limitations of the MAC learning algorithm is that it generates <strong>transmission loops</strong> in redundant physical topologies.</p><p>A redundant topology provides several paths for connecting a source with a destination. It might be interesting for providing a reliable switching service; in case a path is unavailable, we can use another one.</p><h4 id="spanning-trees">Spanning Trees</h4><p>A solution for fixing L2 switching loops is to generate a logical tree. These logical trees are called &#x201C;<strong>spanning trees</strong>&#x201D; and they avoid possible switching loops.</p><p>A protocol called <strong>Spanning Tree Protocol (STP)</strong> is used to dynamically build the spanning tree.</p><p>If switching path becomes unavailable, the STP dynamically generates another spanning tree.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/1*9qcj7uAhpLr70970kMedOA.png" class="kg-image" alt="Internet Educational Series #1: Ethernet, Switching &amp; VLANs" loading="lazy" width="362" height="344"><figcaption><span style="white-space: pre-wrap;">Spanning Trees</span></figcaption></figure><h4 id="7-final-remarks">7. Final Remarks</h4><p>Modern switches use several physical signals to auto-negotiate certain aspects of the communication.</p><ul><li>A physical signal allows a station to automatically detect if the device is a switch or a hub.</li><li>In connections between switches, physical signals allow switches to detect each other and negotiate which one is going to be the <strong>null modem port</strong>.</li><li>Stations and switches also negotiate <strong>transmission rates</strong>.</li><li>The standard of Ethernet at 100Mbps is called &#x201C;Fast Ethernet&#x201D;.</li><li>In Fast Ethernet a pair of twisted wires is used for each direction.</li></ul><hr><p>Well, we are getting to the end of this article. I hope you found what you were looking for, and wish that you now have a better understanding of Ethernet protocols, and how do we connect networks using switches.</p><p>This is just the first episode of a complete series that will guide you through the <strong>Internet Basics</strong>, so in case you want to improve your digital knowledge, and have a solid understanding of <strong>how does the internet work</strong>, keep tuned in to my profile as I&#x2019;ll keep posting articles about this topics.</p><hr><p><strong>Leave a clap if you enjoyed this post, you&#x2019;ll support my work and help me keep myself motivated to write more! Knowledge is power!</strong></p>]]></content:encoded></item><item><title><![CDATA[Bitcoin & Blockchain. How do they work?]]></title><description><![CDATA[A technical explanation for those who want to dive deeper into this Blockchain thing.]]></description><link>https://blog.lares21.xyz/bitcoin-blockchain/</link><guid isPermaLink="false">665ee4afd242c72c9151c1a8</guid><dc:creator><![CDATA[Markush]]></dc:creator><pubDate>Mon, 25 Jan 2021 14:24:47 GMT</pubDate><media:content url="https://cdn-images-1.medium.com/max/800/0*57VDkwQnOXvCeV63" medium="image"/><content:encoded><![CDATA[<h3 id="why-is-bitcoin%E2%80%99s-blockchain-decentralized">Why is Bitcoin&#x2019;s blockchain decentralized?</h3><img src="https://cdn-images-1.medium.com/max/800/0*57VDkwQnOXvCeV63" alt="Bitcoin &amp; Blockchain. How do they work?"><p><em>Dear reader, before you read this article I want you to know this is not financial advice. Do your own research before investing your money. This is an educational intended article. I&#x2019;m just explaining what I wish someone had told me before I started the Cryptocurrencies journey.</em></p><p>I guess if you&#x2019;ve landed over here you do already know what Bitcoin is, but you do not fully get how does it work, so stop worrying, you are in the right place!</p><p>First of all I&#x2019;ll make an introduction about Blockchain Technology, and later on I&#x2019;ll explain how does Bitcoin implement this Technology.</p><p>Blockchain is nothing more than a <strong>specific type of database</strong> (I assume you do know what a database is), but its main difference with traditional databases is the way it stores and structures data.</p><p>A Blockchain, stores its data in groups, also known as blocks. These blocks do have a limit of storage, and when they are filled, they get chained onto the previous block, forming a chain known as a <strong>blockchain</strong>. Each one of this blocks, when it joins the blockchain, is given an <strong>exact timestamp</strong>.</p><p>The interesting part about this specific type of databases is that it operates inside a network of computers. Before each block is chained, it needs to be approved by the majority of the computers that form the network, this way the network can prevent malicious information being added to the chain.</p><p>If we talk about Bitcoin, each block stores <strong>transactions</strong> which go from point A to point B. That is basically Bitcoin, <strong>a public network which stores a database of transactions.</strong></p><p>Regarding other cryptocurrencies, their blockchains can store things like legal contracts, inventories and others, but Bitcoin stores transactions.</p><p>But let&#x2019;s dive a little deeper into <strong>Bitcoin&#x2019;s blockchain</strong>.</p><p>The purpose of Bitcoin is to provide a Decentralized, Transparent and Trustworthy way of transferring and storing money.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/0*nCyyax-nlxYq3X9s" class="kg-image" alt="Bitcoin &amp; Blockchain. How do they work?" loading="lazy" width="6646" height="4430"><figcaption>Photo by <a href="https://unsplash.com/@nasa?utm_source=medium&amp;utm_medium=referral" data-href="https://unsplash.com/@nasa?utm_source=medium&amp;utm_medium=referral" class="markup--anchor markup--figure-anchor" rel="photo-creator noopener" target="_blank">NASA</a> on&#xA0;<a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral" data-href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral" class="markup--anchor markup--figure-anchor" rel="photo-source noopener" target="_blank">Unsplash</a></figcaption></figure><p>Let&#x2019;s start with the <strong>decentralization</strong> part:</p><p>As I said, Bitcoin is just a specific type of database that stores every Bitcoin transaction ever made. This database is distributed between a large set of computers, and these computers aren&#x2019;t usually managed by the same person or group of people. This way, we do have the blockchain distributed in different geographic locations around the world. And the fun part is that as the Bitcoin protocol is open source, ANYONE who wants to contribute to the Bitcoin blockchain can do it just by running their own node in their computer!</p><p>Apart from contributing to the network, if you run a node you can have your own wallet there, which is kinda cool!</p><p>A node is just another point of the network, where all the network transactions get stored and verified. If one node has an error in its data it can use the thousands of other nodes as a reference point to correct itself. This way, no one node within the network can alter information held within it. Because of this, the history of transactions in each block that make up Bitcoin&#x2019;s blockchain is <strong>irreversible</strong>.</p><p>If one user want to change the data stored in one transaction, all other nodes will just automatically say &#x201C;Hey! That&#x2019;s not what it says in my data&#x201D;, and the malicious activity will get discarded.</p><p>This ensures that the whole blockchain acts in the interest of the majority.</p><p>Once you understand the decentralized nature of Bitcoin , it&#x2019;s much easier to understand its <strong>transparency</strong>. Each node stores a copy of all the information that has ever gone through the blockchain, so anyone running a node can see the source and destination of the transactions, and this way they can be easily tracked.</p><p>Also you can make use of websites that track blockchain transactions in case you do not run a node.</p><p>This brings us to question ourselves why governments are talking about Bitcoin being the &#x201C;criminals money&#x201D;, if transactions can be easily tracked, but we won&#x2019;t cover this topic in this article.</p><p>Alright, we are heading to the last part. Why is Blockchain Technology secure?</p><p>Let&#x2019;s think on <em>how does the blockchain add their blocks to the chain</em>.</p><p>New blocks are stored linearly and chronologically, so they are added at the &#x201C;end&#x201D; of the chain. This means that it&#x2019;s really difficult to go back to a previous block than the last one and alter its data, unless a general consensus is reached.</p><p>The difficulty lies in how blocks are stored with a unique identifier. This unique identifier is called a <strong>hash</strong>.</p><p>Hashes are mathematical functions that turns digital information into a random string of numbers and letters. If the information inside the hash changes, the hash itself gets changed too.</p><p>Let&#x2019;s put an example to understand <em>why that&#x2019;s important to security</em>:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/0*bIm1AGK6qejtcjrr" class="kg-image" alt="Bitcoin &amp; Blockchain. How do they work?" loading="lazy" width="6000" height="4000"><figcaption>Photo by <a href="https://unsplash.com/@tar1k?utm_source=medium&amp;utm_medium=referral" data-href="https://unsplash.com/@tar1k?utm_source=medium&amp;utm_medium=referral" class="markup--anchor markup--figure-anchor" rel="photo-creator noopener" target="_blank">Tarik Haiga</a> on&#xA0;<a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral" data-href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral" class="markup--anchor markup--figure-anchor" rel="photo-source noopener" target="_blank">Unsplash</a></figcaption></figure><p>Imagine someone wants to alter the data stored inside a block, to move a transaction destination to their own wallet. Once all the other nodes from the network compare their hash to the one that has been altered, they would see a hash standing out from all the other ones, and the network would automatically discard the transaction that altered it.</p><p>The only way to succeed with such a hack would be to control the 51% of the nodes of the network, and here comes a really interesting insight.</p><p>Everything can be hacked in some way or another. The only way to prevent something being hacked, is to make that hack a nonsense.</p><p>Once someone hacks the 51% of the network, thanks to it being public, the remaining 49% will be able to see it, and as you know, if no one wants the 49% of the network, that network stops having a real value, and so forth, the hacker will own a 51% of a non-valuable network.</p><p>Apart, the hacker would have to spend HUGE amounts of time and energy (and so forth, money) to change a single transaction. Here is were we find an explanation on <strong>WHY Bitcoin does not use PoS</strong>. But that&#x2019;s another story. In case you are interested in it, contact me and we can discuss further about <strong>PoW vs PoS.</strong></p><h4 id="blockchain-bitcoin-history">Blockchain &amp; Bitcoin history:</h4><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://cdn-images-1.medium.com/max/800/0*0KsP_0FHht-X4Ov2" class="kg-image" alt="Bitcoin &amp; Blockchain. How do they work?" loading="lazy" width="4608" height="3072"><figcaption>Photo by <a href="https://unsplash.com/@ewankennedy19?utm_source=medium&amp;utm_medium=referral" data-href="https://unsplash.com/@ewankennedy19?utm_source=medium&amp;utm_medium=referral" class="markup--anchor markup--figure-anchor" rel="photo-creator noopener" target="_blank">Ewan Kennedy</a> on&#xA0;<a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral" data-href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral" class="markup--anchor markup--figure-anchor" rel="photo-source noopener" target="_blank">Unsplash</a></figcaption></figure><p>Blockchain even if it doesn&#x2019;t seem so, was invented around 1990s, but it wasn&#x2019;t until 2009 that it found it&#x2019;s first real-world application: Bitcoin, created originally by Satoshi Nakamoto, who <em>no one still knows who he is</em>.</p><p>And this first blockchain application was designed to work as Satoshi said: &#x201C;a new electronic cash system that&#x2019;s fully peer-to-peer, with no trusted third party.&#x201D;</p><p>But as you now know, blockchain can be used in many different ways, not only implementing money system payments, but also election records, logistic procedures, legal transactions, and many more that are yet to be discovered.</p><p>Woooah this is getting to an end, and all that information was hard to digest, I know, but I hope you do better understand now how does Blockchain Technology and Bitcoin transactions work.</p><hr><p>I hope you liked this article, I just want to say thank you if you reached this far!</p><p>Make sure to leave a &#x2018;Clap&#x2019; if you enjoyed this article, it supports my work and helps keep myself motivated to write more articles!</p><p>Thanks for reading!</p><hr><h3 id="read-my-other-articles">Read my other articles!</h3><ul><li><a href="https://aka-kush.medium.com/what-is-bitcoin-3bc8d9a27f17?ref=blog.lares21.xyz" rel="noopener">What is Bitcoin?</a></li><li><a href="https://aka-kush.medium.com/best-cryptocurrency-exchange-d9a209f7659f?ref=blog.lares21.xyz" rel="noopener">How to Choose the Best Cryptocurrency Exchange of 2021?</a></li></ul>]]></content:encoded></item></channel></rss>