How do I give my Ubuntu machine a domain name on a Windows network?

5,747

Solution 1

You need to add a static entry on your DNS server for that machine. Just add an A record for that machine and the 'subdomain' name you want to give it under Forward Lookup Zones and your appropriate domain name.

Solution 2

For Ubuntu, you need to first edit your /etc/hostname file and set your desired hostname without the domain included. For this example i will use the hostname LINUX and domain UBUNTU.COM.

  1. Run sudo nano /etc/hostname and set your desired hostname, in this example LINUX then write changes.
  2. Update your hostname by running sudo hostname -F /etc/hostname.
  3. Check /etc/hostname by running cat /etc/hostname.

Your /etc/hostname file should now look like this:

LINUX

Now lets take a look to see if your machine is already looking for your domain name.

  • Run cat /etc/resolv.conf. If you get a line showing search UBUNTU.COM then we can skip this part as your machine is aware of the domain.

if you don't get search UBUNTU.COM and you don't see nameserver <ip of your DNS Server>

  1. Edit your resolv.conf file by running sudo nano /etc/resolvconf/resolv.conf.d/head
  2. Add search UBUNTU.COM.
  3. Add nameserver <ip of DNS Server> and write changes.
  4. Run sudo resolvconf -u to update your /etc/resolv.conf file.
  5. Check your updated resolv.conf by running cat /etc/resolv.conf and you should now see search UBUNTU.COM and nameserver 192.168.0.15 or whatever your DNS server's IP is as the first thing your Ubuntu machine will search for.

Now let's update your /etc/hosts file

  1. Run sudo nano /etc/hosts.

  2. On the line that has 127.0.1.1 LINUX change it to 127.0.1.1 LINUX.UBUNTU.COM LINUX and write changes.

  3. Now we run sudo service networking restart to refresh changes.

Lets check to see if changes took effect.

  • Check Hostname: hostname which should return LINUX.
  • Check Domain: hostname -d which should return UBUNTU.COM.
  • Check FQDN: hostname -f which should return LINUX.UBUNTU.COM.
  • Check Name Resolution: nslookup LINUX.UBUNTU.COM should return results from the DNS server you added in resolv.conf. If it cant find it then you may need to give it time to update or manually add an A record in your DNS server for your Ubuntu machine.
  • (If above resolved fine) Ping your FQDN! ping LINUX.UBUNTU.COM should return ping responses from your IP Address.
Share:
5,747
undefined
Author by

undefined

Updated on September 18, 2022

Comments

  • undefined
    undefined over 1 year

    I want to setup a GIT server on my Ubuntu machine in the office but I want a domain name for it that I can connect to from Windows machines on the same network. I've read about using Samba or adding the machine to Active Directory but I'm a bit lost with both. All machines are on the same a.b.com domain.

    I have modified my hosts file on the Ubuntu machine to show the following: 127.0.0.1 ubuntu 127.0.1.1 ubuntu.a.b.com ubuntu 192.168.0.9 ubuntu.a.b.com ubuntu

    I have admin credentials to the domain controllers and Active Directory. What can I do to enable other Windows machines to access the Ubuntu machine for something like SSH or a GIT server via a domain name rather than the machines IP address?

  • undefined
    undefined over 6 years
    Do I not need to add the machine into Active Directory or anything like that then? Seems pretty simple, will give it a try in the morning!
  • xR34P3Rx
    xR34P3Rx over 6 years
    this will only work if your local machines have the DNS server as their DNS server. Ubuntu by default uses itself as a DNS server if you check /etc/resolv.conf so it wont actually "adopt" the FQDN.
  • undefined
    undefined over 6 years
    This solution ended up working fine for me, I just added a DNS record into one of the domain controllers.
  • undefined
    undefined over 6 years
    Very informative but the answer above worked for me!