Configure Clash Nyanpasu on Linux

First Post:

Last Update:

Word Count:
1.4k

Read Time:
8 min

Page View: loading...

Choosing and Setting up Clash.Nyanpasu Client on Linux


This guide will walk you through setting up Clash.Nyanpasu on a Linux server without a graphical user interface. We’ll use the Mihomo core, and you’ll learn how to manage your proxy settings via the command line.

We recommend using Clash.Nyanpasu for its robust features and active development.

1. Determine Your System Architecture

First, identify your Linux server’s architecture to download the correct AppImage. For example, if you have an x86_64 Ubuntu server, you’ll download the amd64.AppImage.

To find your architecture, use the command:

1
uname -m

This will output something like x86_64, aarch64, etc.

2. Download Clash.Nyanpasu

Navigate to the Clash.Nyanpasu releases page. Find the latest pre-release or stable release and locate the .AppImage file corresponding to your architecture.

For example, for x86_64 (also known as amd64), you might download:

1
wget https://github.com/libnyanpasu/clash-nyanpasu/releases/download/pre-release/Clash.Nyanpasu_2.0.0-alpha+2c587d0_amd64.AppImage

Remember to replace the URL with the specific version you are downloading.

3. Extract the AppImage

AppImages are self-contained executables. While they can often be run directly on systems with FUSE set up, on servers without a graphical environment, you might encounter issues like:

1
2
3
4
5
6
7
8
9
$ ./Clash.Nyanpasu_2.0.0-alpha+2c587d0_amd64.AppImage
fuse: device not found, try 'modprobe fuse' first

Cannot mount AppImage, please check your FUSE setup.
You might still be able to extract the contents of this AppImage
if you run it with the --appimage-extract option.
See https://github.com/AppImage/AppImageKit/wiki/FUSE
for more information
open dir error: No such file or directory

And sudo modprobe fuse might not work if modprobe is not in your PATH or if you don’t have the necessary kernel modules.

To proceed without FUSE, extract the AppImage’s contents:

1
2
chmod +x Clash.Nyanpasu_2.0.0-alpha+2c587d0_amd64.AppImage
./Clash.Nyanpasu_2.0.0-alpha+2c587d0_amd64.AppImage --appimage-extract

This will create a squashfs-root directory in your current location.

4. Prepare Configuration Files

4.1 Locate the Mihomo Executable

After extraction, the Mihomo core executable (which Clash.Nyanpasu uses) will be located within the squashfs-root directory. Based on the example, it’s typically found at:

/workspace/squashfs-root/usr/bin/mihomo

(Note: The path in your system might vary if you extracted it elsewhere. Adjust /workspace/ accordingly.)

4.2 Create Configuration Directory

Create a directory for your Clash configuration files. We’ll use /etc/clash/ as the default in this guide:

1
sudo mkdir -p /etc/clash

4.3 Copy Configuration Files

Copy your config.yaml file (which you should have prepared beforehand, containing your proxy settings) into the /etc/clash/ directory.

1
sudo cp /path/to/your/config.yaml /etc/clash/config.yaml

Replace /path/to/your/config.yaml with the actual path to your configuration file.

4.4 GeoIP Database (MMDB)

Clash uses a GeoIP database (Country.mmdb) for IP-based routing. If you don’t have one, you’ll need to download it. Mihomo typically expects it in the same directory as your config.yaml.

You can download Country.mmdb from sources like:

  • Official MaxMind GeoLite2: You need to register for a free account to download GeoLite2-Country.mmdb, then rename it to Country.mmdb.
  • Third-party Mirrors (use with caution and verify integrity): Some Clash-related projects provide direct downloads. Search for “Country.mmdb download clash” to find reputable sources.

Once downloaded, copy it to your configuration directory:

1
sudo cp /path/to/your/Country.mmdb /etc/clash/Country.mmdb

5. Configure Shell Environment

To easily manage Clash and proxy settings, add the following functions to your ~/.bashrc file. This allows you to start Clash, and enable/disable proxy settings with simple commands.

Open ~/.bashrc with your preferred editor (e.g., nano or vim):

1
nano ~/.bashrc

Add the following lines to the end of the file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# --- Clash Functions ---
clash() {
local MIHOMO_BIN="/workspace/squashfs-root/usr/bin/mihomo" # Adjust this path if necessary
local DEFAULT_CONFIG_DIR="/etc/clash/"
local CUSTOM_CONFIG_DIR="$1" # First argument can be a custom config directory

# Check if mihomo executable exists
if [ ! -f "$MIHOMO_BIN" ]; then
echo "Error: Mihomo executable not found at $MIHOMO_BIN" >&2 # Output to standard error
return 1 # Return non-zero status code for failure
fi

# Determine which config directory to use
local CONFIG_TO_USE="$DEFAULT_CONFIG_DIR"
if [ -n "$CUSTOM_CONFIG_DIR" ]; then # If a custom config directory is provided
CONFIG_TO_USE="$CUSTOM_CONFIG_DIR"
echo "Using custom configuration directory: $CONFIG_TO_USE"
else
echo "Using default configuration directory: $DEFAULT_CONFIG_DIR"
fi

# Check if the config directory exists
if [ ! -d "$CONFIG_TO_USE" ]; then
echo "Error: Clash configuration directory not found at $CONFIG_TO_USE" >&2
echo "Please ensure this directory exists and contains a config.yaml file." >&2
return 1
fi

echo "Starting Mihomo..."
# Using exec ensures mihomo replaces the current shell process, so when mihomo exits, the function also ends.
# If you want mihomo to run in the background, remove 'exec' and add '&' at the end.
"$MIHOMO_BIN" -d "$CONFIG_TO_USE" "$@"
# "$@" passes all arguments of the function to mihomo, allowing you to run: clash /path/to/my/config --port 7890
echo "Mihomo started or exited."
}

# --- Proxy Control Functions ---
# Define a function to set system proxy to Clash
proxy_on() {
# Check if Clash's listening port is provided, otherwise use default
local CLASH_PORT=${1:-7890} # Default port is 7890

echo "Setting HTTP/HTTPS proxy to Clash (Port: $CLASH_PORT)..."

# Set HTTP and HTTPS proxy environment variables
# Ensure you use your actual Clash listening address, usually 127.0.0.1 (localhost)
export http_proxy="http://127.0.0.1:$CLASH_PORT"
export https_proxy="http://127.0.0.1:$CLASH_PORT"

# It's also often recommended to set all_proxy to cover more applications (e.g., curl)
export all_proxy="socks5://127.0.0.1:$CLASH_PORT" # Clash also listens on SOCKS5 proxy

# Set addresses that should not use the proxy, typically including localhost and private network addresses
# Traffic to these addresses usually doesn't need to be proxied and could cause issues otherwise
export no_proxy="localhost,127.0.0.1,::1,*.local,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"

echo "Proxy set successfully!"
echo " http_proxy: $http_proxy"
echo " https_proxy: $https_proxy"
echo " all_proxy: $all_proxy"
echo " no_proxy: $no_proxy"
}

# Define a function to turn off the proxy
proxy_off() {
echo "Turning off HTTP/HTTPS proxy..."

# Unset proxy environment variables
unset http_proxy
unset https_proxy
unset all_proxy
unset no_proxy

echo "Proxy turned off."
}

Save the file and exit the editor.

Apply the changes to your current session:

1
source ~/.bashrc

6. Running Clash with TMUX

Since you’re on a server without a GUI, you’ll want to run Clash in a detached session so it continues running even after you close your terminal. tmux is an excellent tool for this.

  1. Start a new tmux session:

    1
    tmux new -s clash

    You are now inside a new tmux session named clash.

  2. Start Clash:

    Inside the tmux session, run the clash function you defined:

    1
    clash

    You should see output indicating Mihomo is starting.

  3. Detach from the tmux session:

    Press Ctrl+b then d. You will be returned to your main shell, and Clash will continue running in the background within the tmux session.

7. Controlling the Proxy

From any other terminal window on your server (or your main shell after detaching from tmux):

  • To enable the proxy:

    1
    proxy_on

    You can optionally specify a port if your Clash instance is listening on something other than 7890: proxy_on 8888.

  • To disable the proxy:

    1
    proxy_off

8. Managing the Clash Session

  • To reattach to the Clash tmux session:

    1
    tmux attach -t clash
  • To stop Clash:

    If you are attached to the clash, you can stop Clash by pressing Ctrl+c in the terminal where Clash is running. This will terminate the Mihomo process and close the tmux pane.

  • To kill the tmux session (and Clash running within it):

    1
    tmux kill-session -t clash

This comprehensive setup allows you to efficiently manage Clash.Nyanpasu and your proxy settings on a headless Linux server.