Difference between revisions of "Mullvad"

From ArchWiki
Jump to: navigation, search
m (Using Mullvad as plain OpenVPN: rm red link)
(Using Mullvad as plain OpenVPN)
Line 4: Line 4:
 
To use the VPN service Mullvad on Arch Linux a few small adjustments need to be done. First, install [[OpenVPN]] and resolvconf. Download the plain [[OpenVPN]] version of Mullvad [http://mullvad.net/en/openvpn_conf.php "here"]. Next, copy the content of the zip file to /etc/openvpn. Open the file mullvad_linux.conf and change the end of the file from  
 
To use the VPN service Mullvad on Arch Linux a few small adjustments need to be done. First, install [[OpenVPN]] and resolvconf. Download the plain [[OpenVPN]] version of Mullvad [http://mullvad.net/en/openvpn_conf.php "here"]. Next, copy the content of the zip file to /etc/openvpn. Open the file mullvad_linux.conf and change the end of the file from  
 
{{hc|mullvad_linux.conf|<nowiki>
 
{{hc|mullvad_linux.conf|<nowiki>
# Parses DHCP options from openvpn to update resolv.conf
 
up /etc/openvpn/update-resolv-conf
 
down /etc/openvpn/update-resolv-conf
 
 
 
ping 10
 
ping 10
  
Line 16: Line 12:
 
to
 
to
 
{{hc|mullvad_linux.conf|<nowiki>
 
{{hc|mullvad_linux.conf|<nowiki>
# Parses DHCP options from openvpn to update resolv.conf
 
# up /etc/openvpn/update-resolv-conf
 
# down /etc/openvpn/update-resolv-conf
 
up /usr/share/openvpn/update-resolv-conf
 
down /usr/share/openvpn/update-resolv-conf
 
 
 
ping 10
 
ping 10
  
Line 28: Line 18:
 
key /etc/openvpn/mullvad.key
 
key /etc/openvpn/mullvad.key
 
</nowiki>}}
 
</nowiki>}}
and make it executable by running
+
and make it executable by running {{ic|<nowiki>sudo chmod +x /etc/openvpn/mullvad_linux.conf</nowiki>}}
    sudo chmod +x /etc/openvpn/mullvad_linux.conf
 
  
Load the tun module by creating the file
+
If {{ic|<nowiki>lsmod | grep tun</nowiki>}} returns a blank line, the tun module isn't getting loaded by default and you'll need to load it manually and tell the system to load it during startup by running {{ic|<nowiki>sudo modprobe tun</nowiki>}} and {{ic|<nowiki>sudo echo "tun" > /etc/modules-load.d/tun.conf</nowiki>}}
{{hc|/etc/modules-load.d/tun.conf|<nowiki>
 
# Load tun.ko at boot
 
tun</nowiki>}}
 
  
and create  
+
then create  
{{hc|/usr/share/openvpn/update-resolv-conf|<nowiki>
+
{{hc|/etc/openvpn/update-resolv-conf|<nowiki>
 
#!/bin/bash
 
#!/bin/bash
 
#
 
#
Line 93: Line 79:
 
</nowiki>}}
 
</nowiki>}}
  
and don't forget to make it executable by running
+
and don't forget to make it executable by running {{ic|<nowiki>sudo chmod +x /etc/openvpn/update-resolv-conf</nowiki>}}
    sudo chmod +x /usr/share/openvpn/update-resolv-conf
 
  
Lastly create the file
+
Now create the launch script:
{{hc|/usr/bin/mullvad|<nowiki>
+
{{hc|/usr/local/bin/mullvad|<nowiki>
#! /bin/bash
+
#!/usr/bin/env bash
# Script to start Mullvad
+
 
gksu openvpn /etc/openvpn/mullvad_linux.conf
+
if [ ! "$UID" = 0 ]; then
 +
    if [ `type -P gksu` ]; then
 +
        SUDOAPP="gksu"
 +
    elif [ `type -P kdesu` ]; then
 +
        SUDOAPP="kdesu"
 +
    else
 +
        SUDOAPP="sudo"
 +
    fi
 +
fi
 +
 
 +
if [ -n "$1" ]; then
 +
    if [ "$1" = "start" ]; then
 +
        $SUDOAPP systemctl start openvpn@mullvad
 +
    elif [ "$1" = "stop" ]; then
 +
        $SUDOAPP systemctl stop openvpn@mullvad
 +
    else
 +
        echo "Invalid command"
 +
        exit 1
 +
    fi
 +
else
 +
    echo "Run 'start' or 'stop' as an argument to start or stop the Mullvad VPN"
 +
    exit 1
 +
fi
 
</nowiki>}}
 
</nowiki>}}
make it executable
 
    sudo chmod +x /usr/bin/mullvad
 
and simply run Mullvad in the terminal by typing
 
    mullvad
 
  
To create a menu item we need the logo
+
Then make the launch script executable by running {{ic|<nowiki>chmod a+x /usr/local/bin/mullvad</nowiki>}}
    wget https://mullvad.net/images/logo.png -O /usr/share/icons/mullvad.png
+
 
Then create the .desktop file
+
You can then start Mullvad in the terminal by running {{ic|<nowiki>mullvad start</nowiki>}} and stop it with: {{ic|<nowiki>mullvad stop</nowiki>}}
{{hc|/usr/share/applications/mullvad.desktop|<nowiki>
+
 
[Desktop Entry]
+
To create a menu item we need the logo run: {{ic|<nowiki>wget https://mullvad.net/static/images/mullvad-circle.svg -O ~/.local/share/icons/mullvad.svg</nowiki>}}
Type=Application
+
 
Icon=/usr/share/icons/mullvad.png
+
Then create the .desktop file by running {{ic|<nowiki>echo -e "[Desktop Entry]\nType=Application\nName=Mullvad\nComment=Start Mullvad VPN service\nIcon=mullvad\nExec=mullvad start\nCategories=Network" > ~/.local/share/applications/mullvad.desktop</nowiki>}}
Name=Mullvad
+
 
Comment=Start Mullvad VPN service
+
If {{ic|<nowiki>mullvad start</nowiki>}} is successful from the command line, the desktop file should appear in your menu and start the service the same way by selecting it.
Exec=mullvad
 
Categories=Network
 
</nowiki>}}
 

Revision as of 20:53, 17 April 2014

Using Mullvad as plain OpenVPN

To use the VPN service Mullvad on Arch Linux a few small adjustments need to be done. First, install OpenVPN and resolvconf. Download the plain OpenVPN version of Mullvad "here". Next, copy the content of the zip file to /etc/openvpn. Open the file mullvad_linux.conf and change the end of the file from

mullvad_linux.conf
ping 10

ca master.mullvad.net.crt
cert mullvad.crt
key mullvad.key

to

mullvad_linux.conf
ping 10

ca /etc/openvpn/master.mullvad.net.crt
cert /etc/openvpn/mullvad.crt
key /etc/openvpn/mullvad.key

and make it executable by running sudo chmod +x /etc/openvpn/mullvad_linux.conf

If lsmod | grep tun returns a blank line, the tun module isn't getting loaded by default and you'll need to load it manually and tell the system to load it during startup by running sudo modprobe tun and sudo echo "tun" > /etc/modules-load.d/tun.conf

then create

/etc/openvpn/update-resolv-conf
#!/bin/bash
#
# Parses DHCP options from openvpn to update resolv.conf
# To use set as 'up' and 'down' script in your openvpn *.conf:
# up /etc/openvpn/update-resolv-conf
# down /etc/openvpn/update-resolv-conf
#
# Used snippets of resolvconf script by Thomas Hood <jdthood@yahoo.co.uk>
# and Chris Hanson
# Licensed under the GNU GPL.  See /usr/share/common-licenses/GPL.
#
# 05/2006 chlauber@bnc.ch
#
# Example envs set from openvpn:
# foreign_option_1='dhcp-option DNS 193.43.27.132'
# foreign_option_2='dhcp-option DNS 193.43.27.133'
# foreign_option_3='dhcp-option DOMAIN be.bnc.ch'

[ -x /usr/sbin/resolvconf ] || exit 0

case $script_type in

up)
   for optionname in ${!foreign_option_*} ; do
      option="${!optionname}"
      echo $option
      part1=$(echo "$option" | cut -d " " -f 1)
      if [ "$part1" == "dhcp-option" ] ; then
         part2=$(echo "$option" | cut -d " " -f 2)
         part3=$(echo "$option" | cut -d " " -f 3)
         if [ "$part2" == "DNS" ] ; then
            IF_DNS_NAMESERVERS="$IF_DNS_NAMESERVERS $part3"
         fi
         if [ "$part2" == "DOMAIN" ] ; then
            IF_DNS_SEARCH="$part3"
         fi
      fi
   done
   R=""
   if [ "$IF_DNS_SEARCH" ] ; then
           R="${R}search $IF_DNS_SEARCH
"
   fi
   for NS in $IF_DNS_NAMESERVERS ; do
           R="${R}nameserver $NS
"
   done
   echo -n "$R" | /usr/sbin/resolvconf -a "${dev}.inet"
   ;;
down)
   /usr/sbin/resolvconf -d "${dev}.inet"
   ;;
esac

and don't forget to make it executable by running sudo chmod +x /etc/openvpn/update-resolv-conf

Now create the launch script:

/usr/local/bin/mullvad
#!/usr/bin/env bash

if [ ! "$UID" = 0 ]; then
    if [ `type -P gksu` ]; then
        SUDOAPP="gksu"
    elif [ `type -P kdesu` ]; then
        SUDOAPP="kdesu"
    else
        SUDOAPP="sudo"
    fi
fi

if [ -n "$1" ]; then
    if [ "$1" = "start" ]; then
        $SUDOAPP systemctl start openvpn@mullvad
    elif [ "$1" = "stop" ]; then
        $SUDOAPP systemctl stop openvpn@mullvad
    else
        echo "Invalid command"
        exit 1
    fi
else
    echo "Run 'start' or 'stop' as an argument to start or stop the Mullvad VPN"
    exit 1
fi

Then make the launch script executable by running chmod a+x /usr/local/bin/mullvad

You can then start Mullvad in the terminal by running mullvad start and stop it with: mullvad stop

To create a menu item we need the logo run: wget https://mullvad.net/static/images/mullvad-circle.svg -O ~/.local/share/icons/mullvad.svg

Then create the .desktop file by running echo -e "[Desktop Entry]\nType=Application\nName=Mullvad\nComment=Start Mullvad VPN service\nIcon=mullvad\nExec=mullvad start\nCategories=Network" > ~/.local/share/applications/mullvad.desktop

If mullvad start is successful from the command line, the desktop file should appear in your menu and start the service the same way by selecting it.