Compare commits

..
16 Commits
Author SHA1 Message Date
thakares 400df6c16e Merge pull request #5 from thakares/main
Update .deb/.rpm scripts
2025-05-25 11:51:56 +05:30
thakares a78beb92fe Add files via upload 2025-05-25 11:49:22 +05:30
thakares f7e8cb0969 Add files via upload 2025-05-25 11:45:47 +05:30
thakares b2cf04452f Merge pull request #4 from thakares/main
Updates
2025-05-24 23:21:57 +05:30
thakares 18b2c37dc0 Delete Docker directory 2025-05-24 23:15:20 +05:30
thakares 50b05d8dd2 Delete Cargo.lock 2025-05-24 23:14:33 +05:30
thakares ce1d265f1f Delete Algorithm-Flowchart.md 2025-05-24 23:14:13 +05:30
thakares 8271dc27dc Add files via upload 2025-05-24 23:13:55 +05:30
thakares b91a0ebcca Delete README.txt 2025-05-24 23:13:01 +05:30
thakares cb65b8c89b Delete Algorithm-Flowchart.md 2025-05-24 23:12:15 +05:30
thakares 26ffeb3092 Update Algorithm & Flowchart.md 2025-05-24 23:11:49 +05:30
thakares 6ab92cc966 Merge pull request #3 from thakares/updates
Updates
2025-05-24 23:09:09 +05:30
thakares 5f45d47f19 Delete target directory 2025-05-24 23:01:50 +05:30
thakares 4b9650e589 Delete .idea directory 2025-05-24 23:01:27 +05:30
thakares 2ac5b54a8b Delete Documents directory 2025-05-24 23:01:16 +05:30
thakares 23a597a952 Refactor: major codebase update and improvements 2025-05-24 22:43:39 +05:30
12 changed files with 446 additions and 1422 deletions

No files matched your search

@@ -57,7 +57,7 @@ This document outlines the algorithm and flowchart for a DNS server implementati
---
## 📊 Flowchart
![Flowchart](flow-chart.png)
![Flowchart](Flow-Chart.png)
Below is the visual representation of the DNS query handling logic:
```
Generated
-1340
View File
File diff suppressed because it is too large. Load diff
-57
View File
@@ -1,57 +0,0 @@
# Build stage
FROM rust:1.72-slim-bookworm AS builder
# Install necessary build dependencies
RUN apt-get update && apt-get install -y \
musl-tools \
build-essential \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Add support for cross-compilation to Alpine
RUN rustup target add x86_64-unknown-linux-musl
# Create a new empty project
WORKDIR /app
COPY . .
# Build the project with musl target
RUN cargo build --target x86_64-unknown-linux-musl --release
# Runtime stage
FROM alpine:3.18
# Install runtime dependencies
RUN apk --no-cache add ca-certificates sqlite tzdata
# Create a non-root user for running the application
RUN addgroup -S dns && adduser -S dnsuser -G dns
# Create necessary directories
RUN mkdir -p /var/nx9-dns-server /var/log/nx9-dns-server /etc/nx9-dns-server
RUN chown -R dnsuser:dns /var/nx9-dns-server /var/log/nx9-dns-server /etc/nx9-dns-server
# Copy the compiled binary
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/dns_server /usr/local/bin/
RUN chmod +x /usr/local/bin/dns_server
# Copy configuration files
COPY --from=builder /app/conf/dns_records.sql /etc/nx9-dns-server/
COPY --from=builder /app/conf/dns.db.sample /etc/nx9-dns-server/
# Expose DNS ports
EXPOSE 53/udp 53/tcp
# Expose Web UI port
EXPOSE 8080/tcp
# Expose API port
EXPOSE 8081/tcp
# Set working directory
WORKDIR /var/nx9-dns-server
# Switch to non-root user
USER dnsuser
# Command to run the application
CMD ["/usr/local/bin/dns_server"]
-24
View File
@@ -1,24 +0,0 @@
version: '3.8'
services:
dns:
image: nx9-dns-server:latest
container_name: nx9-dns
ports:
- "53:53/udp"
- "53:53/tcp"
- "8080:8080"
- "8081:8081"
volumes:
- ./data/dns.db:/var/nx9-dns-server/dns.db
- ./keys:/etc/nx9-dns-server/keys
- ./logs:/var/log/nx9-dns-server
environment:
- DNS_BIND=0.0.0.0:53
- DNS_DB_PATH=/var/nx9-dns-server/dns.db
- DNSSEC_KEY_FILE=/etc/nx9-dns-server/keys/Kanydomain.tld.key
- DNS_FORWARDERS=8.8.8.8:53,1.1.1.1:53
- DNS_NS_RECORDS=ns1.anydomain.tld.,ns2.anydomain.tld.
- WEB_UI_BIND=0.0.0.0:8080
- API_BIND=0.0.0.0:8081
restart: unless-stopped
+138
View File
@@ -0,0 +1,138 @@
# NX9 DNS Server Installation Guide
## Installation Methods
The NX9 DNS Server provides three flexible installation methods:
### 1. Direct Installation Script
The `install.sh` script provides a customizable installation process:
```bash
# Default installation to /usr/local
./install.sh
# Custom installation prefix
./install.sh --prefix=/opt/nx9-dns
```
#### Features:
- Configurable installation prefix
- Automatic service setup
- Documentation and man page installation
- Proper permission handling
### 2. Debian Package Installation
For Debian-based systems (Ubuntu, Debian, etc.):
```bash
# Build the package
./build-deb.sh
# Install the generated package
sudo dpkg -i nx9-dns-server-*.deb
```
#### Package Features:
- Proper dependency management
- System user creation
- Systemd service integration
- Configuration file management
- Clean uninstallation support
### 3. RPM Package Installation
For RPM-based systems (RHEL, CentOS, Fedora):
```bash
# Build the package
./build-rpm.sh
# Install the generated package
sudo rpm -i nx9-dns-server-*.rpm
```
#### Package Features:
- Automatic dependency resolution
- System service management
- Standard RPM filesystem hierarchy
- Built-in upgrade support
## Directory Structure
The installation creates the following directory structure:
```
${PREFIX}/
├── bin/
│ └── nx9-dns-server
├── lib/
│ └── nx9-dns-server/
├── etc/
│ └── nx9-dns-server/
│ └── nx9-dns-server.conf
├── share/
│ ├── doc/
│ │ └── nx9-dns-server/
│ │ ├── README.md
│ │ └── LICENSE
│ └── man/
│ └── man1/
│ └── nx9-dns-server.1.gz
└── var/
└── lib/
└── nx9-dns-server/
└── dns.db
```
## System Integration
### Service Management
After installation, the server runs as a systemd service:
```bash
# Start the service
sudo systemctl start nx9-dns-server
# Enable auto-start at boot
sudo systemctl enable nx9-dns-server
# Check service status
sudo systemctl status nx9-dns-server
```
### Security Features
- Dedicated system user (`nx9-dns`)
- Proper file permissions
- Confined service execution
### Configuration
- Main configuration: `/etc/nx9-dns-server/nx9-dns-server.conf`
- Database location: `/var/lib/nx9-dns-server/dns.db`
- DNSSEC key file: `/etc/nx9-dns-server/dnssec.key`
## Uninstallation
### Using Installation Script
```bash
# If installed with install.sh, manually remove files from prefix
sudo rm -rf ${PREFIX}/{bin,lib,etc,share}/nx9-dns-server
```
### Package-based Removal
```bash
# Debian systems
sudo apt remove nx9-dns-server
# RPM systems
sudo rpm -e nx9-dns-server
```
## Notes
- All installation methods require root/sudo privileges
- The installation preserves existing configuration files
- Service user is created automatically
- Logs are integrated with systemd journal
This installation system follows standard Unix filesystem hierarchy and packaging conventions, making it suitable for both development and production environments.
+110
View File
@@ -0,0 +1,110 @@
#!/bin/bash
# Check for required tools
if ! command -v dpkg-deb &> /dev/null; then
echo "dpkg-deb is required but not installed. Please install dpkg-dev package."
exit 1
fi
# Package information
PACKAGE="nx9-dns-server"
VERSION=$(grep '^version =' Cargo.toml | cut -d '"' -f2)
ARCH=$(dpkg --print-architecture)
MAINTAINER="Sunil Purushottam Thakare"
DESCRIPTION="High-performance DNS server with DNSSEC support"
# Create package directory structure
PKGDIR="$PACKAGE-$VERSION"
mkdir -p "$PKGDIR/DEBIAN"
mkdir -p "$PKGDIR/usr/local/bin"
mkdir -p "$PKGDIR/etc/nx9-dns-server"
mkdir -p "$PKGDIR/usr/lib/systemd/system"
mkdir -p "$PKGDIR/var/lib/nx9-dns-server"
mkdir -p "$PKGDIR/usr/share/doc/$PACKAGE"
# Build the project
cargo build --release
# Create control file
cat > "$PKGDIR/DEBIAN/control" << EOF
Package: $PACKAGE
Version: $VERSION
Architecture: $ARCH
Maintainer: $MAINTAINER
Depends: libc6 (>= 2.17), adduser
Section: net
Priority: optional
Homepage: https://github.com/yourusername/nx9-dns-server
Description: $DESCRIPTION
NX9 DNS Server is a high-performance DNS server implementation
with full DNSSEC support. It provides both authoritative and
recursive DNS services with modern features like cache management
and metrics export.
EOF
# Create postinst script
cat > "$PKGDIR/DEBIAN/postinst" << EOF
#!/bin/sh
set -e
# Create nx9-dns user if it doesn't exist
if ! getent passwd nx9-dns > /dev/null; then
adduser --system --group --no-create-home --home /nonexistent nx9-dns
fi
# Set permissions
chown -R nx9-dns:nx9-dns /var/lib/nx9-dns-server
chmod 755 /var/lib/nx9-dns-server
# Enable and start service
if [ -x "/bin/systemctl" ]; then
systemctl daemon-reload
systemctl enable nx9-dns-server.service || true
systemctl start nx9-dns-server.service || true
fi
EOF
# Create prerm script
cat > "$PKGDIR/DEBIAN/prerm" << EOF
#!/bin/sh
set -e
if [ -x "/bin/systemctl" ]; then
systemctl stop nx9-dns-server.service || true
systemctl disable nx9-dns-server.service || true
fi
EOF
# Set permissions for maintainer scripts
chmod 755 "$PKGDIR/DEBIAN/postinst"
chmod 755 "$PKGDIR/DEBIAN/prerm"
# Copy files
cp target/release/nx9-dns-server "$PKGDIR/usr/local/bin/"
cp config/nx9-dns-server.conf "$PKGDIR/etc/nx9-dns-server/" 2>/dev/null || echo "No config file found, skipping..."
cp README.md LICENSE "$PKGDIR/usr/share/doc/$PACKAGE/" 2>/dev/null || echo "No documentation files found, skipping..."
# Create systemd service file
cat > "$PKGDIR/usr/lib/systemd/system/nx9-dns-server.service" << EOF
[Unit]
Description=NX9 DNS Server
After=network.target
[Service]
ExecStart=/usr/local/bin/nx9-dns-server
Environment=DNS_DB_PATH=/var/lib/nx9-dns-server/dns.db
Environment=DNSSEC_KEY_FILE=/etc/nx9-dns-server/dnssec.key
Restart=always
User=nx9-dns
[Install]
WantedBy=multi-user.target
EOF
# Build the package
dpkg-deb --build "$PKGDIR"
# Cleanup
rm -rf "$PKGDIR"
echo "Debian package created: ${PKGDIR}.deb"
+115
View File
@@ -0,0 +1,115 @@
#!/bin/bash
# Check for required tools
if ! command -v rpmbuild &> /dev/null; then
echo "rpmbuild is required but not installed. Please install rpm-build package."
exit 1
fi
# Package information
NAME="nx9-dns-server"
VERSION=$(grep '^version =' Cargo.toml | cut -d '"' -f2)
RELEASE="1"
# Create RPM build directory structure
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
# Create the spec file
cat > ~/rpmbuild/SPECS/$NAME.spec << EOF
Name: $NAME
Version: $VERSION
Release: $RELEASE%{?dist}
Summary: High-performance DNS server with DNSSEC support
License: MIT
URL: https://github.com/yourusername/nx9-dns-server
BuildRequires: cargo, gcc
Requires: systemd
%description
NX9 DNS Server is a high-performance DNS server implementation
with full DNSSEC support. It provides both authoritative and
recursive DNS services with modern features like cache management
and metrics export.
%prep
%setup -q -c -T
cp -r %{_sourcedir}/* .
%build
cargo build --release
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}/usr/local/bin
mkdir -p %{buildroot}/etc/nx9-dns-server
mkdir -p %{buildroot}/usr/lib/systemd/system
mkdir -p %{buildroot}/var/lib/nx9-dns-server
mkdir -p %{buildroot}/usr/share/doc/%{name}
# Install binary
install -m 755 target/release/nx9-dns-server %{buildroot}/usr/local/bin/
# Install config
install -m 644 config/nx9-dns-server.conf %{buildroot}/etc/nx9-dns-server/ || :
# Install docs
install -m 644 README.md LICENSE %{buildroot}/usr/share/doc/%{name}/ || :
# Install systemd service
cat > %{buildroot}/usr/lib/systemd/system/nx9-dns-server.service << 'EOL'
[Unit]
Description=NX9 DNS Server
After=network.target
[Service]
ExecStart=/usr/local/bin/nx9-dns-server
Environment=DNS_DB_PATH=/var/lib/nx9-dns-server/dns.db
Environment=DNSSEC_KEY_FILE=/etc/nx9-dns-server/dnssec.key
Restart=always
User=nx9-dns
[Install]
WantedBy=multi-user.target
EOL
%pre
# Create nx9-dns user if it doesn't exist
if ! getent passwd nx9-dns > /dev/null; then
useradd -r -s /sbin/nologin nx9-dns
fi
%post
%systemd_post nx9-dns-server.service
chown -R nx9-dns:nx9-dns /var/lib/nx9-dns-server
chmod 755 /var/lib/nx9-dns-server
%preun
%systemd_preun nx9-dns-server.service
%postun
%systemd_postun_with_restart nx9-dns-server.service
%files
%attr(755,root,root) /usr/local/bin/nx9-dns-server
%dir %attr(755,nx9-dns,nx9-dns) /var/lib/nx9-dns-server
%dir %attr(755,root,root) /etc/nx9-dns-server
%config(noreplace) /etc/nx9-dns-server/nx9-dns-server.conf
/usr/lib/systemd/system/nx9-dns-server.service
%doc /usr/share/doc/%{name}/*
%changelog
* $(date '+%a %b %d %Y') $USER <$USER@$(hostname)> - $VERSION-$RELEASE
- Initial RPM release
EOF
# Create source tarball
mkdir -p ~/rpmbuild/SOURCES/$NAME-$VERSION
cp -r * ~/rpmbuild/SOURCES/$NAME-$VERSION/
cd ~/rpmbuild/SOURCES
tar czf $NAME-$VERSION.tar.gz $NAME-$VERSION
rm -rf $NAME-$VERSION
# Build the RPM
rpmbuild -ba ~/rpmbuild/SPECS/$NAME.spec
echo "RPM package created in ~/rpmbuild/RPMS/"
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
Regular → Executable
View File
File mode changed.
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

+82
View File
@@ -0,0 +1,82 @@
#!/bin/bash
# Default installation prefix
PREFIX=${PREFIX:-/usr/local}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--prefix=*)
PREFIX="${1#*=}"
shift
;;
--help)
echo "Usage: $0 [--prefix=/installation/path]"
echo "Default prefix is /usr/local"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Build the project
echo "Building nx9-dns-server..."
cargo build --release
# Create necessary directories
echo "Creating directories in $PREFIX..."
sudo mkdir -p "$PREFIX/bin"
sudo mkdir -p "$PREFIX/lib/nx9-dns-server"
sudo mkdir -p "$PREFIX/etc/nx9-dns-server"
sudo mkdir -p "$PREFIX/share/doc/nx9-dns-server"
sudo mkdir -p "$PREFIX/share/man/man1"
# Install binary
echo "Installing binary..."
sudo install -m 755 target/release/nx9-dns-server "$PREFIX/bin/"
# Install configuration
echo "Installing configuration files..."
sudo install -m 644 config/nx9-dns-server.conf "$PREFIX/etc/nx9-dns-server/" 2>/dev/null || echo "No config file found, skipping..."
# Install documentation
echo "Installing documentation..."
sudo install -m 644 README.md "$PREFIX/share/doc/nx9-dns-server/" 2>/dev/null || echo "No README found, skipping..."
sudo install -m 644 LICENSE "$PREFIX/share/doc/nx9-dns-server/" 2>/dev/null || echo "No LICENSE found, skipping..."
# Install man page if it exists
if [ -f doc/nx9-dns-server.1 ]; then
echo "Installing man page..."
sudo install -m 644 doc/nx9-dns-server.1 "$PREFIX/share/man/man1/"
sudo gzip -f "$PREFIX/share/man/man1/nx9-dns-server.1"
fi
# Create systemd service file
echo "Creating systemd service file..."
cat > nx9-dns-server.service << EOF
[Unit]
Description=NX9 DNS Server
After=network.target
[Service]
ExecStart=$PREFIX/bin/nx9-dns-server
Environment=DNS_DB_PATH=/var/lib/nx9-dns-server/dns.db
Environment=DNSSEC_KEY_FILE=/etc/nx9-dns-server/dnssec.key
Restart=always
User=nx9-dns
[Install]
WantedBy=multi-user.target
EOF
sudo install -m 644 nx9-dns-server.service /lib/systemd/system/
rm nx9-dns-server.service
echo "Installation completed successfully!"
echo "To start the service:"
echo "1. Create nx9-dns user: sudo useradd -r -s /bin/false nx9-dns"
echo "2. Enable the service: sudo systemctl enable nx9-dns-server"
echo "3. Start the service: sudo systemctl start nx9-dns-server"