diff --git a/config.toml b/config.toml index da8f6de..53aaca4 100644 --- a/config.toml +++ b/config.toml @@ -11,7 +11,6 @@ compile_sass = true # Whether to do syntax highlighting # Theme can be customised by setting the `highlight_theme` variable to a theme supported by Zola -highlight_code = false # Whether to build a search index to be used later on by a JavaScript library build_search_index = false @@ -24,6 +23,9 @@ taxonomies = [ {name = "tags", feed = true}, ] +[markdown] +highlight_code = true +highlight_theme = "base16-ocean-dark" [extra] # Put all your custom variables here diff --git a/content/2022-01-16-wireguard-minecraft.md b/content/2022-01-16-wireguard-minecraft.md new file mode 100644 index 0000000..fcdc8fa --- /dev/null +++ b/content/2022-01-16-wireguard-minecraft.md @@ -0,0 +1,51 @@ ++++ +title = "Today I Did: Minecraft behind a point to point wireguard VPN" +date = 2022-01-15 + +slug = "minecraft-wireguard" +[taxonomies] +categories = ["Today I Did", "Technical", "All"] +tags = ["wireguard", "Networking", "Minecraft"] ++++ + +Today I set up a point to point wireguard VPN and forwarded minecraft traffic via it. + + + +# Background + +I live in a student home with about 100 people. Some of us tested positive for the omnicron variant of COVID-19 so we all had to be quarantined. +One of our people who is responsible for board games and such wanted to set up minecraft server we could all play on during our 10 day quarantene. Unfortunately our servers can't handle running a minecraft server, so it'd have to run on his computer. This posed multiple challenges. + +# Network + +Our network is pretty bad (though I'm working on this). Every room is behind their own routers and NATs behind another NAT. It would probably be enough for him to port forward from his NAT so that all the other people could reach it locally, but the routers adress is on DHCP and we wanted the ability to connect from the internet. +We have a server locally which seems to be DMZed or otherwise have a global ip. +To break through the NATs I set up a two node wireguard network. The server listened, and his computer would connect to it, opening up a tunnel from the server to his desktop via the virtual network card `wg0`. The servers ip in this virtual network was `192.168.42.1` and his desktop was `192.168.42.2` + +To route the traffic properly however we needed to use some iptables rules: + +```bash +iptables -t nat -A PREROUTING -p tcp --dport 25565 -j DNAT --to-destination 192.168.42.2 +iptables -t nat -A POSTROUTING -o wg0 -p tcp --dport 25565 -d 192.168.42.2 -j SNAT --to-source 192.168.42.1 + +iptables -t nat -A PREROUTING -p udp --dport 25565 -j DNAT --to-destination 192.168.42.2 +iptables -t nat -A POSTROUTING -o wg0 -p udp --dport 25565 -d 192.168.42.2 -j SNAT --to-source 192.168.42.1 +``` + +These rules mean that before routing takes place all tcp and udp packets which are going to the standard minecraft port `25565` will be changed so that their destination instead points to the desktop computer actually hosting the minecraft server. +After routing, the source adress on the packet gets set to the server's ip adress so that when the minecraft server replies with information. It knows how to route the information back. This has the downside of making you "lose" the player's IP adress, since the minecraft server will think all network traffic comes from the relaying server. +To avoid this you would probably need some other tool to do the relaying. Like for example waterfall or some other dedicated minecraft proxy. + +We also need allow these packets through the firewall, since its probable your default iptables setup blocks forwarding like this. + +``` +iptables -A FORWARD -i enp0s3 -o wg0 --dst 192.168.42.2 -p tcp --dport 25565 -j ACCEPT +iptables -A FORWARD -i enp0s3 -o wg0 --dst 192.168.42.2 -p udp --dport 25565 -j ACCEPT +``` + +# Wrap up + +These rules need to be saved somehow, but I'll leave that as an exercise for the reader. Maybe you should add them to the pre execute phase of your wireguard systemd unit? + +Hopefully this works for you. I'm not an expert in networking or iptables. But if you have any issues feel free to ask in the comments, can't guarantee an answer though! diff --git a/content/2022-05-07-minecraft-polybar/icon.png b/content/2022-05-07-minecraft-polybar/icon.png new file mode 100644 index 0000000..f3dbe5c Binary files /dev/null and b/content/2022-05-07-minecraft-polybar/icon.png differ diff --git a/content/2022-05-07-minecraft-polybar/index.md b/content/2022-05-07-minecraft-polybar/index.md new file mode 100644 index 0000000..2a90e0b --- /dev/null +++ b/content/2022-05-07-minecraft-polybar/index.md @@ -0,0 +1,87 @@ ++++ +title = "Today I Did: Minecraft activity monitor for polybar" +date = 2022-05-07 + +slug = "minecraft-polybar" +[taxonomies] +categories = ["Today I Did", "Technical", "All"] +tags = ["Nix", "Polybar", "Minecraft", "Python", "Ricing"] ++++ + +It can get boring playing singleplayer on a multiplayer server. +So to maximize social play time I wrote a little server monitor widget for my polybar. + + + + +It's pretty simple, it starts with a python script: +```python +from mcstatus import MinecraftServer as JavaServer +pvv = JavaServer.lookup("minecraft.pvv.ntnu.no") +dods = JavaServer.lookup("mc.dodsorf.as") +try: + pvv_status = pvv.status() + dods_status = dods.status() +except: + pass +result = "" +try: + if pvv_status.players.online > 0: + result += ("P" + str(pvv_status.players.online)) + if dods_status > 0: + result += ("D" + str(pvv_status.players.online)) +except: + pass +print(result) +``` +When ran, this will output how many players are online, with a prefix denoting the server it is reporting on. Fetching the data via the [mcstatus](https://github.com/py-mine/mcstatus) python library. + +# Polybar + +My polybar is configured via [home-manager](https://github.com/nix-community/home-manager) - a tool for declaratively configuring user environments via [Nix](https://nixos.org): + +```nix +"module/minecraft" = { + type = "custom/script"; + + exec = "" + pkgs.writers.writePython3 "minecraft_status" { libraries = [ pkgs.python3.pkgs.mcstatus ]; flakeIgnore = [ "E722" ]; } '' + from mcstatus import MinecraftServer as JavaServer + pvv = JavaServer.lookup("minecraft.pvv.ntnu.no") + dods = JavaServer.lookup("mc.dodsorf.as") + try: + pvv_status = pvv.status() + dods_status = dods.status() + except: + pass + result = "" + try: + if pvv_status.players.online > 0: + result += ("P" + str(pvv_status.players.online)) + if dods_status > 0: + result += ("D" + str(pvv_status.players.online)) + except: + pass + print(result) + ''; + + interval = 10; + format = "