Set up Shadowsocks on an Ubuntu VM in Azure for VPN purposes

build a shadowsocks server in Azure

Shadowsocks is one of the techniques that you can use to set up your VPN equivalent server. With Microsoft Azure, you can quickly set up a Ubuntu virtual machine (VM) to host Shadowsocks. But why Ubuntu? Simply because it demands less Azure resource from the cost-saving perspective than other available operating systems. Don’t worry if you barely have the knowledge in Azure or Ubuntu. Follow the steps in the article and you will get there.

Monthly cost of a Shadowsocks server in Azure

Before we start, let’s take a look at the cost of a Shadowsocks server in Azure.

  • VM (Ubuntu): 22.32$/month.
  • Bandwidth: Monthly cost of the first 5GB for free and 0.138$/GB onward for incoming traffic. Outbound traffic from Azure is free.

Let’s say you used 105 GB incoming data in a month which turns out to be 13.8$. Plus the VM cost, you get a total of 36.12$ for that month.
Note: The actual cost may vary over time and the geo region the VM sits in.

To set up Shadowsocks in Azure, you need to:

  1. Set up a Ubuntu server in Azure.
  2. Create a port on the server for Shadowsocks connection.
  3. Set up and configure Shadowsocks.

Now let’s start.

Set up a Ubuntu server in Azure

  1. Open the Azure portal, and log in with your Azure account (Get a one month free trial of Azure with 200$ credit).
  2. Click New, type Ubuntu, and then press Enter.
  3. Select Ubuntu Server 17.04 in the list of matches, and start creating one with the Resource Manager deployment model.
  4. Proceed with the following configuration for the setup:
    • Use the Basic A1 plan at 22.32$/month.
    • Set the Authenticate type to use Password.
    • Create a new resource group to host the server.
    • Set Public IP address to Static.
      2017-05-23_11-47-10
      2017-05-23_11-52-10.png
  5. Once the server is created, note down the Public IP address.
    2017-05-24_15-16-07

Create a port on the server for Shadowsocks connection

  1. Go to the resource group where the VM is hosted, find and open the <server>_nsg resource.
    This resource functions as the firewall for the server. It comes with a pre-configured inbound security rule to allow management through SSH on TCP port 22.
    2017-05-24_15-28-27
  2. Add an inbound security rule by providing a name and port, and leave the rest with the default value. Here I set the port to 2000.
    11

Set up and configure Shadowsocks

  1. Use an SSH client to connect to the Ubuntu server using the public IP address, which you noted down earlier, for remote management. PuTTY is the client I use on Windows.
    2017-05-24_18-39-38
    Upon connection, an SSH client window opens.
  2. Update Ubuntu to the latest version in the SSH client window by running the following commands:
    sudo apt update
    sudo apt dist-upgrade
  3. Install Shadowsocks.
    sudo apt install shadowsocks-libev
  4. Configure Shadowsocks.
    1. Open the config.json file.
      sudo vim /etc/shadowsocks-libev/config.json
    2. Press I to switch to the editing mode.
    3. If you have a single port created in the <server>_nsg resource:
      • Set server to 0.0.0.0.
      • Set server_port to the port you created in the <server>_nsg resource.
      • Set password to the password of your Ubuntu server.
      • Set method to “aes-256-cfb”.
        2017-05-23_11-58-00
    4. Press ESC, and then type :wq to save the file.
  5. In the Azure portal, restart the Ubuntu server.
    Note: The setup has configured Shadowsocks to automatically start with Ubuntu.
    11111
  6. Verify if the ShadowSocks server is listening on the port, in this case 2000.
    netstat -lnp
    If the port was not listened, restart ShadowSocks.
    service shadowsocks-libev restart
  7. Download the Shadowsocks client that is available on Android, iOS, Windows and macOS. For Android and iOS, you may have to get the client from the US app store.
  8. Open the Shadowsocks client, enter the connection information and make the connection. You also have the option of enabling Shadowsocks to handle the traffic only to sites outside of China.

Congratulations! Now you are all set. Enjoy Shadowsocks!

Related Shadowsocks commands

  • Start Shadowsocks: sudo systemctl start shadowsocks-libev
  • Stop Shadowsocks: sudo systemctl stop shadowsocks-libev
  • Kill Shadowsocks in case Stop fails: sudo systemctl kill shadowsocks-libev
  • Restart Shadowsocks: sudo systemctl restart shadowsocks-libev

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s