24

You can reach this IP address 2.186.116.46 (if my computer is online). I want to assign a domain to it so I wonder how is that possible when I have no DNS? I do own my domain which is ".com". My IP is static.

Thanks

4
  • 1
    There are a lot of free DNS providers. If you don't want to use them, you'll need to edit the /etc/hosts file on each computer that uses the IP address.
    – zondo
    Apr 5, 2017 at 17:15
  • So how can I use them? Apr 5, 2017 at 17:24
  • 1
    It looks like you using Apache/2.4.7. So in short: 1st you have to acquire FQDN from some DNS provider. 2nd: you must setup a ServerName directive into your /etc/apache2/sites-available/your-virtualhost.conf file.
    – pa4080
    Apr 5, 2017 at 17:42
  • 1
    If this is just for your use, I highly recommend freedns.afraid.org. You can either use a custom domain that you get elsewhere, or you can take a subdomain of any of their thousands. The guy who runs it is also very friendly and has helped me with some of my DNS problems.
    – zondo
    Apr 5, 2017 at 18:25

2 Answers 2

17

1. You need to acquire a domain name (or maybe just FQDN) from some DNS provider.

2. Once you have registered the domain name, you will gain access to an administrative panel (like this one shown below), where you will be able (via A records), to redirect the domain name (and all *. or certain sub domains / FQDNs) to your server's IP address.

enter image description here

  • Please note that the provider's administrative panel shall looks different, and the provider will give you exact instructions how to use it.

  • Sometimes the redirection can take up-to 24 hours. You can check if it's successful by the command whois example.com.

  • If the server is behind NAT, you must setup port forwarding.

3. Edit your Virtual Host configuration file and add relevant ServerName and maybe ServerAlias directives. Let's assume the configuration file is 000-default.conf that should look as this:

<VirtualHost *:80>

        ServerName example.com
        ServerAlias www.example.com localhost

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        <Directory /var/www/html>
                # etc ...
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
  • This step can be omitted, but it is absolutely necessary when you have more than one Virtual Hosts.

  • Don't forgot to:

    sudo a2ensite 000-default.conf
    sudo systemctl reload apache2.service
    

4. In addition for local needs:

  • You can bind a FQDN to the loopback interface of the server. For this purpose, edit the file /etc/hosts in a way like this:

    127.0.0.1    localhost example.com www.example.com
    

    It is not possible to enter *.example.com here. You can add an entry also for the IP address of another (local) server's network interface - for example 77.77.77.70.

  • If you want to access the FQDN by another computer through the LAN (or by a private computer through Internet), edit its host file in a way like this:

    77.77.77.70    example.com www.example.com
    

Further reading:

6
  • Maybe this answer could be interesting for you.
    – pa4080
    Apr 5, 2017 at 22:29
  • Thanks for your answer. But editing my /etc/hosts will only make domain available for my home network I want to set domain for public internet connection. I now got two DNS: herahost1.ddns.net herahost2.ddns.net shall I set them to my domain? But when I even do it the domain won't redirect to my site! Apr 6, 2017 at 6:28
  • Thanks, Would you please give an screenshot of your sub domain setting which you set it to mine? Apr 6, 2017 at 7:24
  • Thanks for your kindness, I exactly did right that but it's not working. And my bigger problem is that what shall I set the DNS of my domain. when I try to set them in herahost1.ddns.com and herahost2.ddns.com which are set to my ip it says something went wrong! Apr 6, 2017 at 8:38
  • And this is my screen of settings link Apr 6, 2017 at 8:43
6

If it is for just local use, you can just put that entry into your hosts file.

On modern Windows, that is usually c:\Windows\System32\Drivers\etc\hosts.

On Linux, the file is /etc/hosts.

For the rest of the world, use one of the freely available DNS providers.

Here is an example, with instructions: FreeDNS

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .