[No audio]
Changing Linux system Hostname. Hostname is the
name of your Linux machine that is assigned during
the first install. And often times, a machine is
repurposed or decommissioned, or used for
something else, then you have to change its hostname.
To change the hostname, the command that is used is
hostnamectl - set-hostname newhostname.
This is the command, I believe there is no dash in the middle. But I'll
try it out hostnamectl set-hostname newhostname
The files that are used
to save the newhostname in Linux 7 OS
version, it's etc/hostname, the older version
of Linux, which was version six, the configuration
file for hostname was /etc/sysconfig/network.
So again, let's try are changing our hostname of
our Linux machine in our lab environment, or Linux
machine, and right now when you type hostname,
this is the name of our machine MyFirstLinuxOS.
Now I want to change this hostname to a different
hostname because my company came up with a new
standard. Now every machine has to comply with the
new standard requirement. So that's why I want to
change it. So in order to change a hostname, you
have to first become root, because root is only the
one who has the power to do that. Okay, I'm going
to login as root. Alright, and now I'm going to
run the command hostname. Before I run this
command, I just wanted to tell you, that the file that
keeps your hostname information is /etc/
[Author typing]
hostname.
If you see, when I cat this file, it has
my hostname. I could go into this file directly and
modify this hostname and then reboot the system
and it work or I could just simply run hostname
ctl command, set-hostname, and the new hostname, so
I'll put it the new hostname
[No audio]
nyc,
host1, let's say, because my machine is located
in New York City, and this the number one host so
I'm just you know making it up to comply with
the standard my company came up with. Alright,
perfect. So once I have it, I run the command, it
ran. So now when you do cat /etc/hostname, you
should see the new hostname there. Yes, you see
that. nychost1, but when you type hostname,
it gives you the hostname of your new machine.
But if you notice here your prompt, MyFirstLinuxOS,
has, your prompt has the old hostname.
Why is that? Because this shell that I'm logged
into, this shell has to be restarted or the whole
system has to reboot in order to read the new hostname
that we created. So the only way to do that
is simple reboot. So I'll just run reboot or
another command for reboot is init6. So
this time I'll run init 6, and we'll wait for the
system to come back online. Give it a couple of minutes.
[No audio]
Got my login prompt, I'll login.
[No audio]
Some time the virtual machine will take a little
longer to come back online depending on your
laptop speed. So I'm going to go and right click,
Open Terminal,
[No audio]
and you'll see now it has the new hostname.
[No audio]
nychost1, so this is how you change the hostname.
Do you guys know how to change the hostname in
Windows? Well I think you might. If not, then you
should look into it. Because as administrator you
will have to work a little bit of in the Windows
environment too.You just go into your My Computer,
right click on Properties, and change the hostname.
So it is simple in Windows through the GUI, in
Linux it is just running one command. It's simple
here as well. So I'm going to change it back to
my original hostname, becoming root. So this
will stay consistent and this time I'll just
modify the /etc/hostname file.
[No audio]
MyFirstLinuxOS, right, this is my original hostname.
And when you run hostname this time, it will
still give you that because the process that
does the hostname changes, that process hasn't
been restarted. The only way to do it is to
restart like hostname, the command that we run
before, but anyway, I'm just going to simple go
ahead and restart or reboot my computer again, so
the changes will take place and put my system back
to my original hostname.
[No audio]