Enabling LAN Access in Mullvad Wireguard Conf Files
734 words ยท 4 minutes
Download Configuration Files from Mullvad
To begin, you'll need Wireguard configuration files from Mullvad. You can choose any of the options as you download them. For example, I enabled the kill switch, selected all countries, and selected a few content filters.
Once downloaded, unzip the files and move them to the Wireguard folder on your system.
Configuration File Layout
The default configuration files will look something like this:
[Interface]
<redacted>
<redacted>
DNS = <redacted>
iptables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT && ip6tables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
iptables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT && ip6tables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
[Peer]
<redacted>
<redacted>
<redacted>
Note: If you didn't select the kill switch option, you won't see the
PostUp
andPreDown
lines. In this case, you'll need to modify the script below to simply append those lines to the[Interface]
block.
Editing the Configuration Files
Once you have the files, you'll need to edit them and replace the PostUp
and PreDown
lines to enable LAN access.
I recommend that you do this process as root, since you'll need to be able to access files in /etc/wireguard
, which are generally owned by root. You can also try using sudo
or doas
, but I didn't test that scenario so you may need to adjust, as necessary.
Create the Python file that we'll be using to update the Wireguard configuration files.
Within the Python file, copy and paste the logic below. This script will open a directory, loop through every configuration file within the directory, and replace the PostUp
and PreDown
lines with the new LAN-enabled iptables commands.
Note: If your LAN is on a subnet other than
192.168.1.0/24
, you'll need to update the Python script below appropriately.
=
Once you're done, save and close the file. You can now run the Python script and watch as each file is updated.
To confirm it worked, you can cat
one of the configuration files to inspect the new logic and connect to one to test it out.
The configuration files should now look like this:
[Interface]
<redacted>
<redacted>
DNS = <redacted>
iptables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL ! -d -j REJECT && ip6tables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
iptables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL ! -d -j REJECT && ip6tables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
[Peer]
<redacted>
<redacted>
<redacted>
If you connect to a Wireguard interface, such as us-chi-wg-001
, you can test your SSH functionality and see that it works even while on the VPN.
To confirm your VPN connection, you can curl Mullvad's connection API:
# You are connected to Mullvad (server us-chi-wg-001). Your IP address is <redacted>