<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mehdi mFat</title>
    <description>The latest articles on DEV Community by Mehdi mFat (@mfat).</description>
    <link>https://dev.to/mfat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F820843%2Fe4fa2570-4f2b-4c92-85a5-fc0f52c16ae4.png</url>
      <title>DEV Community: Mehdi mFat</title>
      <link>https://dev.to/mfat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mfat"/>
    <language>en</language>
    <item>
      <title>Local port forwarding using shadowsocks-rust + openvpn over shadowsocks</title>
      <dc:creator>Mehdi mFat</dc:creator>
      <pubDate>Fri, 08 Sep 2023 22:58:16 +0000</pubDate>
      <link>https://dev.to/mfat/local-port-forwarding-using-shadowsocks-rust-openvpn-over-shadowsocks-14i7</link>
      <guid>https://dev.to/mfat/local-port-forwarding-using-shadowsocks-rust-openvpn-over-shadowsocks-14i7</guid>
      <description>&lt;h2&gt;
  
  
  How to forward local port using shadowsocks
&lt;/h2&gt;

&lt;p&gt;The purpose here is to forward local port 3080 to remote port 2.2.2.2:1194 (where an openvpn server is listening) using shadowsocks. &lt;/p&gt;

&lt;p&gt;To do this we'll use &lt;a href="https://github.com/shadowsocks/shadowsocks-rust"&gt;shadowsocks-rust&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;First we download the latest binaries for linux:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://github.com/shadowsocks/shadowsocks-rust/releases/download/v1.16.1/shadowsocks-v1.16.1.x86_64-unknown-linux-gnu.tar.xz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and extract the files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir shadowsocks
tar xvf shadowsocks-v1.16.1.x86_64-unknown-linux-gnu.tar.xz -C shadowsocks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we cd into the folder and make the binaries executable and move them to /usr/local/bin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd shadowsocks/
chmod +x ss*
sudo mv ss* /usr/local/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify installation using this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sslocal --version

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are ready to create our local tunnel.&lt;/p&gt;

&lt;p&gt;To do this we obviously need a shadowsocks server. There are many tutorials for setting up one. However here is how you can quickly set up a shadowsocks server on a debian/ubuntu VPS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install shadowsocks-libev simple-obfs

sudo nano /etc/shadowsocks-libev/config.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
   "server": "0.0.0.0",
   "server_port": DESIRED PORT,
   "password": "DESIRED PASSWORD",
   "timeout": 300,
   "method": "chacha20-ietf-poly1305",
   "mode": "tcp_only",
   "dns":"1.1.1.1",
   "plugin":"obfs-server",
   "plugin_opts": "obfs=http;obfs-host=cloudfront.net",
   "fast_open": false
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;(Please note simple-obfs is obsolete and you should consider using a more secure pluging such as xray.)&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart shadowsocks-libev.service

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now back to our local system, we create a shadowsocks tunnel configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano sstunnel.json

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and paste these lines. Make necessary adjustments based on your shadowsocks server configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
"locals": [
{
            "protocol": "tunnel",

            "local_address": "127.0.0.1",
            "local_port": 3080,
            "forward_address":"2.2.2.2",
            "forward_port": 1194,

}
],
            "server": "SHADOWSOCKS_SERVER_IP",
            "server_port": SHADOWSOCKS_SERVER_PORT,
            "password": "SHADOWSOCKS_SERVER_PASSWORD",
            "method": "chacha20-ietf-poly1305",
            "mode": "tcp_only",
            "plugin": "obfs-local",
            "plugin_opts": "obfs=http;obfs-host=cloudfront.net"

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file tells shadowsocks to forward connections to 127.0.0.1:3080 to the remote port 2.2.2.2:1194 which is our openvpn server, for example.&lt;/p&gt;

&lt;p&gt;Now we can run the tunnel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/usr/local/bin/sslocal -c sstunnel.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the output on my system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ /usr/local/bin/sslocal -c sstest.json 
2023-09-09T02:08:53.356339957+03:30 INFO  shadowsocks local 1.16.1 build 2023-09-01T05:08:00.031376835+00:00
 2023-09-09 02:08:53 [simple-obfs] INFO: obfuscating enabled
 2023-09-09 02:08:53 [simple-obfs] INFO: obfuscation http method: GET
 2023-09-09 02:08:53 [simple-obfs] INFO: obfuscating hostname: cloudfront.net
 2023-09-09 02:08:53 [simple-obfs] INFO: tcp port reuse enabled
 2023-09-09 02:08:53 [simple-obfs] INFO: listening at 127.0.0.1:41681
2023-09-09T02:08:53.357713632+03:30 INFO  shadowsocks TCP tunnel listening on 127.0.0.1:3080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see the last line &lt;br&gt;
&lt;code&gt;TCP tunnel listening on 127.0.0.1:3080&lt;/code&gt;&lt;br&gt;
shows sslocal is listening at port 3080.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to connect to openvpn over shadowsocks
&lt;/h2&gt;

&lt;p&gt;Now let's assume we have an client.ovpn file for connecting to our 2.2.2.2:1194 openvpn server.&lt;/p&gt;

&lt;p&gt;We open the client.ovpn file and make two changes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We change &lt;strong&gt;remote&lt;/strong&gt; line to 127.0.0.1 3080&lt;/li&gt;
&lt;li&gt;We also tell openvpn to route the shadowsocks server IP through default gateway, not through the vpn tunnel:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;route SHADOWSOCKS_SERVER_IP 255.255.255.255 net_gateway

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is how my openvpn client configuration looks now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;client
proto tcp-client
remote 127.0.0.1 3080
route SHADOWSOCKS_SERVER_IP 255.255.255.255 net_gateway
....
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The rest of the configuration file remains intact.&lt;/p&gt;

&lt;p&gt;Now I can connect to openvpn using this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo openvpn --config client.ovpn

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;P.S: instead of creating a shadowsocks tunnel configuration file we can also use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sslocal --protocol tunnel -b "127.0.0.1:3080" -f "2.2.2.2:1194"  --server-url "ss://...."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/usr/local/bin/sslocal --protocol tunnel -b "127.0.0.1:3080" -f "2.2.2.2:1194" -s "SHADOWSOCKS_SERVER_IP:PORT" -m "chacha20-ietf-poly1305" -k "SHADOWSOCKS_SERVER_PASSWORD" --plugin "obfs-local" --plugin-opts "obfs=http;obfs-host=cloudfront.net"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>openvpn</category>
      <category>shadowsocks</category>
      <category>portforwardng</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Tunnel any port over shadowsocks in openwrt using ss-tunnel</title>
      <dc:creator>Mehdi mFat</dc:creator>
      <pubDate>Sat, 02 Sep 2023 15:12:32 +0000</pubDate>
      <link>https://dev.to/mfat/tunnel-any-port-over-shadowsocks-in-linuxopenwrt-using-ss-tunnel-1i8b</link>
      <guid>https://dev.to/mfat/tunnel-any-port-over-shadowsocks-in-linuxopenwrt-using-ss-tunnel-1i8b</guid>
      <description>&lt;p&gt;When you install luci-app-shadowsocks-libev on openwrt, there is a mudule called ss-tunnel.&lt;/p&gt;

&lt;p&gt;SS-Tunnel is also part of any standard shadowsocks-libev or shadowsocks-rust installation in linux.&lt;/p&gt;

&lt;p&gt;But what does it do?&lt;/p&gt;

&lt;p&gt;SS-Tunnel can forward any local port over shadowsocks.&lt;/p&gt;

&lt;p&gt;For example if you have an openvpn server somewhere with ip address of 214.43.76.543 listening on port 1194, you can easily connect to it over shadowsocks by setting 214.43.76.543:1194 as tunnel address in ss-tunnel.&lt;/p&gt;

&lt;p&gt;Now if ss-tunnel is listening on local port 1085, you can use it as your remote server ip in your openvpn config like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;remote 127.0.0.1 1085
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is very useful if openvpn is blocked on your network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/cbeuw/Cloak" rel="noopener noreferrer"&gt;Cloak&lt;/a&gt; is another alternative. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa424ug0yku13wk3pwh0x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa424ug0yku13wk3pwh0x.png" alt="screenshot" width="800" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>shadowsocks</category>
      <category>vpn</category>
      <category>cloak</category>
      <category>openwrt</category>
    </item>
    <item>
      <title>How to use Cloudflare Warp as a socks proxy on your local computer</title>
      <dc:creator>Mehdi mFat</dc:creator>
      <pubDate>Thu, 31 Aug 2023 23:05:28 +0000</pubDate>
      <link>https://dev.to/mfat/how-to-use-cloudflare-warp-as-a-socks-proxy-on-your-local-computer-1675</link>
      <guid>https://dev.to/mfat/how-to-use-cloudflare-warp-as-a-socks-proxy-on-your-local-computer-1675</guid>
      <description>&lt;p&gt;Cloudflare Warp is a wonderful VPN. It's very fast and with the Plus account you can enjoy virtually unlimited traffic.&lt;/p&gt;

&lt;p&gt;One great thing about Warp is that you can run it in proxy mode. This is useful if you don't want your entire traffic to go through the Warp network.&lt;/p&gt;

&lt;p&gt;In order to use Cloudflare warp in socks proxy mode you can use &lt;a href="https://github.com/pufferffish/wireproxy"&gt;Wireproxy&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Wireproxy is a wireguard client that exposes itself as a socks5/http proxy or tunnels.&lt;/p&gt;

&lt;p&gt;There is a very handy &lt;a href="https://gitlab.com/fscarmen/warp"&gt;script&lt;/a&gt; to automatically install and configure Wireproxy with Cloudflare Warp on either a vps or your local machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget -N https://gitlab.com/fscarmen/warp/-/raw/main/api.sh &amp;amp;&amp;amp; bash api.sh [option]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just run and follow the steps. In the end you'll have a locally running socks proxy that you can use in your web browsers, Telegram and other apps.&lt;/p&gt;

&lt;p&gt;The default host:port is &lt;strong&gt;127.0.0.1:40000&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The script creates a systemd service for controlling wireproxy.&lt;/p&gt;

&lt;p&gt;To change Wireguard/warp parameters you can edit this files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano /etc/wireguard/proxy.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example you can change the dns to 162.159.36.1 (recommended) and modify the endpoint as well.&lt;/p&gt;

&lt;p&gt;To find a fast endpoint you can run &lt;a href="https://gitlab.com/Misaka-blog/warp-script/-/tree/main/files/warp-yxip"&gt;this script&lt;/a&gt; as root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget -N https://gitlab.com/Misaka-blog/warp-script/-/raw/main/files/warp-yxip/warp-yxip.sh &amp;amp;&amp;amp; bash warp-yxip.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you prefer to run warp in VPN mode instead of proxy mode, check out the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gitlab.com/Misaka-blog/warp-script"&gt;https://gitlab.com/Misaka-blog/warp-script&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;WGCF：&lt;a href="https://replit.com/@misaka-blog/wgcf-profile-generator"&gt;https://replit.com/@misaka-blog/wgcf-profile-generator&lt;/a&gt;&lt;br&gt;
WARP-GO：&lt;a href="https://replit.com/@misaka-blog/warpgo-profile-generator"&gt;https://replit.com/@misaka-blog/warpgo-profile-generator&lt;/a&gt;&lt;br&gt;
Sing-box：&lt;a href="https://replit.com/@misaka-blog/warpgo-sbfile-generator"&gt;https://replit.com/@misaka-blog/warpgo-sbfile-generator&lt;/a&gt;&lt;/p&gt;

</description>
      <category>wireguard</category>
      <category>warp</category>
      <category>vpn</category>
      <category>censorship</category>
    </item>
    <item>
      <title>How to bypass wireguard client for local network on openwrt</title>
      <dc:creator>Mehdi mFat</dc:creator>
      <pubDate>Sat, 19 Aug 2023 16:00:26 +0000</pubDate>
      <link>https://dev.to/mfat/how-to-bypass-wireguard-client-for-local-network-on-openwrt-2kig</link>
      <guid>https://dev.to/mfat/how-to-bypass-wireguard-client-for-local-network-on-openwrt-2kig</guid>
      <description>&lt;p&gt;Assuming your local network is 192.168.0.0/24, you should do this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nano /etc/config/network&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and add the following to your wireguard peer config section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        list allowed_ips '0.0.0.0/1'
        list allowed_ips '128.0.0.0/2'
        list allowed_ips '192.0.0.0/9'
        list allowed_ips '192.128.0.0/11'
        list allowed_ips '192.160.0.0/13'
        list allowed_ips '192.168.1.0/24'
        list allowed_ips '192.168.2.0/23'
        list allowed_ips '192.168.4.0/22'
        list allowed_ips '192.168.8.0/21'
        list allowed_ips '192.168.16.0/20'
        list allowed_ips '192.168.32.0/19'
        list allowed_ips '192.168.64.0/18'
        list allowed_ips '192.168.128.0/17'
        list allowed_ips '192.169.0.0/16'
        list allowed_ips '192.170.0.0/15'
        list allowed_ips '192.172.0.0/14'
        list allowed_ips '192.176.0.0/12'
        list allowed_ips '192.192.0.0/10'
        list allowed_ips '193.0.0.0/8'
        list allowed_ips '194.0.0.0/7'
        list allowed_ips '196.0.0.0/6'
        list allowed_ips '200.0.0.0/5'
        list allowed_ips '208.0.0.0/4'
        list allowed_ips '224.0.0.0/3'
        option route_allowed_ips '1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can calculate allowed IPs using the following calculators:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://krasovs.ky/2021/07/04/wireguard-allowed-ips.html"&gt;Wireguard's AllowedIPs calculator&lt;br&gt;
 by Savely Krasovsky's&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.procustodibus.com/blog/2021/03/wireguard-allowedips-calculator/"&gt;Pro Custodibus calculator&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to access a local service over the internet using bore</title>
      <dc:creator>Mehdi mFat</dc:creator>
      <pubDate>Tue, 30 May 2023 12:26:54 +0000</pubDate>
      <link>https://dev.to/mfat/how-to-access-a-local-service-over-the-internet-using-bore-n1j</link>
      <guid>https://dev.to/mfat/how-to-access-a-local-service-over-the-internet-using-bore-n1j</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/ekzhang/bore"&gt;Bore&lt;/a&gt; is a modern, simple TCP tunnel written in Rust that exposes local ports to a remote server, bypassing standard NAT connection firewalls. &lt;/p&gt;

&lt;p&gt;The advantage of Bore over some popular services such as &lt;a href="https://ngrok.com/"&gt;ngrok&lt;/a&gt; is that it can be hosted on your own server. The CLI is also very straightforward and intuitive.&lt;/p&gt;

&lt;p&gt;Installing Bore is very easy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cargo install bore-cli

# On your local machine
bore local 8000 --to bore.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command gives you a public URL that points to your local port 8000. No need for opening ports on your router or using dynamic DNS!&lt;/p&gt;

&lt;p&gt;Instead of using bore servers you can use your own VPS to route traffic to your home.&lt;/p&gt;

&lt;p&gt;Self-hosting bore is as simple as installing it on your server and running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bore server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if my server's ip address is 2.2.2.2 this is what I need to run on my home computer to access a service running on port 9981 of my home PC through my VPS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bore local 9981 --to 2.2.2.2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bore server assigns a random port to this tunnel. Now I can access my local service running on port 9981 of my home PC using 2.2.2.2:PORT&lt;/p&gt;

</description>
      <category>tunnels</category>
      <category>selfhosting</category>
      <category>reverseproxy</category>
      <category>ngrok</category>
    </item>
    <item>
      <title>How to enable battery charge limit on Linux</title>
      <dc:creator>Mehdi mFat</dc:creator>
      <pubDate>Sun, 28 May 2023 08:16:52 +0000</pubDate>
      <link>https://dev.to/mfat/how-to-enable-battery-charge-limit-on-linux-4392</link>
      <guid>https://dev.to/mfat/how-to-enable-battery-charge-limit-on-linux-4392</guid>
      <description>&lt;p&gt;Some laptops allow you to set a limit on the battery charge level. This feature is known as a &lt;strong&gt;charge threshold&lt;/strong&gt;. For instance, you can choose to stop charging the battery when it reaches 60%, which may help to prolong the battery's lifespan.&lt;/p&gt;

&lt;p&gt;On my Lenovo Thinkbook 14s Yoga it's very easy to do this. Here are the steps:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo dnf install tlp tlp-rdw



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo nano /etc/tlp.conf



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;add this line to the file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

STOP_CHARGE_THRESH_BAT0=1



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;save and close.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo systemctl enable tlp.service
sudo systemctl start tlp.service



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Done! Now your laptop should stop charging the battery beyond 60%.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgwvzobd773c3nglb9xq1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgwvzobd773c3nglb9xq1.png"&gt;&lt;/a&gt;&lt;br&gt;As you can see in the screenshot, the battery is charged until it reaches 59% and then stops charging above that limit.
  &lt;/p&gt;

&lt;p&gt;To check if your laptop supports this feature run:&lt;br&gt;
&lt;code&gt;sudo tlp-stat -b&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
On my laptop the output is this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

$sudo tlp-stat -b
--- TLP 1.5.0 --------------------------------------------

+++ Battery Care
Plugin: lenovo
Supported features: charge threshold
Driver usage:
* vendor (ideapad_laptop) = active (charge threshold)
Parameter value range:
* STOP_CHARGE_THRESH_BAT0: 0(off), 1(on) -- battery conservation mode

/sys/bus/platform/drivers/ideapad_acpi/VPC2004:00/conservation_mode = 1 (60%)

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = Celxpert
/sys/class/power_supply/BAT1/model_name                     = L19C4PDB
/sys/class/power_supply/BAT1/cycle_count                    =    316
/sys/class/power_supply/BAT1/energy_full_design             =  60000 [mWh]
/sys/class/power_supply/BAT1/energy_full                    =  52800 [mWh]
/sys/class/power_supply/BAT1/energy_now                     =  31380 [mWh]
/sys/class/power_supply/BAT1/power_now                      =      0 [mW]
/sys/class/power_supply/BAT1/status                         = Not charging

Charge                                                      =   59.4 [%]
Capacity                                                    =   88.0 [%]


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This line:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Supported features: charge threshold&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
shows that my laptop supports charge threshold.&lt;/p&gt;

&lt;p&gt;And this section gives me the line I need to add to /etc/tlp.conf:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Parameter value range:
* STOP_CHARGE_THRESH_BAT0: 0(off), 1(on) -- battery conservation mode


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>battery</category>
      <category>linux</category>
      <category>tlp</category>
    </item>
    <item>
      <title>How to encrypt DNS requests using cloudflared</title>
      <dc:creator>Mehdi mFat</dc:creator>
      <pubDate>Wed, 24 May 2023 10:38:14 +0000</pubDate>
      <link>https://dev.to/mfat/how-to-proxy-dns-requests-using-cloudflared-58p7</link>
      <guid>https://dev.to/mfat/how-to-proxy-dns-requests-using-cloudflared-58p7</guid>
      <description>&lt;p&gt;&lt;a href="https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation/"&gt;cloudflared&lt;/a&gt; has many functions. When it comes to DNS, it can work as an encrypted DNS proxy. By default it listens for DNS requests and forwards them to Cloudflare DNS server over HTTPS.&lt;/p&gt;

&lt;p&gt;But cloudflared can work with any upstream DoH server, including your self-hosted servers.&lt;/p&gt;

&lt;p&gt;Let's for example see how to forward DNS queries to Google's encrypted DNS server using cloudflared:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cloudflared proxy-dns --upstream https://dns.google/dns-query --port 53
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command tells cloudflared to listen on local port 53 (127.0.0.1:53) for DNS queries. It then encrypts and forwards DNS requests to &lt;a href="https://dns.google/dns-query"&gt;https://dns.google/dns-query&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To use this system-wide, you need to either set 127.0.0.1:53 as your default DNS resolver or make your system resolver forward DNS queries to 127.0.0.1:53.&lt;/p&gt;

&lt;p&gt;Most modern linux distributions use systemd-resolved as their main resolver. &lt;a href="https://dev.to/mfat/how-to-enable-system-wide-dns-over-https-on-fedora-linux-og7"&gt;In my other tutorial&lt;/a&gt; I have explained how you can make systemd-resolved forward DNS requests to any other resolver. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to enable system-wide DNS-over-HTTPS on linux</title>
      <dc:creator>Mehdi mFat</dc:creator>
      <pubDate>Tue, 23 May 2023 17:25:32 +0000</pubDate>
      <link>https://dev.to/mfat/how-to-enable-system-wide-dns-over-https-on-fedora-linux-og7</link>
      <guid>https://dev.to/mfat/how-to-enable-system-wide-dns-over-https-on-fedora-linux-og7</guid>
      <description>&lt;p&gt;In this tutorial we learn how to enable system-wide DNS-over-HTTPS on linux to protect all queries. DNS-over-HTTPS, or simply DOH, encrypts DNS traffic by passing DNS queries through https.&lt;/p&gt;

&lt;p&gt;This howto was tested on Fedora 38 but should work on other linux distributions too. &lt;/p&gt;

&lt;p&gt;First we need to install dnscryp-proxy. It works as a client for DOH servers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo dnf install dnscrypt-proxy

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to edit its config file using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /etc/dnscrypt-proxy/dnscrypt-proxy.toml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we are adding 2 servers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server_names = ['adfilter', 'ahadns']
listen_addresses = ['127.0.0.1:53']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also add more popular servers like 'cloudflare' or 'google' to &lt;code&gt;server_name&lt;/code&gt;.   &lt;/p&gt;

&lt;p&gt;Now we scroll down to the [static] section and add these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[static]

   [static.'adfilter']
   stamp= 'sdns://AgMAAAAAAAAADjE2My40Ny4xMTcuMTc2oMwQYNOcgym2K2-8fQ1t-TCYabmB5-Y5LVzY-kCPTYDmIEROvWe7g_iAezkh6TiskXi4gr1QqtsRIx8ETPXwjffOEGFkbC5hZGZpbHRlci5uZXQKL2Rucy1xdWVyeQ'

   [static.'ahadns']
   stamp= 'sdns://AgMAAAAAAAAACTUuMi43NS43NQARZG9oLm5sLmFoYWRucy5uZXQKL2Rucy1xdWVyeQ'

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For any DOH server you need to find the "stamp". It's usually on the DNS provider website.&lt;/p&gt;

&lt;p&gt;Now we can save the file and exit nano editor.&lt;/p&gt;

&lt;p&gt;We should restart the service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart dnscrypt-proxy.service

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to make our system use this configuration. The default dns server on modern linux systems is called systemd-resolved.&lt;/p&gt;

&lt;p&gt;We should tell systemd-resolved to forward all DNS queries to &lt;br&gt;
dnscrypt-proxy, which is listening on 127.0.0.1:53.&lt;/p&gt;

&lt;p&gt;To do so we create a so-called drop-in file for systemd-resolved using this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo cat &amp;lt;&amp;lt;EOF | sudo tee /etc/systemd/resolved.conf.d/dns_servers.conf
[Resolve]
DNS=127.0.0.1
Domains=~.
EOF
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also need to make sure all lines in /etc/systemd/resolved.conf file are commented out.&lt;/p&gt;

&lt;p&gt;Now we can restart the systemd resolver:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart systemd-resolved.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything has been set correctly, our DNS queries should be encrypted and sent via https.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>privacy</category>
      <category>tutorial</category>
      <category>security</category>
    </item>
  </channel>
</rss>
