dnspod-sr Documentation

repository·master·Indexed 23 days ago

https://github.com/dnspod/dnspod-sr

A high-performance, security-focused recursive DNS server for Linux designed for high-load environments. The project includes a server binary with configuration options for listening ports and external recursive DNS mapping, as well as a CLI client tool for performing hijacking operations and flushing DNS caches via Unix domain sockets.

Tokens
1.1K
Snippets
6
Records
9
Agent score
80%

What's inside dnspod-sr

  1. Get support and documentation for dnspod-sr

    master

    For further information, troubleshooting, or contributing, use the following resources:

    • Wiki: Detailed documentation is available on the project Wiki.
    • FAQ: Common questions and answers can be found in the FAQ section of the Wiki.
    • Issues: Report bugs or request features via the GitHub Issues page.
    • Feedback: Submit new feedback or issues directly through the GitHub issue creation interface.
  2. Quick Start: Install and run dnspod-sr

    master

    To use dnspod-sr, you can either clone the repository directly or download the source archive. Once you have the source code, compile it using make within the src directory and run the resulting binary.

    Installation via Git

    git clone https://github.com/DNSPod/dnspod-sr.git
    cd dnspod-sr

    Compilation

    Navigate to the src directory and run the make command:

    cd src
    make

    Running the server

    After successful compilation, execute the binary from the src directory:

    ./dnspod-sr
    cd src
    make
    ./dnspod-sr
  3. Configure dnspod-sr via config file

    master

    The application looks for a default configuration file named sr.conf. You can specify a custom path using the -c flag.

    Configuration Keys

    KeyDescription
    listenThe port to listen on (e.g., listen:9054).
    log_path(Optional) The directory where logs will be stored (e.g., log_path: ./log/).
    rootThe filename for the root file (e.g., root:root.z).
    recordsThe filename for the records file (e.g., records:records.z).
    xferA section used to specify external recursive DNS for specific domain names.

    Using the xfer section

    In the xfer section, map domain names to specific external DNS servers. Each entry follows the format domain.:IP. The section must end with a single : on a new line.

    # Example configuration
    listen:9054
    log_path:
    ./log/
    root:root.z
    records:records.z
    
    xfer:
    googleusercontent.com.:8.8.8.8
    google.com.:8.8.8.8
    youtube.com.:8.8.8.8
    s-static.ak.facebook.com.edgekey.net.:8.8.8.8
    :
  4. Use the client tool for hijacking and cache flushing

    master

    The client tool provides a command-line interface to perform hijacking operations or flush specific DNS caches.

    • To initiate a general hijack: ./client "hijack"
    • To initiate a hijack for a specific domain: ./client "hijack <domain>"
    • To flush the cache for a specific domain: ./client "cache flush: <domain>"
    ./client "hijack"
    ./client "hijack example.com"
    ./client "cache flush: example.com"
  5. Use dnspod-sr command line options

    master

    The dnspod-sr binary supports the following command line flags:

    • -c: Specify a custom configuration file.
    • -h: Display the help message.
    • -f: Forward mode.
    • -d: Run as a daemon.
    • -v: Print the version information.
  6. Use the CLI client to send a command

    master

    The CLI tool interacts with the DNS server by taking a single command-line argument and sending it over a Unix domain socket. The server's default socket path is /tmp/foo.socket.

    Usage:

    ./client <command>

    Behavior:

    1. Connects to the server via the Unix socket.
    2. Sends the provided argument as a string.
    3. Waits for a response from the server.
    4. Prints the response to stdout and exits.
    5. If the connection fails or the server disconnects, it prints an error message and exits.
  7. Create a local client connection with create_local_client()

    master

    The create_local_client function establishes a connection to the DNS server using a Unix domain socket. It follows a two-step process: first, it creates a temporary local socket bound to a path in /tmp/ based on the current process ID, and then it connects that socket to the provided name (the server's socket path).

    Returns:

    • sock: A valid file descriptor for the connected socket on success.
    • -1: Socket creation error.
    • -2: Bind error.
    • -3: Connection error.
    int create_local_client(const char *name)
  8. Handle SIGPIPE signals with set_signal_catcher()

    master

    The set_signal_catcher function configures the process to ignore SIGPIPE signals. This is used to prevent the client from terminating abruptly if it attempts to write to a socket that has been closed by the server.

    void set_signal_catcher()