How to create your own hostname for an ip address?
Example:-
If i am running apache, and giving my friend my ip to view the webpage.
what should i do if i want a hostname instead of ip?
Note:- i have tried freeDNS,DynDNS,No-IP and other services and they are not free. i want to learn how to create it manually.

Thanks.

Dani AI

Generated

Short version: you cannot invent a public hostname out of thin air. For anyone on the Internet to resolve a name to your IP, that name must live under a real domain in the public DNS hierarchy. Without owning a domain (or using a DDNS provider), only per-machine workarounds like editing the HOSTS file (as suggested) or LAN-only mDNS names like device.local will work. Note that .local names are link-local only and are not routed over the Internet mDNS .local, Public DNS hierarchy.

If you want to do it yourself (the way companies do), the manual path looks like this:

  • Register a cheap domain. Most registrars include DNS hosting.
  • Create DNS records: an A/AAAA for your web host, and optional CNAMEs. Use a low TTL (e.g., 300) if your IP changes.
  • If you insist on running your own authoritative DNS (BIND/NSD/PowerDNS), you still must register the domain and publish your nameservers at the registrar. You will need publicly reachable NS hosts.
  • On your router, forward TCP 80 (and 443 if using HTTPS) to your Apache server. Open your firewall accordingly. Test from outside with dig or an online DNS checker.

On Apache, use name-based virtual hosts and set the canonical host you just published in DNS. In Apache 2.4, you do not use NameVirtualHost (that directive is obsolete). A minimal vhost looks like:

<VirtualHost *:80>
    ServerName www.yourdomain.tld
    ServerAlias yourdomain.tld
    DocumentRoot /var/www/yourdomain
</VirtualHost>

See the official docs for details and examples: Apache name-based virtual hosts.

This complements ’s DDNS tip: if your IP changes often, either script your registrar’s DNS via API or use DDNS. Otherwise, you will keep breaking the A record.

Recommended Answers

All 7 Replies

If you do not want to use paid DNS or cannot find a free service, the other free option is to tell your friend to modify his/her HOSTS file on their computer.

You can create an entry like...

192.168.0.1 www.yourName.local

Replace that IP with your public IP.

Alternatively, register a .info domain name or similar one that only costs a few dollars per year. Most of thee registrars also provide DNS services included in the domain registration.

no-ip.org is a dynamic dns provider offering free service. I use it with success. You just have to type in a code every month when they send you a reminder email.

:/
ok but really, isn't there any other way?
thanks for your replies.

i mean, if you just have any knowledge, what does the companies do?
(educational purpose)

what does the companies do?

The most appropriate way to handle this, the way companies and enterprises implement this, is by having a publicly accessing domain name hosted in a DNS zone with the appropriate records.

You asked for a free solution though.

thanks alot BRO!

Step1: Check for the package installed or not

rpm -qa | grep httpd

Step2 : Install the package

yum install httpd

Step3 : For hostbased web access we require DNS server entries of our host.

Example host in this post is : server1.example.com(Actual server name) and
hostbase.example.com(our virtual host name)

So we have to give A record for the server1.example.com and CNAME record for hostbase.example.com which points to server1.example.com

Step3 : Create the root web directory and a test index.html for this testing.

I want to create my web directory in /hostnamebase

mkdir /hostnamebase

Now create index.html and try to write something in to that file then save the file.

vi /hostnamebase/index.html

save and exit the file.

Step4 : Now edit the httpd.config file

vi /etc/httpd/conf/httpd.conf

Step4(a) : Please specify the NameVirtualHost

NameVirtualHost 192.168.0.1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.