<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Tailscale – Yeri Tiete</title><link>https://yeri.be/tag/tailscale/</link><description>Yeri Tiete's blog</description><language>en</language><copyright>© Yeri Tiete</copyright><lastBuildDate>Sat, 09 Jul 2022 23:14:54 +0200</lastBuildDate><atom:link href="https://yeri.be/tag/tailscale/index.xml" rel="self" type="application/rss+xml"/><item><title>Remote desktop and Wake-on-LAN</title><link>https://yeri.be/remote-desktop-and-wake-on-lan/</link><pubDate>Sat, 09 Jul 2022 23:14:54 +0200</pubDate><author>Yeri Tiete</author><guid isPermaLink="true">https://yeri.be/remote-desktop-and-wake-on-lan/</guid><description>&lt;p&gt;&lt;a href="http://shanwong.com" target="_blank" rel="noreferrer noopener"&gt;Shan&lt;/a&gt; uses her iPad a lot, but a lot of the more serious (interior design) work needs to happen on &lt;a href="https://yeri.be/screen-going-black-with-autocad-lt"&gt;AutoCAD&lt;/a&gt; or Photoshop. That is just not going to work on an iPad. &lt;/p&gt;
&lt;p&gt;When we're travelling (read: holiday) she's carrying an old Lenovo &lt;a href="https://www.lenovo.com/gb/en/laptops/thinkpad/13-series/ThinkPad-13-Windows-2nd-Gen/p/22TP2TX133E" target="_blank" rel="noreferrer noopener"&gt;ThinkPad 13&lt;/a&gt; (great device!) just "in case" she needs to open AutoCAD and edit something minor or read the drawings/dimensions. But honestly, most of the time that device is turned off and dead weight.&lt;/p&gt;</description><content:encoded><![CDATA[<p><a href="http://shanwong.com" target="_blank" rel="noreferrer noopener">Shan</a> uses her iPad a lot, but a lot of the more serious (interior design) work needs to happen on <a href="https://yeri.be/screen-going-black-with-autocad-lt">AutoCAD</a> or Photoshop. That is just not going to work on an iPad. </p>
<p>When we're travelling (read: holiday) she's carrying an old Lenovo <a href="https://www.lenovo.com/gb/en/laptops/thinkpad/13-series/ThinkPad-13-Windows-2nd-Gen/p/22TP2TX133E" target="_blank" rel="noreferrer noopener">ThinkPad 13</a> (great device!) just "in case" she needs to open AutoCAD and edit something minor or read the drawings/dimensions. But honestly, most of the time that device is turned off and dead weight.</p>
<p>But all the above is just an excuse to "I was bored, and I wanted to test something": can I use an old Raspberry Pi (<a href="https://www.raspberrypi.com/products/raspberry-pi-zero-w/" target="_blank" rel="noreferrer noopener">zero W</a>) to remotely wake her Intel NUC, and then use <a href="http://tailscale.com/" target="_blank" rel="noreferrer noopener">Tailscale</a> to use RD on her iPad? Well, yes I can. </p>
<p>I completed this using:</p>
<ul><li>Tailscale to remote desktop from anywhere to home</li><li>Cloudflare Tunnels, Access and DNS to have a web interface to wake the desktop</li><li>A Linux device that's always on and in the same LAN, and that'll run a PHP script. </li></ul>
<h2>Prep work: enable WOL</h2>
<p>First off: enable Wake-on-LAN (WOL) in the BIOS <em>and </em>in your Windows settings. <a href="https://www.intel.com/content/www/us/en/support/articles/000027615/intel-nuc.html" target="_blank" rel="noreferrer noopener">This article explains</a> it for Intel NUCs, but would be similar enough for most devices. The Device Manager pane looked different on our i5 NUC, but was close enough. </p>
<p>On Mac, you just need to enable it in the Energy preference pane, for Linux I have no clue. 🤷‍♂️</p>
<p>Second step: have a working Raspberry Pi (or any Linux device) in <em>the same LAN</em>. This device needs to be turned on 24/7, so use something that uses very little power. </p>
<pre class="wp-block-verse">I do have a more powerful <a href="https://yeri.be/making-bluetooth-work-on-rpi4">RPi4</a> I wish I could've reused (running <a href="https://yeri.be/running-wireguard-in-a-docker-container-rpi">Docker</a> and some other "serious" stuff; however it's currently in a different VLAN, and it's quite crucial the Linux device is in the same LAN as the device(s) you want to wake up), so I went with an old Raspberry Pi Zero W that was collecting dust (it used to run <a href="https://pwnagotchi.ai/" target="_blank" rel="noreferrer noopener">pwnagotchi</a>).</pre>
<p>On the Linux device, install <a href="https://www.mkssoftware.com/docs/man1/etherwake.1.asp" target="_blank" rel="noreferrer noopener">etherwake</a>. The command to run is quite simply <code>etherwake aa:bb:cc:11:22:33</code> (= the ethernet MAC address of your device).</p>
<p>If this doesn't wake your desktop, something is wrong and there's no point continuing. Go and troubleshoot. </p>
<h2>Install Tailscale and RD</h2>
<p>On the (<a href="https://www.youtube.com/watch?v=lKQroybFqg4" target="_blank" rel="noreferrer noopener">Windows</a>) desktop and your iPad, install <a href="https://tailscale.com/download" target="_blank" rel="noreferrer noopener">Tailscale</a>. Login, and make sure it works by pinging from one to the other. </p>
<p>Then set up Remote Desktop on both (<a href="https://support.microsoft.com/en-us/windows/how-to-use-remote-desktop-5fe128d5-8fb1-7a23-3b8a-41e636865e8c#ID0EDD=Windows_10" target="_blank" rel="noreferrer noopener">Windows</a>, <a href="https://apps.apple.com/us/app/remote-desktop-mobile/id714464092" target="_blank" rel="noreferrer noopener">iPad</a>). You should test and make sure you can properly connect using the LAN IP address and then the Tailscale IP address.</p>
<pre class="wp-block-verse">Fun fact: I create a DNS record for all my devices using <a href="https://developers.cloudflare.com/dns/manage-dns-records/how-to/create-dns-records/" target="_blank" rel="noreferrer noopener">Cloudflare DNS</a> with the syntax of <a href="https://smokeping-sg.superuser.one/smokeping/?target=yeri.TSwol" target="_blank" rel="noreferrer noopener">device-name.ts.yeri.be</a>, so I don't need to ever remember IPs, and can easily <code>ssh</code> or <code>ping</code> devices without having to look up IPs. </pre>
<figure class="wp-block-image size-large is-resized"><img src="https://static.yeri.be/2022/07/cf-dns-ts-1024x461.png" alt="" class="wp-image-70039" width="610" height="274"/><figcaption>Cloudflare DNS screenshot, filtered on "ts". I add both <code>A</code> and <code>AAAA</code> records (not shown in the screenshot) </figcaption></figure>
<pre class="wp-block-verse">Fun fact side track: I actually have a dynamic script that runs (on Linux) and creates <code>hostname.ts.yeri.be</code> for the Tailscale IP, <code>hostname.wg.yeri.be</code> based on the <a href="https://yeri.be/wireguard" target="_blank" rel="noreferrer noopener">Wireguard</a> IP, <code>hostname.lan.yeri.be</code> based on the LAN IP. This dyndns script runs every so often and updates IPs if needed. All this is running using <a href="https://github.com/tech-otaku/cloudflare-dns" target="_blank" rel="noreferrer noopener">Cloudflare DNS and their API</a>. Super convenient.</pre>
<h2>Nginx, php and etherwake</h2>
<pre class="wp-block-verse">I'm a 80s kid, so I'll use dirty PHP to run this script. I'm sure I'll go straight to hell for this, but yolo.</pre>
<p>Install <a href="https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04" target="_blank" rel="noreferrer noopener">nginx and PHP</a> (no need for MySQL and other stuff).</p>
<p><code>etherwake</code> requires root to run (because it needs root access to create a weird <a href="https://en.wikipedia.org/wiki/Wake-on-LAN#Magic_packet" target="_blank" rel="noreferrer noopener">magic</a> ethernet packet). Create a file in <code>/etc/sudoers.d/etherwake</code> and add this line:</p>
<pre class="wp-block-code"><code>www-data ALL=(ALL) NOPASSWD: /usr/sbin/etherwake</code></pre>
<p>This will allow <code>www-data</code> (nginx/php) to run <code>/usr/sbin/etherwake</code> using <code>sudo</code>, without password.</p>
<p>In <code>/var/www/html/</code> create an <code>index.php</code> file with:</p>
<pre class="wp-block-code"><code>&lt;html&gt;
&lt;head&gt;&lt;title&gt;Wake on Lan&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;Wake up &lt;a href="mycooldesktop.php"&gt;My Cool Desktop&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
<p>And a <code>mycooldesktop.php</code> (or whatever) file with:</p>
<pre class="wp-block-code"><code>&lt;?php
$output = shell_exec('sudo /usr/sbin/etherwake aa:bb:cc:11:22:33 2&gt;&amp;1');
echo "&lt;pre&gt;$output&lt;/pre&gt;";
?&gt;
&lt;p&gt;&lt;a href=".."&gt;Back&lt;/a&gt;&lt;/p&gt;</code></pre>
<pre class="wp-block-verse">It ain't pretty -- but it gets the job done. </pre>
<p>And be sure to edit the MAC address to match your desktop's ethernet MAC address. </p>
<h2>Cloudflare tunnels</h2>
<p>Install Cloudflare Tunnel (via <a href="https://dash.teams.cloudflare.com" target="_blank" rel="noreferrer noopener">Zero Trust</a> dashboard). </p>
<p>When creating a new tunnel, the dashboard will give you all needed commands to install the tunnel on your RPi -- but be sure to select the right OS/architecture (arm64? arm? armhf?). </p>
<figure class="wp-block-image size-large"><img src="https://static.yeri.be/2022/07/cf-tunnel-1024x448.png" alt="" class="wp-image-70047"/><figcaption>Easy.</figcaption></figure>
<p>And then point the tunnel to <code>http://localhost</code>. No need to mess around with <a href="https://yeri.be/tag/ssl">SSL</a> certs.</p>
<p>Lastly, set up Cloudflare Access (via the same Zero Trust dashboard): create a new application, and make sure only approved users can sign in (i.e.: using a pin code emailed to only approved emails). </p>
<figure class="wp-block-image size-large"><img src="https://static.yeri.be/2022/07/cf-access-1024x796.png" alt="" class="wp-image-70048"/><figcaption>I only allow access to my own emails, and my family, by using groups.</figcaption></figure>
<p>You can try it yourself via <a href="https://wol.superuser.one/" target="_blank" rel="noreferrer noopener">wol.superuser.one</a>. You won't get in. :)</p>
<pre class="wp-block-verse">Optionally, but recommended: lock down Nginx to only allow connections from localhost (<code>127.0.0.0/8</code> and <code>::1</code>) if using Cloudflare Tunnels, or <a href="https://www.frankindev.com/2020/11/18/allow-cloudflare-only-in-nginx/" target="_blank" rel="noreferrer noopener">Cloudflare IPs</a> if using port forwarding with <a href="https://www.cloudflare.com/en-gb/products/zero-trust/access/" target="_blank" rel="noreferrer noopener">Cloudflare Access</a> in front. </pre>
<figure class="wp-block-image size-large is-resized"><img src="https://static.yeri.be/2022/07/wol-interface-1024x540.png" alt="" class="wp-image-70042" width="610" height="321"/><figcaption>Love my design skills... But it gets the job done: click that link, and it'll execute <code>etherwake</code>.</figcaption></figure>
<h2>To recap</h2>
<ul><li>We used Tailscale to create a VPN network between the desktop and the iPad. The big benefit is that Tailscale works effortlessly across NAT networks without having to open ports,</li><li>We used Cloudflare DNS so we don't need to remember hostnames :),</li><li>We used Cloudflare Tunnels to make sure the RPi web interface is accessible across NAT (without port forwarding) and from anywhere, </li><li>We used Cloudflare Acces and locked down access to the right people using ACLs,</li><li>We used <code>etherwake</code> running on a RPi to wake up devices that are hibernating or turned off.</li></ul>
<p>And that's it really.</p>
<pre class="wp-block-verse">PS: technically WoL works with WiFi, but when I enabled WoL on the WiFi adapter, the NUC refused to hibernate/sleep for more than a minute, and kept waking itself up. So, there seems to be some kind of trigger in my network that keeps waking it up. Also, not sure if WoL via WiFi would work if the device is turned off (as opposed to sleep or hibernate). I just ended up using ethernet. 

PPS: both Cloudflare Tunnels and Tailscale use <a href="https://www.wireguard.com/" target="_blank" rel="noreferrer noopener">Wireguard</a> tech in the background, so that's really cool. </pre>
]]></content:encoded><category>Apple</category><category>Hardware</category><category>Linux</category><category>Misc</category><category>Networking</category><category>Software</category><category>Windows</category><category>www</category><category>Windows</category><category>cloudflare</category><category>tailscale</category><category>vpn</category></item></channel></rss>