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 line1
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 with1
wget http://dlcdnet.asus.com/pub/ASUS/wireless/RT-AC1200G+/GPL_RT_AC1200GPlus_300438250624.zip
Unzip the archive to /opt folder1
2unzip 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 | export PATH=$PATH:/opt/asuswrt/release/src-rt-9.x/src/toolchains/hndtools-arm-linux-2.6.36-uclibc-4.5.3/bin |
Compile zlib
Create a folder for compiled files1
mkdir -p ${HOME}/bin/zlib
Download source code with1
wget https://zlib.net/zlib-1.2.11.tar.gz
Unzip the archive1
tar xvzf zlib-1.2.11.tar.gz
Compile1
2
3cd zlib-1.2.11/
./configure --prefix=${HOME}/bin/zlib
make && make install
Compile mbedtls
Create a folder for compiled files1
mkdir -p ${HOME}/bin/mbedtls
Download source code with1
wget https://tls.mbed.org/download/mbedtls-2.11.0-apache.tgz
Unzip the archive1
tar zxvf mbedtls-2.11.0-apache.tgz
Edit MakeFile1
2
3
4cd mbedtls-2.11.0/
vim Makefile
# Change second line to
DESTDIR=${HOME}/bin/mbedtls
Save file and exit vim.
Compile1
make && make install
Compile pcre
Create a folder for compiled files1
mkdir -p ${HOME}/bin/pcre
Download source code with1
wget http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-8.41.zip
Unzip the archive1
unzip pcre-8.41.zip
Compile1
2
3cd pcre-8.41/
./configure --prefix=${HOME}/bin/pcre --host=arm-uclibc-linux
make && make install
Compile libev
Create a folder for compiled files1
mkdir -p ${HOME}/bin/ev
Clone source code with1
git clone https://github.com/shadowsocks/libev
Compile1
2
3cd libev/
./configure --prefix=${HOME}/bin/ev --host=arm-uclibc-linux
make && make install
Compile libsodium
Create a folder for compiled files1
mkdir -p ${HOME}/bin/sodium
Download source code with1
wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.16.tar.gz
Unzip the archive1
tar xvf libsodium-1.0.16.tar.gz
Compile1
2
3cd libsodium-1.0.16/
./configure --prefix=${HOME}/bin/sodium --host=arm-uclibc-linux
make && make install
Compile c-ares
Create a folder for compiled files1
mkdir -p ${HOME}/bin/c-ares
Download source code with1
wget https://github.com/c-ares/c-ares/files/1731591/c-ares-1.14.0.tar.gz
Unzip the archive1
tar xvf c-ares-1.14.0.tar.gz
Compile1
2
3cd 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 files1
mkdir -p ${HOME}/bin/ss
Download source code with1
git clone https://github.com/shadowsocks/shadowsocks-libev.git
Compile1
2
3
4
5cd 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
5cd ${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.