1 00:00:00,000 --> 00:00:01,620 [No audio] 2 00:00:01,620 --> 00:00:06,030 Changing Linux system Hostname. Hostname is the 3 00:00:06,030 --> 00:00:09,750 name of your Linux machine that is assigned during 4 00:00:09,750 --> 00:00:14,460 the first install. And often times, a machine is 5 00:00:14,460 --> 00:00:19,050 repurposed or decommissioned, or used for 6 00:00:19,350 --> 00:00:22,860 something else, then you have to change its hostname. 7 00:00:24,450 --> 00:00:28,280 To change the hostname, the command that is used is 8 00:00:28,280 --> 00:00:38,675 hostnamectl - set-hostname newhostname. 9 00:00:38,675 --> 00:00:42,270 This is the command, I believe there is no dash in the middle. But I'll 10 00:00:42,270 --> 00:00:45,874 try it out hostnamectl set-hostname newhostname 11 00:00:45,874 --> 00:00:47,610 The files that are used 12 00:00:48,240 --> 00:00:52,290 to save the newhostname in Linux 7 OS 13 00:00:52,290 --> 00:00:56,580 version, it's etc/hostname, the older version 14 00:00:56,610 --> 00:01:01,920 of Linux, which was version six, the configuration 15 00:01:01,920 --> 00:01:06,480 file for hostname was /etc/sysconfig/network. 16 00:01:07,530 --> 00:01:12,300 So again, let's try are changing our hostname of 17 00:01:12,300 --> 00:01:16,050 our Linux machine in our lab environment, or Linux 18 00:01:16,050 --> 00:01:18,960 machine, and right now when you type hostname, 19 00:01:20,160 --> 00:01:24,180 this is the name of our machine MyFirstLinuxOS. 20 00:01:25,170 --> 00:01:29,190 Now I want to change this hostname to a different 21 00:01:29,190 --> 00:01:31,620 hostname because my company came up with a new 22 00:01:31,620 --> 00:01:35,670 standard. Now every machine has to comply with the 23 00:01:35,670 --> 00:01:38,160 new standard requirement. So that's why I want to 24 00:01:38,160 --> 00:01:41,250 change it. So in order to change a hostname, you 25 00:01:41,250 --> 00:01:44,670 have to first become root, because root is only the 26 00:01:44,670 --> 00:01:48,360 one who has the power to do that. Okay, I'm going 27 00:01:48,360 --> 00:01:51,180 to login as root. Alright, and now I'm going to 28 00:01:51,180 --> 00:01:55,290 run the command hostname. Before I run this 29 00:01:55,290 --> 00:01:58,140 command, I just wanted to tell you, that the file that 30 00:01:58,320 --> 00:02:01,290 keeps your hostname information is /etc/ 31 00:02:01,290 --> 00:02:04,020 [Author typing] 32 00:02:04,020 --> 00:02:05,100 hostname. 33 00:02:06,150 --> 00:02:09,030 If you see, when I cat this file, it has 34 00:02:09,030 --> 00:02:13,560 my hostname. I could go into this file directly and 35 00:02:13,560 --> 00:02:18,030 modify this hostname and then reboot the system 36 00:02:18,030 --> 00:02:21,600 and it work or I could just simply run hostname 37 00:02:22,140 --> 00:02:27,570 ctl command, set-hostname, and the new hostname, so 38 00:02:27,570 --> 00:02:29,070 I'll put it the new hostname 39 00:02:29,070 --> 00:02:32,790 [No audio] 40 00:02:32,790 --> 00:02:34,560 nyc, 41 00:02:35,910 --> 00:02:41,010 host1, let's say, because my machine is located 42 00:02:41,010 --> 00:02:43,920 in New York City, and this the number one host so 43 00:02:43,920 --> 00:02:46,110 I'm just you know making it up to comply with 44 00:02:46,110 --> 00:02:48,780 the standard my company came up with. Alright, 45 00:02:48,780 --> 00:02:52,530 perfect. So once I have it, I run the command, it 46 00:02:52,530 --> 00:02:57,450 ran. So now when you do cat /etc/hostname, you 47 00:02:57,450 --> 00:03:00,240 should see the new hostname there. Yes, you see 48 00:03:00,240 --> 00:03:05,430 that. nychost1, but when you type hostname, 49 00:03:06,510 --> 00:03:09,930 it gives you the hostname of your new machine. 50 00:03:10,500 --> 00:03:16,690 But if you notice here your prompt, MyFirstLinuxOS, 51 00:03:16,690 --> 00:03:19,560 has, your prompt has the old hostname. 52 00:03:19,560 --> 00:03:22,980 Why is that? Because this shell that I'm logged 53 00:03:23,040 --> 00:03:28,200 into, this shell has to be restarted or the whole 54 00:03:28,200 --> 00:03:33,176 system has to reboot in order to read the new hostname 55 00:03:33,176 --> 00:03:36,090 that we created. So the only way to do that 56 00:03:36,090 --> 00:03:40,020 is simple reboot. So I'll just run reboot or 57 00:03:40,020 --> 00:03:42,990 another command for reboot is init6. So 58 00:03:42,990 --> 00:03:47,370 this time I'll run init 6, and we'll wait for the 59 00:03:47,370 --> 00:03:51,030 system to come back online. Give it a couple of minutes. 60 00:03:51,030 --> 00:03:57,150 [No audio] 61 00:03:57,150 --> 00:03:59,100 Got my login prompt, I'll login. 62 00:03:59,100 --> 00:04:02,520 [No audio] 63 00:04:02,520 --> 00:04:05,640 Some time the virtual machine will take a little 64 00:04:05,640 --> 00:04:09,960 longer to come back online depending on your 65 00:04:09,960 --> 00:04:13,830 laptop speed. So I'm going to go and right click, 66 00:04:14,550 --> 00:04:15,510 Open Terminal, 67 00:04:15,510 --> 00:04:18,779 [No audio] 68 00:04:18,779 --> 00:04:22,469 and you'll see now it has the new hostname. 69 00:04:22,469 --> 00:04:24,360 [No audio] 70 00:04:24,360 --> 00:04:29,460 nychost1, so this is how you change the hostname. 71 00:04:30,930 --> 00:04:33,600 Do you guys know how to change the hostname in 72 00:04:33,600 --> 00:04:37,170 Windows? Well I think you might. If not, then you 73 00:04:37,170 --> 00:04:41,190 should look into it. Because as administrator you 74 00:04:41,190 --> 00:04:43,920 will have to work a little bit of in the Windows 75 00:04:43,920 --> 00:04:46,620 environment too.You just go into your My Computer, 76 00:04:46,770 --> 00:04:49,470 right click on Properties, and change the hostname. 77 00:04:49,470 --> 00:04:54,720 So it is simple in Windows through the GUI, in 78 00:04:54,720 --> 00:04:57,480 Linux it is just running one command. It's simple 79 00:04:57,480 --> 00:04:59,970 here as well. So I'm going to change it back to 80 00:05:00,000 --> 00:05:03,540 my original hostname, becoming root. So this 81 00:05:03,540 --> 00:05:05,550 will stay consistent and this time I'll just 82 00:05:05,550 --> 00:05:07,800 modify the /etc/hostname file. 83 00:05:07,800 --> 00:05:10,170 [No audio] 84 00:05:10,170 --> 00:05:15,300 MyFirstLinuxOS, right, this is my original hostname. 85 00:05:16,650 --> 00:05:18,900 And when you run hostname this time, it will 86 00:05:18,900 --> 00:05:23,010 still give you that because the process that 87 00:05:23,010 --> 00:05:26,910 does the hostname changes, that process hasn't 88 00:05:26,910 --> 00:05:29,580 been restarted. The only way to do it is to 89 00:05:29,580 --> 00:05:32,820 restart like hostname, the command that we run 90 00:05:33,090 --> 00:05:35,880 before, but anyway, I'm just going to simple go 91 00:05:35,880 --> 00:05:39,270 ahead and restart or reboot my computer again, so 92 00:05:39,270 --> 00:05:43,080 the changes will take place and put my system back 93 00:05:43,140 --> 00:05:44,802 to my original hostname. 94 00:05:44,802 --> 00:05:46,411 [No audio]