Friday, November 17, 2017

Running Technitium DNS Server on Ubuntu Linux

Technitium DNS Server is build to be cross platform using the .NET Standard 2.0. You can run the DNS Server Portable App on Linux or macOS by using .NET Core 2.2. This post is written for Ubuntu Linux but, you can easily follow similar steps on your favorite distro.

This blog post is updated regularly to provide latest instructions to install the DNS Server. So, refer it when you are about to do a fresh installation.

Using Automated Installer

Automated installer script can be used to install or update the DNS Server. Automated installer script is available for following distros:

  • Ubuntu Server
    curl -sSL https://technitium.com/download/dns/install-ubuntu.sh | sudo bash
    
  • Raspbian (Stretch) for Raspberry Pi
    curl -sSL https://technitium.com/download/dns/install-raspi.sh | sudo bash
    

Installing DNS Server Manually

Install the latest .NET Core runtime from here. Start Terminal and follow the steps below to run DNS Server on Ubuntu:

  1. Download DNS Server portable app using wget and extract it.
    wget https://technitium.com/download/dns/DnsServerPortable.tar.gz
    sudo mkdir -p /etc/dns/
    sudo tar -zxf DnsServerPortable.tar.gz -C /etc/dns/
    
  2. You can now run the DNS Server directly from console as a standalone app.
    cd /etc/dns/
    sudo ./start.sh
    
  3. Or, if your distro uses systemd, follow these steps to install it as a daemon.
    sudo cp /etc/dns/systemd.service /etc/systemd/system/dns.service
    sudo systemctl enable dns.service
    sudo systemctl start dns.service
    

    You may want to check the systemd log entries to find issue if the daemon fails to start:

    journalctl --unit dns --follow
    

  4. Or, if your distro does not support systemd, follow these steps to run it as a daemon using supervisor.
    sudo apt-get -y install supervisor
    sudo cp /etc/dns/supervisor.conf /etc/supervisor/conf.d/dns.conf
    sudo service supervisor restart
    

    You may want to check the log file to find issue if the daemon fails to start:

    cat /var/log/dns.err.log
    

  5. Open the url http://localhost:5380/ to access the web console.

Common Issue With Ubuntu

If you are using Ubuntu Desktop, you may find dnsmasq or systemd-resolved daemon already running on UDP port 53 preventing the DNS Server to listen on the same port. You can check the DNS Server log file from the web console to confirm the issue by finding this error:

[2019-01-01 07:30:59 UTC] [0.0.0.0:53] System.Net.Sockets.SocketException (98): Address already in use
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
   at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Bind(EndPoint localEP)
   at DnsServerCore.DnsServer.Start() in Z:\Technitium\Projects\DnsServer\DnsServerCore\DnsServer.cs:line 811

You may confirm if its dnsmasq or systemd-resolved by running sudo netstat -nlpu command.

Follow these steps below to disable the dnsmasq service:

  1. Edit the NetworkManager.conf file to disable dnsmasq service:
    sudo nano /etc/NetworkManager/NetworkManager.conf
    
    Comment out the dns=dnsmasq line by adding # character at the beginning like this #dns=dnsmasq and exit the editor by pressing CTRL+X and enter y to save the file.
  2. Restart the computer to apply changes as shown below:
    sudo reboot now
    
  3. After system reboot, open Terminal and check DNS Server logs again from the web console.

Follow these steps below to disable the systemd-resolved service:

  1. Disable the systemd-resolved service and stop it:
    sudo systemctl disable systemd-resolved
    sudo systemctl stop systemd-resolved
    
  2. Edit your /etc/resolv.conf using nano:
    sudo nano /etc/resolv.conf
    
    Edit the existing nameserver entry to the one shown below in your /etc/resolv.conf
    nameserver 127.0.0.1
    
  3. Edit your /etc/NetworkManager/NetworkManager.conf using nano:
    sudo nano /etc/NetworkManager/NetworkManager.conf
    
    Put the following line in the [main] section of your /etc/NetworkManager/NetworkManager.conf as shown below:
    [main]
    dns=default
    
  4. Restart network-manager:
    sudo service network-manager restart
    
  5. Now restart the DNS Server and check logs again from the web console.
    sudo systemctl restart dns.service
    

That's it!

The DNS Server is running and you can configure your network with the IP address of this computer for DNS resolution.

Check out the web console to create zone, check cached zones, access DNS client tool and configure server settings.

The DNS Server creates a folder named config in the current folder which contains the server config and zone files. Make sure you copy this folder while moving the DNS server folder if you want all the zone files and config to persist.

For any related queries, feel free to comment on this post.

12 comments:

  1. Hello my loved one! I wish to say that this post is amazing, nice written and come
    with approximately all significant infos. I would like to look
    more posts like this .

    ReplyDelete
  2. I have a problem regarding to hosting a hotspot with spoofed MAC address. None of my devices can connect to my hotspot unless I revert the MAC address back to original. Is there anyways to be able to host a hotspot with spoofed MAC Address?

    ReplyDelete
    Replies
    1. Send email to support@technitium.com with screenshots and details like OS version mobile device type etc.

      Delete
  3. I have a problem regarding to hosting a hotspot with spoofed MAC address. None of my devices can connect to my hotspot unless I revert the MAC address back to original. Is there anyways to be able to host a hotspot with spoofed MAC Address?

    ReplyDelete
  4. Replies
    1. You can do that as mentioned here: https://pmcgrath.net/running-a-simple-dotnet-core-linux-daemon

      I will be working on making an bash script that will automate and run the app as a daemon.

      Delete
    2. I have updated this post with instructions to run the DNS server as a daemon.

      Delete
  5. I have used this program for some time on my company's server for client computers. I'm finding it very good, fast and besides it's safe!!! Many thanks for being free!!!

    ReplyDelete
  6. How do I uninstall Technitium?

    ReplyDelete
    Replies
    1. It depends on your installation. If you have systemd then just disable & stop the dns.service. If you are using supervisord, then delete the /etc/supervisor/conf.d/dns.conf file and restart supervisord. After that, you can delete the /etc/dns/ directory to complete the uninstallation.

      Delete
    2. Sorry, I was not clear. I am a Noob and I installed on my Raspberry Pi using the following: curl -sSL https://technitium.com/download/dns/install-raspi.sh | sudo bash.
      Is there a way to run a "reverse" install to remove all that has been installed?

      Delete
    3. Just run the following commands to remove it from raspberry pi:

      # stop and disable the dns daemon
      sudo systemctl disable dns.service
      sudo systemctl stop dns.service
      # delete dns server files
      sudo rm -rf /etc/dns/

      # remove dotnet
      sudo rm /usr/bin/dotnet
      sudo rm -rf /opt/dotnet/

      Delete