{"version":"https://jsonfeed.org/version/1.1","title":"Jaryl Chng's Knowledge Base","home_page_url":"https://kb.jarylchng.com","feed_url":"https://kb-jarylchng-com.pages.dev/json/","description":"<p>Welcome to the index page of my knowledge base, if you haven't done so, do visit my website at <a href=\"https://jarylchng.com\" rel=\"noopener noreferrer\" target=\"_blank\">https://jarylchng.com</a>.</p><p>I will mainly use this site to document stuff, most of which will likely be in the public domain.</p>","icon":"https://kb-static.jarylchng.com/kb-jarylchng-com/production/images/channel-c68f1f55f856ab833b4365991609dbec.png","favicon":"https://kb-static.jarylchng.com/kb-jarylchng-com/production/images/favicon-b94914f57599a477f9f72dab6bc71001.png","authors":[{"name":"Jaryl Chng"}],"language":"en-us","items":[{"id":"cGYI6ANCvu6","title":"Linux - Wireguard Server and Peer Configuration","url":"https://kb.jarylchng.com/i/linux-wireguard-server-and-peer-configuration-cGYI6ANCvu6/","content_html":"<p>Wireguard is a new VPN tool that is vastly easier to setup than the popular alternative OpenVPN. Also reports state that it is also superior in speed and reliability.</p><h2>Setup</h2><h3>General</h3><h4>Installation</h4><p>Most package managers should have the required packages named</p><p>wireguard-tools wireguard-dkms</p><p>Install them on both your server and client(s).</p><p>Note: very soon, Wireguard will become baked into the Linux kernel by default and wireguard-dkms will not be needed anymore.</p><h4>Generation of private and public key pair</h4><pre class=\"ql-syntax\" spellcheck=\"false\">(umask 077 &amp;&amp; printf \"[Interface]\\nPrivateKey = \" | sudo tee /etc/wireguard/wg0.conf &gt; /dev/null)\nwg genkey | sudo tee -a /etc/wireguard/wg0.conf | wg pubkey | sudo tee /etc/wireguard/publickey\n</pre><p>Replace wg0 with your desired network device id throughout the article if needed.</p><p>This generates a private key and automatically inserts as a configuration line to /etc/wireguard/wg0.conf and a public key saved to /etc/wireguard/publickey automatically. Run it on both your server and client(s) respectively.</p><h3>Server</h3><h4>Edit /etc/wireguard/wg0.conf</h4><pre class=\"ql-syntax\" spellcheck=\"false\">[Interface]\n# Private key, automatically generated by above command on the server (should be only 44 characters as of writing)\nPrivateKey = -auto generated-\n\n# Private IPv4 and IPv6 address of Server for peers to communicate with when connected, you can replace `123.210` and `123:210` with anything you like throughout the article\nAddress = 10.123.210.1/24,fd00:123:210::1/112\n\n# Listen port, can be any port you like including 53 if you don't use it for DNS. Must be the same throughout the article.\nListenPort = 51820\n\n# Setup IPv4 and IPv6 iptables to forward the network of peers through the server, not required if only a LAN connection is required (optional)\nPostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i %i -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE\nPostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FORWARD -i %i -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE\n\n# Save the configuration to the file on every shutdown, personally I prefer it off because I find it easier to edit the configuration directly rather than to rely on tools\nSaveConfig = false\n\n\n# CLIENT 1\n[Peer]\n\n# Public key of the peer, generated by the above command on the peer (also should be only 44 characters as of writing)\nPublicKey = -auto generated and copied here-\n\n# Allow IPv4 and IPv6 range from 10.123.210.1-10.123.210.254 and fd00:123:210::1-fd00:123:210::ffff respectively\nAllowedIPs = 10.123.210.0/24,fd00:123:210::0/112\n\n\n# CLIENT 2\n[Peer]\n# Public key of the peer, generated by the above command on the peer (also should be only 44 characters as of writing)\nPublicKey = -auto generated and copied here-\n\n# Allow IPv4 and IPv6 range from 10.123.210.1-10.123.210.254 and fd00:123:210::1-fd00:123:210::ffff respectively\nAllowedIPs = 10.123.210.0/24,fd00:123:210::0/112\n\n# ... More peers if required ...\n</pre><h4>Additional step to allow forwarding (optional)</h4><pre class=\"ql-syntax\" spellcheck=\"false\">echo -e \"net.ipv4.ip_forward=1\\nnet.ipv6.conf.all.forwarding=1\" | sudo tee -a /etc/sysctl.d/99-sysctl.conf\nsudo sysctl -p\n</pre><h4>Start the server</h4><pre class=\"ql-syntax\" spellcheck=\"false\">sudo systemctl enable --now wg-quick@wg0\n</pre><h3>Client(s)</h3><h4>Edit /etc/wireguard/wg0.conf</h4><pre class=\"ql-syntax\" spellcheck=\"false\">[Interface]\n# Private key, automatically generated by above command on the client (should be only 44 characters as of writing)\nPrivateKey = -auto generated-\n\n# Private IPv4 and IPv6 address of client, must be static IP (no clashes) because there is no DHCP provided by Wireguard as of writing. Change the `2` to an incremental number for every client\nAddress = 10.123.210.2/32,fd00:123:210::2/128\n\n# DNS server to use, currently set to Cloudflare\nDNS = 1.1.1.1\n\n\n# SERVER\n[Peer]\n# Public key of server, generated by the above command on the server (only 44 characters as of writing)\nPublicKey = -auto generated and copied here-\n\n# Public IP of server and port configured in the server\nEndpoint = -public key of server-:51820\n\n# IP ranges Wireguard will listen on and forward\n# AllowedIPs = 10.123.210.0/24,fd00:123:210::0/112 # ROUTE ONLY VIRTUAL PRIVATE NETWORK TRAFFIC\nAllowedIPs = 0.0.0.0/5, 8.0.0.0/7, 11.0.0.0/8, 12.0.0.0/6, 16.0.0.0/4, 32.0.0.0/3, 64.0.0.0/2, 128.0.0.0/3, 160.0.0.0/5, 168.0.0.0/6, 172.0.0.0/12, 172.32.0.0/11, 172.64.0.0/10, 172.128.0.0/9, 173.0.0.0/8, 174.0.0.0/7, 176.0.0.0/4, 192.0.0.0/9, 192.128.0.0/11, 192.160.0.0/13, 192.169.0.0/16, 192.170.0.0/15, 192.172.0.0/14, 192.176.0.0/12, 192.192.0.0/10, 193.0.0.0/8, 194.0.0.0/7, 196.0.0.0/6, 200.0.0.0/5, 208.0.0.0/4, ::/0, 10.123.210.0/32 # ROUTE ALL INTERNET TRAFFIC LESS LAN THROUGH\n\n# Constant pings to keep the connection alive and not time out on inactivity\nPersistentKeepalive = 25\n</pre><h4>Connect to server</h4><pre class=\"ql-syntax\" spellcheck=\"false\">sudo wg-quick up wg0\n</pre><h4>Connection information</h4><p>You can run these commands to check the connection</p><pre class=\"ql-syntax\" spellcheck=\"false\">sudo wg\nping 10.123.210.1\n</pre><h4>Disconnect from server</h4><pre class=\"ql-syntax\" spellcheck=\"false\">sudo wg-quick down wg0\n</pre><h2>Extra information</h2><h3>networkmanager-wireguard</h3><p>If you use NetworkManager (especially nm-applet) you can install networkmanager-wireguard or networkmanager-wireguard-git (AUR) for Wireguard capabilities and configuration.</p><h3>Forward other UDP ports to Wireguard port with iptables</h3><p>On the server:</p><pre class=\"ql-syntax\" spellcheck=\"false\">sudo iptables -t nat -I PREROUTING -i eth0 -p udp -m multiport --dports 53,80,123,161,443 -j REDIRECT --to-ports 51820\n</pre><p>To disable:</p><pre class=\"ql-syntax\" spellcheck=\"false\">sudo iptables -t nat -D PREROUTING -i eth0 -p udp -m multiport --dports 53,80,123,161,443 -j REDIRECT --to-ports 51820\n</pre><p>You can add it to PostUp and PostDown. Don't forget ip6tables if needed.</p><h3>More reading</h3><p><a href=\"https://wiki.jarylchng.com/en/operating-systems/linux/wireguard-server-and-peers-configuration\" rel=\"noopener noreferrer\" target=\"_blank\">https://github.com/pirate/wireguard-docs#Interface</a></p>","content_text":"Wireguard is a new VPN tool that is vastly easier to setup than the popular\nalternative OpenVPN. Also reports state that it is also superior in speed and\nreliability.\n\n\nSETUP\n\n\nGENERAL\n\nINSTALLATION\n\nMost package managers should have the required packages named\n\nwireguard-tools wireguard-dkms\n\nInstall them on both your server and client(s).\n\nNote: very soon, Wireguard will become baked into the Linux kernel by default\nand wireguard-dkms will not be needed anymore.\n\nGENERATION OF PRIVATE AND PUBLIC KEY PAIR\n\n(umask 077 && printf \"[Interface]\\nPrivateKey = \" | sudo tee /etc/wireguard/wg0.conf > /dev/null)\nwg genkey | sudo tee -a /etc/wireguard/wg0.conf | wg pubkey | sudo tee /etc/wireguard/publickey\n\n\nReplace wg0 with your desired network device id throughout the article if\nneeded.\n\nThis generates a private key and automatically inserts as a configuration line\nto /etc/wireguard/wg0.conf and a public key saved to /etc/wireguard/publickey\nautomatically. Run it on both your server and client(s) respectively.\n\n\nSERVER\n\nEDIT /ETC/WIREGUARD/WG0.CONF\n\n[Interface]\n# Private key, automatically generated by above command on the server (should be only 44 characters as of writing)\nPrivateKey = -auto generated-\n\n# Private IPv4 and IPv6 address of Server for peers to communicate with when connected, you can replace `123.210` and `123:210` with anything you like throughout the article\nAddress = 10.123.210.1/24,fd00:123:210::1/112\n\n# Listen port, can be any port you like including 53 if you don't use it for DNS. Must be the same throughout the article.\nListenPort = 51820\n\n# Setup IPv4 and IPv6 iptables to forward the network of peers through the server, not required if only a LAN connection is required (optional)\nPostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i %i -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE\nPostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FORWARD -i %i -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE\n\n# Save the configuration to the file on every shutdown, personally I prefer it off because I find it easier to edit the configuration directly rather than to rely on tools\nSaveConfig = false\n\n\n# CLIENT 1\n[Peer]\n\n# Public key of the peer, generated by the above command on the peer (also should be only 44 characters as of writing)\nPublicKey = -auto generated and copied here-\n\n# Allow IPv4 and IPv6 range from 10.123.210.1-10.123.210.254 and fd00:123:210::1-fd00:123:210::ffff respectively\nAllowedIPs = 10.123.210.0/24,fd00:123:210::0/112\n\n\n# CLIENT 2\n[Peer]\n# Public key of the peer, generated by the above command on the peer (also should be only 44 characters as of writing)\nPublicKey = -auto generated and copied here-\n\n# Allow IPv4 and IPv6 range from 10.123.210.1-10.123.210.254 and fd00:123:210::1-fd00:123:210::ffff respectively\nAllowedIPs = 10.123.210.0/24,fd00:123:210::0/112\n\n# ... More peers if required ...\n\n\nADDITIONAL STEP TO ALLOW FORWARDING (OPTIONAL)\n\necho -e \"net.ipv4.ip_forward=1\\nnet.ipv6.conf.all.forwarding=1\" | sudo tee -a /etc/sysctl.d/99-sysctl.conf\nsudo sysctl -p\n\n\nSTART THE SERVER\n\nsudo systemctl enable --now wg-quick@wg0\n\n\n\nCLIENT(S)\n\nEDIT /ETC/WIREGUARD/WG0.CONF\n\n[Interface]\n# Private key, automatically generated by above command on the client (should be only 44 characters as of writing)\nPrivateKey = -auto generated-\n\n# Private IPv4 and IPv6 address of client, must be static IP (no clashes) because there is no DHCP provided by Wireguard as of writing. Change the `2` to an incremental number for every client\nAddress = 10.123.210.2/32,fd00:123:210::2/128\n\n# DNS server to use, currently set to Cloudflare\nDNS = 1.1.1.1\n\n\n# SERVER\n[Peer]\n# Public key of server, generated by the above command on the server (only 44 characters as of writing)\nPublicKey = -auto generated and copied here-\n\n# Public IP of server and port configured in the server\nEndpoint = -public key of server-:51820\n\n# IP ranges Wireguard will listen on and forward\n# AllowedIPs = 10.123.210.0/24,fd00:123:210::0/112 # ROUTE ONLY VIRTUAL PRIVATE NETWORK TRAFFIC\nAllowedIPs = 0.0.0.0/5, 8.0.0.0/7, 11.0.0.0/8, 12.0.0.0/6, 16.0.0.0/4, 32.0.0.0/3, 64.0.0.0/2, 128.0.0.0/3, 160.0.0.0/5, 168.0.0.0/6, 172.0.0.0/12, 172.32.0.0/11, 172.64.0.0/10, 172.128.0.0/9, 173.0.0.0/8, 174.0.0.0/7, 176.0.0.0/4, 192.0.0.0/9, 192.128.0.0/11, 192.160.0.0/13, 192.169.0.0/16, 192.170.0.0/15, 192.172.0.0/14, 192.176.0.0/12, 192.192.0.0/10, 193.0.0.0/8, 194.0.0.0/7, 196.0.0.0/6, 200.0.0.0/5, 208.0.0.0/4, ::/0, 10.123.210.0/32 # ROUTE ALL INTERNET TRAFFIC LESS LAN THROUGH\n\n# Constant pings to keep the connection alive and not time out on inactivity\nPersistentKeepalive = 25\n\n\nCONNECT TO SERVER\n\nsudo wg-quick up wg0\n\n\nCONNECTION INFORMATION\n\nYou can run these commands to check the connection\n\nsudo wg\nping 10.123.210.1\n\n\nDISCONNECT FROM SERVER\n\nsudo wg-quick down wg0\n\n\n\nEXTRA INFORMATION\n\n\nNETWORKMANAGER-WIREGUARD\n\nIf you use NetworkManager (especially nm-applet) you can install\nnetworkmanager-wireguard or networkmanager-wireguard-git (AUR) for Wireguard\ncapabilities and configuration.\n\n\nFORWARD OTHER UDP PORTS TO WIREGUARD PORT WITH IPTABLES\n\nOn the server:\n\nsudo iptables -t nat -I PREROUTING -i eth0 -p udp -m multiport --dports 53,80,123,161,443 -j REDIRECT --to-ports 51820\n\n\nTo disable:\n\nsudo iptables -t nat -D PREROUTING -i eth0 -p udp -m multiport --dports 53,80,123,161,443 -j REDIRECT --to-ports 51820\n\n\nYou can add it to PostUp and PostDown. Don't forget ip6tables if needed.\n\n\nMORE READING\n\nhttps://github.com/pirate/wireguard-docs#Interface","date_published":"2024-04-06T16:15:32.003Z","_microfeed":{"web_url":"https://kb-jarylchng-com.pages.dev/i/linux-wireguard-server-and-peer-configuration-cGYI6ANCvu6/","json_url":"https://kb-jarylchng-com.pages.dev/i/cGYI6ANCvu6/json/","rss_url":"https://kb-jarylchng-com.pages.dev/i/cGYI6ANCvu6/rss/","guid":"cGYI6ANCvu6","status":"published","itunes:episodeType":"full","date_published_short":"Sat Apr 06 2024","date_published_ms":1712420132003}}],"_microfeed":{"microfeed_version":"0.1.2","base_url":"https://kb-jarylchng-com.pages.dev","categories":[{"name":"Technology"}],"subscribe_methods":[{"name":"RSS","type":"rss","url":"https://kb-jarylchng-com.pages.dev/rss/","image":"https://kb-jarylchng-com.pages.dev/assets/brands/subscribe/rss.png","enabled":true,"editable":false,"id":"sQbXXExV58H"},{"name":"JSON","type":"json","url":"https://kb-jarylchng-com.pages.dev/json/","image":"https://kb-jarylchng-com.pages.dev/assets/brands/subscribe/json.png","enabled":true,"editable":false,"id":"nC8cjLCnOOi"}],"description_text":"Welcome to the index page of my knowledge base, if you haven't done so, do visit\nmy website at https://jarylchng.com.\n\nI will mainly use this site to document stuff, most of which will likely be in\nthe public domain.","copyright":"©2024","itunes:type":"episodic","items_sort_order":"newest_first"}}