This Go program captures DNS (Domain Name System) traffic from specified network interfaces and stores the captured data in a ClickHouse database. It utilises the github.com/google/gopacket
library for packet capture and processing and the gorm.io/gorm
library for interacting with the ClickHouse database.
- Captures DNS packets from specified network interfaces.
- Extracts relevant information from the captured packets, including the timestamp, domain name, query type, and source IP address.
- Stores the captured DNS queries in a ClickHouse database.
- Stores both the raw domain queried along with a normalised version of the domain.TLD
- Supports batching of queries to improve performance and reduce database operations.
- Uses goroutines for concurrent packet capture and database insertion, maximising efficiency.
- Go 1.20 or later
- ClickHouse database
- Network interfaces with DNS traffic to capture
- Clone the repository or download the source code files.
- Install the required dependencies by running the following command:
go mod download
Before running the program, you need to configure the following settings:
- ClickHouse Database Connection: Update the
dsn
variable in theclickhouseDB()
function with the appropriate connection details for your ClickHouse database. Make sure to set the correct username, password, host, port, and database name.
To capture DNS traffic and store it in the ClickHouse database, follow these steps:
- Build the program by running the following command:
go build dns-logger.go
- Set the
DNS_TRAFFIC_DB_PASS
environment variable to the clickhouse database password - Run the executable file:
./dns-logger
- Alternatively use the provided systemd unit file to run this program as a service just ensure you set the
DNS_TRAFFIC_DB_PASS='clickhouse_db_pass'
in/etc/default/dns-logger
The program will start capturing DNS packets from the specified network interfaces ( eth1, eth2 by default ) and store the captured data in the ClickHouse database.
Contributions are welcome! If you find any issues or have suggestions for improvement, please feel free to open an issue or submit a merge request.
This project is licensed under the GPLv3 Licence.
This program uses the following open-source libraries: