### Start Daemon Service Source: https://context7.com/gravitl/netclient/llms.txt Starts the Netclient daemon as a system service. An error is returned if the daemon fails to start. ```go import "github.com/gravitl/netclient/daemon" // Start the daemon service err := daemon.Start() if err != nil { log.Fatalf("failed to start daemon: %v", err) } ``` -------------------------------- ### Install Daemon as System Service Source: https://context7.com/gravitl/netclient/llms.txt Installs the Netclient daemon as a system service, allowing it to run automatically on boot. An error is returned if the installation fails. ```go import "github.com/gravitl/netclient/daemon" // Install daemon as system service err := daemon.Install() if err != nil { log.Fatalf("failed to install daemon: %v", err) } ``` -------------------------------- ### Install Netclient Source: https://context7.com/gravitl/netclient/llms.txt Installs the netclient binary and configures it as a system daemon. Supports custom WireGuard listen ports, interface names, and firewall marks. ```bash # Install netclient as a system service ./netclient install ``` ```bash # Install with a specific WireGuard listen port ./netclient install -p 51822 ``` ```bash # Install with a custom interface name ./netclient install -I netmaker-custom ``` ```bash # Install with a specific firewall mark for traffic ./netclient install -F 100 ``` -------------------------------- ### Install Dependencies for Head Build (Linux) Source: https://github.com/gravitl/netclient/blob/develop/build_notes.md Installs npm and essential build tools for a graphical interface build. Ensure you have sufficient disk space and a stable internet connection. ```bash sudo apt-get install npm build-essential libgtk3 libwebkit libx11-dev ``` ```bash sudo apt-get install npm build-essential libgtk-3-dev libwebkit2gtk-4.0 libx11-dev ``` -------------------------------- ### Install Dependencies for Headless Build (Linux) Source: https://github.com/gravitl/netclient/blob/develop/build_notes.md Installs only the essential build tools for a non-graphical environment. This is suitable for server or CI/CD pipelines. ```bash sudo apt-get install build-essential ``` -------------------------------- ### Get and Manage Server Configuration Source: https://context7.com/gravitl/netclient/llms.txt Retrieve the current server configuration, list registered servers, and update server details. Remember to write the server configuration to disk after modifications. ```go import "github.com/gravitl/netclient/config" // Get current server server := config.GetServer(config.CurrServer) if server != nil { fmt.Printf("Server: %s\n", server.Name) fmt.Printf("API: %s\n", server.API) fmt.Printf("Broker: %s\n", server.Broker) fmt.Printf("Is Pro: %t\n", server.IsPro) fmt.Printf("Manages DNS: %t\n", server.ManageDNS) } // List all servers for name := range config.Servers { fmt.Printf("Registered server: %s\n", name) } // Save server config config.UpdateServer(server.Name, *server) config.WriteServerConfig() ``` -------------------------------- ### Start Netclient Daemon Source: https://context7.com/gravitl/netclient/llms.txt Initiates the Netclient daemon, which manages continuous operations such as MQTT communication, peer updates, and network monitoring. This is a blocking call. ```go import "github.com/gravitl/netclient/functions" // Start the daemon (blocking call) // Handles: // - MQTT message queue for server communication // - Periodic check-ins with server // - Peer connection monitoring // - Firewall rule management // - DNS configuration functions.Daemon() ``` -------------------------------- ### Run Netclient Daemon Source: https://context7.com/gravitl/netclient/llms.txt Starts the netclient daemon process for continuous network management. This is typically managed by system init services like systemd. ```bash # Start daemon (usually called by systemd/init) netclient daemon ``` -------------------------------- ### Get and Manage Nodes Source: https://context7.com/gravitl/netclient/llms.txt Retrieve and iterate through all network nodes, or fetch and update a specific node by its network name. Ensure to write changes to the configuration file after updates. ```go import "github.com/gravitl/netclient/config" // Get all nodes nodes := config.GetNodes() for network, node := range nodes { fmt.Printf("Network: %s\n", network) fmt.Printf(" Node ID: %s\n", node.ID) fmt.Printf(" Address: %s\n", node.Address) fmt.Printf(" Address6: %s\n", node.Address6) fmt.Printf(" Connected: %t\n", node.Connected) fmt.Printf(" Server: %s\n", node.Server) } // Get a specific node node := config.GetNode("my-network") if node.Network != "" { fmt.Printf("Found node for network: %s\n", node.Network) } // Update a node node.Connected = false config.UpdateNodeMap(node.Network, node) config.WriteNodeConfig() ``` -------------------------------- ### Update Netclient Configuration in Go Source: https://context7.com/gravitl/netclient/llms.txt Shows how to modify and persist netclient configuration changes using the Go API. It involves getting the current config, updating fields like Name and ListenPort, and then writing the changes back to disk. ```go import "github.com/gravitl/netclient/config" // Get current config netclient := config.Netclient() // Modify settings netclient.Name = "new-hostname" netclient.ListenPort = 51822 netclient.Verbosity = 3 // Update in-memory config config.UpdateNetclient(*netclient) // Persist to disk if err := config.WriteNetclientConfig(); err != nil { log.Fatalf("failed to write config: %v", err) } ``` -------------------------------- ### Restart Daemon Service Source: https://context7.com/gravitl/netclient/llms.txt Restarts the Netclient daemon service. If the restart fails, it attempts to start the daemon. An error is returned if both operations fail. ```go import "github.com/gravitl/netclient/daemon" // Restart the daemon service err = daemon.Restart() if err != nil { // Try starting if restart failed if startErr := daemon.Start(); startErr != nil { log.Fatalf("failed to restart daemon: %v", startErr) } } ``` -------------------------------- ### Register with SSO or Basic Authentication Source: https://context7.com/gravitl/netclient/llms.txt Register a host using either Single Sign-On (SSO) or basic authentication credentials. Configure whether to register for all networks or a specific one. ```go import "github.com/gravitl/netclient/functions" // SSO registration regData := functions.RegisterSSO{ API: "api.mynetmaker.com", Network: "my-network", AllNetworks: false, UsingSSO: true, } err := functions.RegisterWithSSO(®Data) if err != nil { log.Fatalf("SSO registration failed: %v", err) } // Basic auth registration regData := functions.RegisterSSO{ API: "api.mynetmaker.com", Network: "my-network", User: "admin", Pass: "password", UsingSSO: false, } err := functions.RegisterWithSSO(®Data) ``` -------------------------------- ### Push Configuration to Server Source: https://context7.com/gravitl/netclient/llms.txt Uploads the local configuration to the server. The `restart` parameter indicates whether the daemon should restart after the push operation. ```go import "github.com/gravitl/netclient/functions" // Push local configuration to server // restart: whether to restart daemon after push err = functions.Push(true) if err != nil { log.Fatalf("push failed: %v", err) } ``` -------------------------------- ### Build Netclient (Go) Source: https://github.com/gravitl/netclient/blob/develop/build_notes.md Executes the Go build command to compile the Netclient application. This command should be run in the project's root directory. ```go go build ``` -------------------------------- ### Create and Configure WireGuard Interface Source: https://context7.com/gravitl/netclient/llms.txt Create a new WireGuard interface, configure it with necessary addresses, and manage its lifecycle by closing it when no longer needed. Error handling is crucial for interface operations. ```go import ( "github.com/gravitl/netclient/config" "github.com/gravitl/netclient/wireguard" ) // Create a new WireGuard interface netclient := config.Netclient() nodes := config.GetNodes() nc := wireguard.NewNCIface(netclient, nodes) if err := nc.Create(); err != nil { log.Fatalf("failed to create interface: %v", err) } // Configure the interface with addresses if err := nc.Configure(); err != nil { log.Fatalf("failed to configure interface: %v", err) } // Get the interface instance iface := wireguard.GetInterface() fmt.Printf("Interface name: %s\n", iface.Name) // Close the interface iface.Close() ``` -------------------------------- ### Read Netclient Configuration in Go Source: https://context7.com/gravitl/netclient/llms.txt Demonstrates how to read the current netclient configuration using the Go API. It accesses configuration values like Host ID, Name, Interface, and Public Key. Ensure correct OS-specific paths are used. ```go // Config paths by OS // Linux: /etc/netclient/netclient.json // macOS: /Applications/Netclient/netclient.json // Windows: C:\\Program Files (x86)\\Netclient\\netclient.json // Read current configuration cfg, err := config.ReadNetclientConfig() if err != nil { log.Fatalf("failed to read config: %v", err) } // Access configuration values fmt.Printf("Host ID: %s\n", cfg.ID) fmt.Printf("Host Name: %s\n", cfg.Name) fmt.Printf("Interface: %s\n", cfg.Interface) fmt.Printf("Listen Port: %d\n", cfg.ListenPort) fmt.Printf("Public Key: %s\n", cfg.PublicKey.Key.String()) fmt.Printf("Endpoint IP: %s\n", cfg.EndpointIP) fmt.Printf("MTU: %d\n", cfg.MTU) fmt.Printf("Firewall: %s\n", cfg.FirewallInUse) ``` -------------------------------- ### Register Host with Server Source: https://context7.com/gravitl/netclient/llms.txt Register the current host with a Netmaker server using an enrollment token. Ensure the token is valid and contains the correct server API endpoint. ```go import "github.com/gravitl/netclient/functions" // Register using enrollment token token := "eyJzZXJ2ZXIiOiJhcGkubXluZXRtYWtlci5jb20iLCJ2YWx1ZSI6IjEyMzQ1Njc4OTAifQ==" err := functions.Register(token) if err != nil { log.Fatalf("registration failed: %v", err) } ``` -------------------------------- ### Switch Netclient Version Source: https://context7.com/gravitl/netclient/llms.txt Downloads and switches to a specific version of the netclient binary. Note that this command is skipped inside containers; image updates are recommended instead. ```bash # Switch to a specific version netclient use v0.24.0 ``` -------------------------------- ### Netclient CLI Usage Source: https://github.com/gravitl/netclient/blob/develop/README.md The Netclient CLI allows you to manage WireGuard networks. Use '--help' for command-specific details. ```bash Netmaker's netclient agent and CLI to manage wireguard networks Join, leave, connect and disconnect from netmaker wireguard networks. Usage: netclient [command] Available Commands: completion Generate the autocompletion script for the specified shell connect connect to a netmaker network daemon netclient daemon disconnect disconnet from a network help Help about any command install install netclient binary and daemon join join a network leave leave a network list display list of netmaker networks pull get the latest node configuration uninstall uninstall netclient version Displays version information Flags: --config string use specified config file -h, --help help for netclient -v, --verbosity int set logging verbosity 0-4 Use "netclient [command] --help" for more information about a command. ``` -------------------------------- ### Join Netmaker Network with Token Source: https://github.com/gravitl/netclient/blob/develop/README.md Use this command to join a Netmaker network when you have an authentication token. ```bash netclient join -t ``` -------------------------------- ### Join Netmaker Network with User (Basic Auth) Source: https://github.com/gravitl/netclient/blob/develop/README.md Use this command to join a Netmaker network using your username and a Netmaker domain, with basic authentication. ```bash netclient join -n -u -s api. ``` -------------------------------- ### Join Netmaker Network with User (SSO) Source: https://github.com/gravitl/netclient/blob/develop/README.md Use this command to join a Netmaker network using your username and a Netmaker domain, with Single Sign-On (SSO). ```bash netclient join -n -s api. ``` -------------------------------- ### Pull Configuration from Server Source: https://context7.com/gravitl/netclient/llms.txt Fetches the latest configuration from the server. The `restart` parameter determines if the daemon should restart after the pull, and `resetIfFailedOvered` resets the failover state. ```go import "github.com/gravitl/netclient/functions" // Pull latest configuration from server // restart: whether to restart daemon after pull // resetIfFailedOvered: reset failover state pullResp, resetInterface, replacePeers, err := functions.Pull(false, true) if err != nil { log.Fatalf("pull failed: %v", err) } fmt.Printf("Pulled %d nodes\n", len(pullResp.Nodes)) fmt.Printf("Pulled %d peers\n", len(pullResp.Peers)) fmt.Printf("Reset interface: %t\n", resetInterface) fmt.Printf("Replace peers: %t\n", replacePeers) ``` -------------------------------- ### Manage WireGuard Peers Source: https://context7.com/gravitl/netclient/llms.txt Manage WireGuard peers by setting all peers, updating a single peer with its configuration, retrieving peers from a device, or fetching a specific peer. Ensure to handle potential errors like 'ErrPeerNotFound'. ```go import ( "github.com/gravitl/netclient/config" "github.com/gravitl/netclient/wireguard" "github.com/gravitl/netclient/ncutils" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) // Set peers (replaces all existing peers) err := wireguard.SetPeers(true) if err != nil { log.Fatalf("failed to set peers: %v", err) } // Update a single peer peer := wgtypes.PeerConfig{ PublicKey: pubKey, Endpoint: endpoint, AllowedIPs: allowedIPs, } err = wireguard.UpdatePeer(&peer) if err != nil { log.Fatalf("failed to update peer: %v", err) } // Get peers from the device ifaceName := ncutils.GetInterfaceName() peers, err := wireguard.GetPeersFromDevice(ifaceName) if err != nil { log.Fatalf("failed to get peers: %v", err) } for pubKey, peer := range peers { fmt.Printf("Peer: %s\n", pubKey) fmt.Printf(" Endpoint: %s\n", peer.Endpoint) fmt.Printf(" Last Handshake: %s\n", peer.LastHandshakeTime) fmt.Printf(" Received: %d bytes\n", peer.ReceiveBytes) fmt.Printf(" Transmitted: %d bytes\n", peer.TransmitBytes) } // Get a specific peer peer, err := wireguard.GetPeer(ifaceName, "publicKeyString") if err != nil { if errors.Is(err, wireguard.ErrPeerNotFound) { fmt.Println("Peer not found") } } ``` -------------------------------- ### Switch Server Connection Source: https://context7.com/gravitl/netclient/llms.txt Changes the active server connection to a different registered server. Provide the name of the target server. An error is returned if the switch fails. ```go import "github.com/gravitl/netclient/functions" // Switch to a different server err = functions.SwitchServer("staging-server") if err != nil { log.Fatalf("switch server failed: %v", err) } ``` -------------------------------- ### Push Netclient Configuration Source: https://context7.com/gravitl/netclient/llms.txt Updates the Netmaker server with the current host configuration. Options allow specifying endpoint IP, hostname, listen port, and firewall type. ```bash # Push current host config to server netclient push ``` ```bash # Push with updated endpoint IP netclient push -e 203.0.113.10 ``` ```bash # Push with updated hostname netclient push -o new-hostname ``` ```bash # Push with new listen port netclient push -p 51823 ``` ```bash # Push with firewall selection netclient push -f iptables ``` -------------------------------- ### List Netmaker Networks Source: https://context7.com/gravitl/netclient/llms.txt Displays information about connected networks. Use the long flag for detailed peer information. Output is in JSON format. ```bash # List all networks netclient list ``` ```json # Output (JSON format): # [ # { # "network": "my-network", # "node_id": "abc12345-1234-5678-abcd-1234567890ab", # "connected": true, # "ipv4_addr": "10.10.10.5/24", # "ipv6_addr": "fd00::5/64" # } # ] ``` ```bash # List a specific network with detailed peer info netclient list my-network -l ``` ```json # Output with peers: # [ # { # "network": "my-network", # "node_id": "abc12345-1234-5678-abcd-1234567890ab", # "connected": true, # "ipv4_addr": "10.10.10.5/24", # "ipv6_addr": "fd00::5/64", # "peers": [ # { # "public_key": "aB1cD2eF3gH4iJ5kL6mN7oP8qR9sT0uV1wX2yZ3=", # "endpoint": "198.51.100.20:51821", # "allowed_ips": ["10.10.10.10/32"] # } # ] # } # ] ``` -------------------------------- ### List Registered Servers Source: https://context7.com/gravitl/netclient/llms.txt Retrieves a list of all servers that the Netclient is currently registered with. This function does not take any arguments and returns an error if the operation fails. ```go import "github.com/gravitl/netclient/functions" // List all registered servers err := functions.ListServers() // Output: // registered servers: // // active: production-server // staging-server ``` -------------------------------- ### Connect and Disconnect from Network Source: https://context7.com/gravitl/netclient/llms.txt Control the network connectivity of the host by connecting to a specified network or disconnecting from it. Ensure proper error handling for these operations. ```go import "github.com/gravitl/netclient/functions" // Connect to a network err := functions.Connect("my-network") if err != nil { log.Fatalf("connect failed: %v", err) } fmt.Println("Connected to my-network") // Disconnect from a network err = functions.Disconnect("my-network") if err != nil { log.Fatalf("disconnect failed: %v", err) } fmt.Println("Disconnected from my-network") ``` -------------------------------- ### Connect to Netmaker Network Source: https://context7.com/gravitl/netclient/llms.txt Enables connectivity to a network that was previously disconnected. Updates the node status and restarts the daemon. If no network is specified, it lists available networks. ```bash # Connect to a network netclient connect my-network ``` ```bash # Output on success: # connect called [my-network] # node is connected to my-network ``` ```bash # If network not specified, shows available networks: # Please specify the network name as the argument. For example: netclient connect my-network # # Available Networks: # production-network # development-network ``` -------------------------------- ### View Network Peers Source: https://context7.com/gravitl/netclient/llms.txt Displays a list of peers for a specific network or all networks. Use the -j flag for JSON output. ```bash netclient peers my-network ``` ```bash netclient peers -j ``` ```bash netclient peers my-network -j ``` -------------------------------- ### Uninstall Netclient Source: https://context7.com/gravitl/netclient/llms.txt Completely removes the netclient application and all associated configuration files from the system. ```bash # Uninstall netclient netclient uninstall ``` -------------------------------- ### Pull Netclient Configuration Source: https://context7.com/gravitl/netclient/llms.txt Retrieves the latest host configuration and peer list from the Netmaker server. This command ensures your local netclient is up-to-date with the server's desired state. ```bash # Pull latest configuration netclient pull ``` -------------------------------- ### Join Netmaker Network Source: https://context7.com/gravitl/netclient/llms.txt Joins a Netmaker network using enrollment tokens, SSO, or basic authentication. Supports custom host settings including endpoint, port, hostname, interface name, and firewall type. ```bash # Join using an enrollment token (most common) netclient join -t eyJzZXJ2ZXIiOiJhcGkubXluZXRtYWtlci5jb20iLCJ2YWx1ZSI6IjEyMzQ1Njc4OTAifQ== ``` ```bash # Join via SSO (OAuth) - opens browser for authentication netclient join -s api.mynetmaker.com ``` ```bash # Join a specific network via SSO netclient join -s api.mynetmaker.com -n my-network ``` ```bash # Join via basic auth with username/password netclient join -s api.mynetmaker.com -u admin -n my-network # (prompts for password) ``` ```bash # Join all available networks on a server netclient join -s api.mynetmaker.com -A ``` ```bash # Join with custom host settings netclient join -t \ -e 203.0.113.10 \ -p 51822 \ -o my-hostname \ -I netmaker-vpn \ -f nftables ``` -------------------------------- ### Show Netclient Peer Information Source: https://context7.com/gravitl/netclient/llms.txt Displays detailed WireGuard peer information including connection status, traffic statistics, and handshake times for all networks. ```bash # Show all peers across all networks netclient peers ``` ```text # Output: # Interface: netmaker # Interface Port: 51821 # Interface Public Key: aB1cD2eF3gH4iJ5kL6mN7oP8qR9sT0uV1wX2yZ3= # # Network: my-network # +-------+---------+---------------+------------------+---------------------+----------------+----------+--------+-----------+------------------+ ``` -------------------------------- ### Clean Up Daemon Files Source: https://context7.com/gravitl/netclient/llms.txt Removes Netclient daemon files and configurations. Use this for cleanup operations. An error is returned if the cleanup process fails. ```go import "github.com/gravitl/netclient/daemon" // Clean up daemon files err := daemon.CleanUp() if err != nil { log.Fatalf("failed to clean up: %v", err) } ``` -------------------------------- ### Leave Netmaker Network Source: https://context7.com/gravitl/netclient/llms.txt Removes the host from a specific network, deleting the node from the server and cleaning up local configuration. ```bash # Leave a specific network netclient leave my-network ``` ```bash # Expected output on success: # leave called # successfully left network my-network ``` -------------------------------- ### Customize Excluded Interfaces Source: https://github.com/gravitl/netclient/blob/develop/README.md Set the NETCLIENT_EXCLUDE_INTERFACES environment variable to a comma-separated list of interface name patterns to exclude them from being advertised to peers. Default is 'flannel,cni'. ```bash NETCLIENT_EXCLUDE_INTERFACES=flannel,cni,calico,weave ``` -------------------------------- ### Leave Server Connection Source: https://context7.com/gravitl/netclient/llms.txt Removes a server connection and all associated networks from the Netclient configuration. Use this when a server is no longer needed. An error is returned if the operation fails. ```go import "github.com/gravitl/netclient/functions" // Leave a server (removes all networks on that server) err = functions.LeaveServer("old-server") if err != nil { log.Fatalf("leave server failed: %v", err) } ``` -------------------------------- ### Exclude Network Interfaces (Bash) Source: https://context7.com/gravitl/netclient/llms.txt Configures Netclient to exclude specific network interfaces from being advertised to peers. This is done by setting the `NETCLIENT_EXCLUDE_INTERFACES` environment variable with a comma-separated list of interface name patterns. ```bash # Exclude specific network interfaces from being advertised to peers # Comma-separated list of interface name patterns (substring match) # Default: flannel,cni export NETCLIENT_EXCLUDE_INTERFACES=flannel,cni,calico,weave,docker0 # Example: Exclude all Docker and Kubernetes interfaces export NETCLIENT_EXCLUDE_INTERFACES=docker,veth,cni,flannel,calico ``` -------------------------------- ### Disconnect from Netmaker Network Source: https://context7.com/gravitl/netclient/llms.txt Temporarily disconnects from a network without leaving it, preserving configuration for later reconnection. If no network is specified, it lists available networks. ```bash # Disconnect from a network netclient disconnect my-network ``` ```bash # Output on success: # disconnect called [my-network] # node is disconnected from my-network ``` ```bash # If network not specified, shows available networks: # Please specify the network name as the argument. For example: netclient disconnect my-network # # Available Networks: # production-network # development-network ``` -------------------------------- ### Leave Network Source: https://context7.com/gravitl/netclient/llms.txt Removes a host from a specified network. Use when a host should no longer be part of a network. The `isDaemon` parameter indicates if the call originates from the daemon or CLI. ```go import "github.com/gravitl/netclient/functions" // Leave a network // isDaemon should be true if called from daemon, false from CLI faults, err := functions.LeaveNetwork("my-network", false) if err != nil { fmt.Printf("Error leaving network: %v\n", err) for _, fault := range faults { fmt.Printf(" Fault: %v\n", fault) } } ``` -------------------------------- ### Stop Daemon Service Source: https://context7.com/gravitl/netclient/llms.txt Stops the Netclient daemon service. An error is returned if the daemon fails to stop. ```go import "github.com/gravitl/netclient/daemon" // Stop the daemon service err := daemon.Stop() if err != nil { log.Fatalf("failed to stop daemon: %v", err) } ``` -------------------------------- ### Ping WireGuard Peers Source: https://context7.com/gravitl/netclient/llms.txt Checks connectivity and measures latency to WireGuard peers. Supports pinging all peers, specific networks, individual peers, custom packet counts, and IPv4/IPv6 filtering. JSON output is available with the -j flag. ```bash # Ping all peers on all networks netclient ping ``` ```bash # Ping peers on a specific network netclient ping -n my-network ``` ```bash # Ping a specific peer by name netclient ping -p server-1 ``` ```bash # Ping with custom packet count netclient ping -c 5 ``` ```bash # Use IPv4 addresses only netclient ping -4 ``` ```bash # Use IPv6 addresses only netclient ping -6 ``` ```bash # JSON output netclient ping -j ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.