Update the package list to ensure you have the latest available versions.
opkg update
Install the necessary kernel module for nftables.
opkg install kmod-nft-tproxy
For iptables (if you have OpenWrt version < 22.03.x) – iptables-mod-tproxy
.
Create the Clash directory and navigate to it.
mkdir -p /opt/clash
cd /opt/clash
Download the ssclash package and extract it.
curl -L https://github.com/zerolabnet/ssclash/releases/download/v1.1/ssclash-v1.1.tar.gz -o ssclash-v1.1.tar.gz
tar zxvf ssclash-v1.1.tar.gz
Move the necessary files to their respective directories.
mv rootfs/etc/init.d/clash /etc/init.d/
mv rootfs/opt/clash/* .
rm -rf rootfs
rm -rf ssclash-v1.1.tar.gz
Navigate to the bin
directory and download the Clash.Meta Kernel. Choose the appropriate architecture.
For amd64 architecture:
cd /opt/clash/bin
curl -L https://github.com/MetaCubeX/mihomo/releases/download/v1.18.7/mihomo-linux-amd64-compatible-v1.18.7.gz -o clash.gz
For mipsel_24kc architecture:
curl -L https://github.com/MetaCubeX/mihomo/releases/download/v1.18.7/mihomo-linux-mipsle-softfloat-v1.18.7.gz -o clash.gz
Need a different architecture? Visit the MetaCubeX Release Page and choose the one that matches your device.
Decompress the downloaded file and make it executable.
gunzip clash.gz
chmod +x clash
Enable the Clash service.
/etc/init.d/clash enable
I've written a simple interface for managing Clash from LUCI interface luci-app-ssclash
. Edit Clash config and Apply.
You can access the Dashboard at:
http://ROUTER_IP:9090/ui/
To remove Clash, stop the service, delete the related files and kernel module kmod-nft-tproxy
or iptables-mod-tproxy
.
/etc/init.d/clash stop
rm -f /etc/init.d/clash
rm -rf /opt/clash
rm -f /usr/share/luci/menu.d/luci-app-ssclash.json
rm -f /usr/share/rpcd/acl.d/luci-app-ssclash.json
rm -rf /www/luci-static/resources/view/ssclash
Extra info (optional): Automating Clash Rules Update in OpenWrt whenever the Internet interface is brought up
To automatically update the rules for Clash whenever the Internet interface is brought up in OpenWrt, follow these step:
- Open a terminal and create a new shell script named
40-clash_rules
in the/etc/hotplug.d/iface/
directory:
vi /etc/hotplug.d/iface/40-clash_rules
- Insert the following script content (change
api_base_url
if needed):
#!/bin/sh
# Add delay
sleep 10
# API IP address and port
api_base_url="http://192.168.1.1:9090"
# API URL
base_url="$api_base_url/providers/rules"
# Get JSON response with provider names
response=$(curl -s "$base_url")
# Extract provider names using standard utilities
providers=$(echo "$response" | grep -o '"name":"[^"]*"' | sed 's/"name":"\([^"]*\)"/\1/')
# Check if data retrieval was successful
if [ -z "$providers" ]; then
echo "Failed to retrieve providers or no providers found."
exit 1
fi
# Loop through each provider name and send PUT request to update
for provider in $providers; do
echo "Updating provider: $provider"
curl -X PUT "$base_url/$provider"
# Check success and output the result
if [ $? -eq 0 ]; then
echo "Successfully updated $provider"
else
echo "Failed to update $provider"
fi
done
- Save and exit the editor.
The script will now automatically run whenever the Internet interface is brought up. This ensures that the rules for Clash are updated as soon as the router is rebooted and connected to the Internet.