How do I give my Ubuntu machine a domain name on a Windows network?
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.
- Run
sudo nano /etc/hostname
and set your desired hostname, in this exampleLINUX
then write changes. - Update your hostname by running
sudo hostname -F /etc/hostname
. - Check
/etc/hostname
by runningcat /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 showingsearch 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>
- Edit your
resolv.conf
file by runningsudo nano /etc/resolvconf/resolv.conf.d/head
- Add
search UBUNTU.COM
. - Add
nameserver <ip of DNS Server>
and write changes. - Run
sudo resolvconf -u
to update your/etc/resolv.conf
file. - Check your updated
resolv.conf
by runningcat /etc/resolv.conf
and you should now seesearch UBUNTU.COM
andnameserver 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
Run
sudo nano /etc/hosts
.On the line that has
127.0.1.1 LINUX
change it to127.0.1.1 LINUX.UBUNTU.COM LINUX
and write changes.- Now we run
sudo service networking restart
to refresh changes.
Lets check to see if changes took effect.
- Check Hostname:
hostname
which should returnLINUX
. - Check Domain:
hostname -d
which should returnUBUNTU.COM
. - Check FQDN:
hostname -f
which should returnLINUX.UBUNTU.COM
. - Check Name Resolution:
nslookup LINUX.UBUNTU.COM
should return results from the DNS server you added inresolv.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.
undefined
Updated on September 18, 2022Comments
-
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 over 6 yearsDo 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 over 6 yearsthis 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 over 6 yearsThis solution ended up working fine for me, I just added a DNS record into one of the domain controllers.
-
undefined over 6 yearsVery informative but the answer above worked for me!