Email
Enterprise Service
menu
Email
Enterprise Service
Submit
Basic information
Waiting for a reply
Your form has been submitted. We'll contact you in 24 hours.
Close
Home/ Blog/ Installing Shadowsocks Server on OpenWrt

Installing Shadowsocks Server on OpenWrt

Author:PYPROXY
2024-09-05 15:22:43

Installing Shadowsocks Server on OpenWrt


OpenWrt is a powerful, open-source router firmware that provides advanced features and flexibility, making it a popular choice for tech enthusiasts and network administrators. One of the many applications you can run on OpenWrt is Shadowsocks, a secure proxy protocol designed to protect privacy and circumvent internet censorship. This article will guide you through the process of installing and configuring a Shadowsocks server on OpenWrt.


Prerequisites

Before we start, ensure you have the following:

1. OpenWrt Installed: Make sure your router is running OpenWrt. You can check this by accessing the router's web interface, usually at `192.168.1.1`.

2. Internet Connection: Your router should be connected to the internet.

3. Basic Knowledge of SSH: Familiarity with the command line and SSH will be beneficial.


Step 1: Accessing Your Router

1. Connect to Your Router: Use an SSH client (like PuTTY for Windows or Terminal for macOS/Linux) to connect to your router. The command is as follows:

```bash

ssh root@192.168.1.1

```

Replace `192.168.1.1` with your router's IP address if it's different.

2. Log In: Enter your password when prompted. If you haven't changed it, the default password is usually empty.


Step 2: Updating Package Lists

Before installing any new packages, it's a good practice to update the package lists:

```bash

opkg update

```

This command fetches the latest package information from the OpenWrt repositories.


Step 3: Installing Shadowsocks

OpenWrt supports Shadowsocks through various packages. You can choose between Shadowsocks-libev and ShadowsocksR. Here, we will install Shadowsocks-libev, which is lightweight and efficient.

1. Install Shadowsocks-libev:

```bash

opkg install shadowsocks-libev-server

```

2. Install Additional Dependencies (if necessary):

You might need to install additional packages for DNS resolution and other functionalities:

```bash

opkg install dnsmasq-full

```


Step 4: Configuring Shadowsocks

After installation, you need to configure Shadowsocks. The configuration file is typically located at `/etc/shadowsocks-libev/config.json`. You can create or edit this file using a text editor like `vi` or `nano`.

1. Create/Edit the Configuration File:

```bash

vi /etc/shadowsocks-libev/config.json

```

If you prefer `nano`, install it first:

```bash

opkg install nano

```

Then open the file:

```bash

nano /etc/shadowsocks-libev/config.json

```

2. Add Configuration Settings: Here’s a sample configuration:

```json

{

"server": "0.0.0.0",

"server_port": 8388,

"local_address": "127.0.0.1",

"local_port": 1080,

"password": "your_password",

"timeout": 300,

"method": "aes-256-gcm",

"fast_open": false

}

```

- server: Set to `0.0.0.0` to listen on all interfaces.

- server_port: Choose a port (e.g., `8388`).

- password: Set a strong password for your Shadowsocks server.

- method: Choose an encryption method (e.g., `aes-256-gcm`).

3. Save and Exit: If using `vi`, press `Esc`, type `:wq`, and hit `Enter`. If using `nano`, press `Ctrl + X`, then `Y`, and `Enter` to save.


Step 5: Starting the Shadowsocks Server

Now that you have configured Shadowsocks, you can start the server:

```bash

/etc/init.d/shadowsocks-libev-server start

```

To ensure that Shadowsocks starts automatically on boot, run:

```bash

/etc/init.d/shadowsocks-libev-server enable

```


Step 6: Configuring Firewall Rules

You need to ensure that your router's firewall allows traffic on the Shadowsocks port. By default, OpenWrt uses `iptables` for firewall management.

1. Open Firewall Configuration:

```bash

vi /etc/config/firewall

```

2. Add a New Rule: Add the following lines to allow traffic on the Shadowsocks port:

```plaintext

config rule

option src 'wan'

option target 'ACCEPT'

option proto 'tcp'

option dest_port '8388'

option name 'Allow Shadowsocks'

```

Adjust the `dest_port` if you chose a different port in the configuration.

3. Save and Exit: Save the changes as before.

4. Restart the Firewall:

```bash

/etc/init.d/firewall restart

```


Step 7: Testing the Shadowsocks Server

To test if your Shadowsocks server is working correctly, you can use a Shadowsocks client on your device (Windows, macOS, Android, or iOS).

1. Download a Shadowsocks Client: Choose a client suitable for your platform. For example, you can use Shadowsocks for Windows or Shadowsocks for Android.

2. Configure the Client:

- Server Address: Enter your router's public IP address.

- Server Port: Use the port you set in the configuration (e.g., `8388`).

- Password: Use the password set in the configuration.

- Encryption Method: Match the method used in the server configuration (e.g., `aes-256-gcm`).

3. Connect: Start the Shadowsocks client and connect to the server. If everything is set up correctly, you should be able to access blocked content and enjoy a secure connection.


Step 8: Monitoring and Maintenance

After installation, it’s essential to monitor your Shadowsocks server for performance and security:

1. Check Logs: You can view the logs to troubleshoot any issues:

```bash

logread | grep shadowsocks

```

2. Update Regularly: Keep your OpenWrt firmware and Shadowsocks packages updated to ensure security and stability.

3. Change Passwords Regularly: To maintain security, change your Shadowsocks password periodically.


Conclusion

Installing a Shadowsocks server on OpenWrt is a straightforward process that enhances your internet privacy and allows you to bypass restrictions. With the steps outlined in this article, you can set up your own Shadowsocks server and enjoy secure browsing from any connected device. Always remember to keep your server updated and monitor its performance for the best experience.