For the complete documentation index, see llms.txt. This page is also available as Markdown.

Mihomo

Mihomo is a derivative of the Clash series and has been included in the FreeBSD Ports tree (net/mihomo). This section provides installation and basic configuration steps.

Installing Mihomo

Install using pkg:

# pkg install mihomo

Or install using Ports:

# cd /usr/ports/net/mihomo/
# make install clean

Mihomo File Structure

The Mihomo file structure is as follows:

/usr/
├── ports/
   └── net/
       └── mihomo/ # Mihomo Ports directory
├── local/
   ├── bin/
      └── mihomo # Mihomo executable
   └── etc/
       └── rc.d/
           └── mihomo # Mihomo RC service script
└── etc/
    └── rc.conf # System service configuration file

Mihomo can also run the Linux version through FreeBSD's Linux binary compatibility layer, but it is recommended to prioritize the native FreeBSD version (net/mihomo); the compatibility layer should only be used as a fallback.

RC Script

A merge request has been submitted to the Ports maintainer (Bug 291295 - net/mihomo: Add rc.conf and some Post-installation) to add system service management support for Mihomo. As of writing, no response has been received. Until official integration is complete, you can use the custom RC script provided below for service management.

Custom RC Script

To facilitate Mihomo service management, you can use the following script. Save the script below as mihomo and place it in /usr/local/etc/rc.d/, then grant executable permissions using the root account: chmod +x /usr/local/etc/rc.d/mihomo.

Available Parameters and Options

The RC script provides multiple command-line parameters and configuration options. The commonly used parameters are listed below. These commands write the configuration directly to the /etc/rc.conf file; if the configuration is incorrect, you can directly modify the corresponding line.

  • Enable the Mihomo service and set it to start automatically at boot:

  • Start the Mihomo service process:

  • Stop the Mihomo service process:

  • Check the Mihomo service running status:

  • Specify the subscription link address (the example address is for demonstration purposes only and must be replaced with a valid link):

  • GeoIP data implements traffic routing or rule matching based on the geographic attribution of IP addresses:

  • Specify extra parameters for Mihomo:

  • -m: Enables geodata mode, making Mihomo use geoip.dat and geosite.dat files (DAT format) for rule matching instead of the default MMDB format (Country.mmdb).

  • Specify the user identity for running the Mihomo service:

  • Specify the Mihomo data directory:

Related file structure:

  • Initialize the Mihomo data directory and prepare the service runtime environment:

  • Update the subscription configuration. Run this before start to ensure the configuration file is the latest version:

  • Update the GeoIP geographic location database:

Minimal RC Example

The following is a minimal configuration example that can be modified as needed after understanding its meaning and written to the /etc/rc.conf file:

Unfinished Items

The following are issues to be investigated:

  • How to implement traffic routing for "direct," "proxy," and "global" modes?

  • How to implement TUN virtual network interface proxy? TUN mode can achieve lower-level network traffic interception.

  • How to test node speeds using a subscription link?

  • How to specify a particular node from a proxy group in the subscription link (e.g., using only a proxy node located in the US)? This involves fine-grained proxy node selection.

Clash for FreeBSD

Environment Preparation

FreeBSD's default login shell is sh, not bash. Before executing the following commands, you must first switch to bash:

It is recommended to use a root privileged account.

Notes:

  • The current script is executed via bash.

  • The freebsd-rc backend depends on service and /usr/local/etc/rc.d.

Installation and Initialization

First-time configuration:

FreeBSD Service Management (rc.d)

The system installation uses the freebsd-rc backend by default, with the service name: clash_freebsd.

Manage kernel service auto-start at boot:

Notes:

  • clashctl autostart on only controls whether the rc.d service starts with the system.

  • service and autostart commands require root privileges (use root or sudo).

  • FreeBSD auto-start configuration file: /etc/rc.conf.d/clash_freebsd.

Tun and Route Diagnostics (FreeBSD)

Tun devices are typically /dev/tun*.

When Tun is not working, check first:

  • tun on/off requires root privileges

  • ls -l /dev/tun*

  • Current user permissions (root recommended)

  • Whether the default route has been taken over by the tun interface

Common Troubleshooting Commands

Uninstallation

For a thorough cleanup of runtime data:

References

  • wenyinos. A more complete and elegant FreeBSD Clash / Mihomo runtime platform[EB/OL]. [2026-04-26]. https://github.com/wenyinos/clash-freebsd. Provides a complete deployment solution for Clash proxy on FreeBSD, supporting subscription link management.

Unfinished Items

Decouple from Bash, support the default sh, and better adapt to the FreeBSD default environment.

Last updated