<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
      <title>~&#x2F;magostinelli - iptables</title>
      <link>https://www.agostinelli.eu</link>
      <description>La casa delle mie passioni</description>
      <generator>Zola</generator>
      <language>it</language>
      <atom:link href="https://www.agostinelli.eu/tags/iptables/rss.xml" rel="self" type="application/rss+xml"/>
      <lastBuildDate>Wed, 14 Feb 2024 00:00:00 +0000</lastBuildDate>
      <item>
          <title>Come bloccare la pubblicità sullo smartphone </title>
          <pubDate>Sat, 10 Feb 2024 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://www.agostinelli.eu/blog/come-bloccare-la-pubblicita-sullo-smartphone/</link>
          <guid>https://www.agostinelli.eu/blog/come-bloccare-la-pubblicita-sullo-smartphone/</guid>
          <description xml:base="https://www.agostinelli.eu/blog/come-bloccare-la-pubblicita-sullo-smartphone/">&lt;p&gt;&lt;strong&gt;Aggiornamento 14&#x2F;02&#x2F;2024&lt;&#x2F;strong&gt;: aggiungo in fondo all&#x27;articolo le modifiche necessarie per la parte server.&lt;&#x2F;p&gt;
&lt;p&gt;Questo metodo lo utilizzo ormai da svariati mesi e &lt;strong&gt;funziona benissimo&lt;&#x2F;strong&gt;!&lt;&#x2F;p&gt;
&lt;p&gt;Premetto subito che non è una semplice soluzione adatta per tutti, poiché richiede un server #wireguard e un&#x27;installazione di #pihole.
Però se avete un amico che ha già configurato tutto per se, sarà molto semplice farlo usare anche a voi! E&#x27; complessa la configurazione server, mentre la &lt;strong&gt;parte client è semplicissima&lt;&#x2F;strong&gt;: scaricare un&#x27;app e scansionare un qr code.&lt;&#x2F;p&gt;
&lt;p&gt;Abbiamo visto la configurazione di entrambi su questo blog (cliccate sui due hashtag per le leggere le guide).&lt;&#x2F;p&gt;
&lt;p&gt;Con questo metodo non solo bloccherete le pubblicità invasive sul browser, ma &lt;strong&gt;su tutte le app&lt;&#x2F;strong&gt;!
Inoltre oltre al blocco pubblicità avrete anche il &lt;strong&gt;blocco dei siti malevoli&lt;&#x2F;strong&gt; (in base alle liste che avete deciso di aggiungere a pihole).&lt;&#x2F;p&gt;
&lt;p&gt;Il trucco è usare la vpn per fare in modo che lo smartphone navighi nello stessa modalità che avviene da casa, cioè protetto da pihole!&lt;&#x2F;p&gt;
&lt;p&gt;Abbiamo due diverse modalità di uso per la vpn:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;usarla solo per la risoluzione dns&lt;&#x2F;li&gt;
&lt;li&gt;usarla per tutto il traffico&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;L&#x27;una non esclude l&#x27;altra, cioè possiamo fare due profili diversi e passare da uno all&#x27;altro in base alle necessità (ad esempio se ci connettiamo un WiFi pubblico non protetto, conviene usare la seconda opzione).
La prima soluzione ha il vantaggio di consumare pochissima banda per il server, solo lo stretto necessario per le risoluzioni dns.&lt;&#x2F;p&gt;
&lt;p&gt;Esempio di configurazione solo dns:&lt;&#x2F;p&gt;
&lt;pre class=&quot;z-code&quot;&gt;&lt;code&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;[Interface]
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PrivateKey = chiave_priv_client1
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;Address = 192.168.20.2&#x2F;24
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;Dns = ip_vpn_privato_server
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;[Peer]
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PublicKey = chiave_pub_server
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PresharedKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;AllowedIPs = ip_vpn_privato_server&#x2F;32
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;Endpoint = hostname_pubblico_server:porta
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Esempio di configurazione traffico completo:&lt;&#x2F;p&gt;
&lt;pre class=&quot;z-code&quot;&gt;&lt;code&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;[Interface]
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PrivateKey = chiave_priv_client1
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;Address = 192.168.20.2&#x2F;24
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;Dns = ip_vpn_privato_server
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;[Peer]
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PublicKey = chiave_pub_server
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PresharedKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;AllowedIPs  = 0.0.0.0&#x2F;0, ::&#x2F;0
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;Endpoint = hostname_pubblico_server:porta
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Vi consiglio di usare questo client per wireguard &lt;strong&gt;wg-tunnel&lt;&#x2F;strong&gt;, perché ha una funzionalità fondamentale per il nostro scopo: è in grado di &lt;strong&gt;attivare automaticamente la vpn&lt;&#x2F;strong&gt; quando ci disconnettiamo dalla nostra wifi (è possibile scegliere più reti fidate).&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;img.agostinelli.eu&#x2F;2024&#x2F;wg-tunnel_logo.png&quot; alt=&quot;Wg tunnel Logo&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;img.agostinelli.eu&#x2F;2024&#x2F;wg-tunnel_screen1.png&quot; alt=&quot;Wg tunnel Screen 1&quot; &#x2F;&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;img.agostinelli.eu&#x2F;2024&#x2F;wg-tunnel_screen2.png&quot; alt=&quot;Wg tunnel Screen 2&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Non ho provato questa soluzione su iPhone, ma presumo che possa funzionare anche lì.&lt;&#x2F;p&gt;
&lt;p&gt;Infine vi consiglio anche un&#x27;ottimo client #android per gestire pihole: Pi-hole Droid.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;aggiornamento-14-12-2024&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#aggiornamento-14-12-2024&quot; aria-label=&quot;Anchor link for: aggiornamento-14-12-2024&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Aggiornamento 14&#x2F;12&#x2F;2024&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;modifiche-configurazione-server&quot;&gt;&lt;a class=&quot;header-anchor no-hover-padding&quot; href=&quot;#modifiche-configurazione-server&quot; aria-label=&quot;Anchor link for: modifiche-configurazione-server&quot;&gt;&lt;span class=&quot;link-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
Modifiche configurazione server&lt;&#x2F;h3&gt;
&lt;p&gt;Affinchè il server sia in grado di ruotare i pacchetti ricevuti dalla VPN è necessaria qualche configurazione in più, dei comandi &lt;em&gt;&quot;standard&quot;&lt;&#x2F;em&gt; #iptables per gli addetti ai lavori.
(su iptables trovate  ampia documentazione on line)
Ma veniamo al dunque&lt;&#x2F;p&gt;
&lt;p&gt;Esempio di righe in aggiunta alla parte server:&lt;&#x2F;p&gt;
&lt;pre class=&quot;z-code&quot;&gt;&lt;code&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PostUp = iptables -A FORWARD -i %i -j ACCEPT
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PostUp = iptables -A FORWARD -o %i -j ACCEPT
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;# DNS - sostituire 192.168.1.x con ip del proprio pihole
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PostUp = iptables -I FORWARD -i %i -p udp -m udp -d 192.168.1.x&#x2F;32 --dport 53 -j ACCEPT
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PostUp = iptables -I FORWARD -i %i -p tcp -m tcp -d 192.168.1.x&#x2F;32 --dport 53 -j ACCEPT
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;# Blocco rete locale per tutti (nell&amp;#39;esempio è con subnet 192.168.1.0)
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PostUp = iptables -I FORWARD -i %i -d 192.168.1.0&#x2F;24 -j REJECT
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;# Apertura rete locale ad un singolo ip
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PostUp = iptables -I FORWARD -i %i -s 172.16.2.2&#x2F;32 -d 192.168.1.0&#x2F;24 -j ACCEPT
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PostDown = iptables -D FORWARD -i %i -j ACCEPT
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PostDown = iptables -D FORWARD -o %i -j ACCEPT
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
&lt;&#x2F;span&gt;&lt;span class=&quot;z-text z-plain&quot;&gt;...
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</description>
      </item>
    </channel>
</rss>
