舫摘

知人者智 自知者明 胜人者有力 自胜者强

0%

How to cross-compile shadowsocks for Asus router in Ubuntu

Shadowsocks-libev is a lightweight secured SOCKS5 proxy for embedded devices and low-end boxes.

It’s a useful tool for peoples whose cannot access the website like Facebook, Twitter.

Usually, we run it on PC. It’s not environmentally friendly because the computer should power supply 24/7 whether we want to share the Shadowsocks proxy to friends.

To resolve this problem I prefer to run it on a router. In general, routers always running and more power efficient than a computer.

Today, I will show you how to build an arm version Shadowsocks for Asus router. Let’s go.

Important: Ubuntu 16.04 and basic Linux knowledge is necessary.

Prepare your build environment

Run command below in command line

1
sudo apt-get install --no-install-recommends gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libc-ares-dev automake libmbedtls-dev libsodium-dev

Download Asus firmware source code

You can find the source code of your Asus router in Asus website.
My router is RT-AC1200G+, the source code at here.

Download archive with

1
wget http://dlcdnet.asus.com/pub/ASUS/wireless/RT-AC1200G+/GPL_RT_AC1200GPlus_300438250624.zip

Unzip the archive to /opt folder

1
2
unzip GPL_RT_AC1200GPlus_300438250624.zip
sudo tar zxvf GPL_RT-AC1200G+_3.0.0.4.382.50624-gdf1b286.tgz -C /opt/

Update system environmental variables

1
2
3
4
5
6
7
export PATH=$PATH:/opt/asuswrt/release/src-rt-9.x/src/toolchains/hndtools-arm-linux-2.6.36-uclibc-4.5.3/bin
export STAGING_DIR=/opt/asuswrt/release/src-rt-9.x/src/toolchains/hndtools-arm-linux-2.6.36-uclibc-4.5.3
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/asuswrt/release/src-rt-9.x/src/toolchains/hndtools-arm-linux-2.6.36-uclibc-4.5.3/lib
export CC=arm-uclibc-linux-2.6.36-gcc
export CXX=arm-uclibc-linux-2.6.36-g++
export AR=arm-uclibc-linux-2.6.36-ar
export RANLIB=arm-uclibc-linux-2.6.36-ranlib

Compile zlib

Create a folder for compiled files

1
mkdir -p ${HOME}/bin/zlib

Download source code with

1
wget https://zlib.net/zlib-1.2.11.tar.gz

Unzip the archive

1
tar xvzf zlib-1.2.11.tar.gz

Compile

1
2
3
cd zlib-1.2.11/
./configure --prefix=${HOME}/bin/zlib
make && make install

Compile mbedtls

Create a folder for compiled files

1
mkdir -p ${HOME}/bin/mbedtls

Download source code with

1
wget https://tls.mbed.org/download/mbedtls-2.11.0-apache.tgz

Unzip the archive

1
tar zxvf mbedtls-2.11.0-apache.tgz

Edit MakeFile

1
2
3
4
cd mbedtls-2.11.0/
vim Makefile
# Change second line to
DESTDIR=${HOME}/bin/mbedtls

Save file and exit vim.

Compile

1
make && make install

Compile pcre

Create a folder for compiled files

1
mkdir -p ${HOME}/bin/pcre

Download source code with

1
wget http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-8.41.zip

Unzip the archive

1
unzip pcre-8.41.zip

Compile

1
2
3
cd pcre-8.41/
./configure --prefix=${HOME}/bin/pcre --host=arm-uclibc-linux
make && make install

Compile libev

Create a folder for compiled files

1
mkdir -p ${HOME}/bin/ev

Clone source code with

1
git clone https://github.com/shadowsocks/libev

Compile

1
2
3
cd libev/
./configure --prefix=${HOME}/bin/ev --host=arm-uclibc-linux
make && make install

Compile libsodium

Create a folder for compiled files

1
mkdir -p ${HOME}/bin/sodium

Download source code with

1
wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.16.tar.gz

Unzip the archive

1
tar xvf libsodium-1.0.16.tar.gz

Compile

1
2
3
cd libsodium-1.0.16/
./configure --prefix=${HOME}/bin/sodium --host=arm-uclibc-linux
make && make install

Compile c-ares

Create a folder for compiled files

1
mkdir -p ${HOME}/bin/c-ares

Download source code with

1
wget https://github.com/c-ares/c-ares/files/1731591/c-ares-1.14.0.tar.gz

Unzip the archive

1
tar xvf c-ares-1.14.0.tar.gz

Compile

1
2
3
cd c-ares-1.14.0/
./configure --prefix=/home/ubuntu/bin/c-ares --host=arm-uclibc-linux
make && make install

Compile shadowsocks-libev

Create a folder for compiled files

1
mkdir -p ${HOME}/bin/ss

Download source code with

1
git clone https://github.com/shadowsocks/shadowsocks-libev.git

Compile

1
2
3
4
5
cd shadowsocks-libev/
git submodule update --init --recursive
./autogen.sh
./configure --prefix=${HOME}/bin/ss --with-mbedtls=${HOME}/bin/mbedtls --with-pcre=${HOME}/bin/pcre --with-sodium=${HOME}/bin/sodium --with-cares=${HOME}/bin/c-ares --with-ev=${HOME}/bin/ev --disable-ssp --host=arm-uclibc-linux
make && make install

Compress binary files

We can find the binary files in ${HOME}/bin/ss/bin. Those binary files looks fat for router, they need lose some weight.

Use commands below to reduce binary files size.

1
2
3
4
5
cd ${HOME}/bin/ss/bin
arm-uclibc-strip ss-local ss-manager ss-redir ss-server ss-tunnel

cd ${HOME}/bin/ss/lib
arm-uclibc-strip libshadowsocks-libev.a

Done! We have a arm version Shadowsocks here. You can upload it to your Asus router and have fun.