<!DOCTYPE html>
    <html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
    <head>
<title>Cách thay đổi hostname trong Linux</title>
<meta name="description" content="Cách thay đổi hostname trong Linux - Savefile - Tin Tức -...">
<meta name="author" content=".: Nguoicodonvn2008.info - Cõi lòng người cô đơn :.">
<meta name="copyright" content=".: Nguoicodonvn2008.info - Cõi lòng người cô đơn :. [admin@nguoicodonvn2008.info]">
<meta name="robots" content="index, archive, follow, noodp">
<meta name="googlebot" content="index,archive,follow,noodp">
<meta name="msnbot" content="all,index,follow">
<meta name="generator" content="NukeViet v4.5">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Cách thay đổi hostname trong Linux">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;www.nguoicodonvn2008.info&#x002F;vi&#x002F;news&#x002F;savefile&#x002F;kien-thuc-may-tinh&#x002F;cach-thay-doi-hostname-trong-linux-9482.html">
<meta property="og:site_name" content=".&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.">
<meta property="og:url" content="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/cach-thay-doi-hostname-trong-linux-9482.html">
<link rel="shortcut icon" href="https://www.nguoicodonvn2008.info/favicon.ico">
<link rel="canonical" href="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/cach-thay-doi-hostname-trong-linux-9482.html">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/karaoke-dual/" title="Tin Tức - Karaoke Dual" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/nhac-tre/" title="Tin Tức - Nhạc trẻ" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/tru-tinh/" title="Tin Tức - Trữ tình" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/nuoc-ngoai/" title="Tin Tức - Nước ngoài" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/remix/" title="Tin Tức - Remix" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/tam-su-tinh-yeu/" title="Tin Tức - Tâm sự tình yêu" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/tho-suu-tam/" title="Tin Tức - Thơ sưu tầm" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/cuoc-song/" title="Tin Tức - Cuộc sống" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/phan-mem/" title="Tin Tức - Phần mềm" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/kien-thuc-may-tinh/" title="Tin Tức - Kiến thức máy tính" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/hoc-tap/" title="Tin Tức - Học tập" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/tai-lieu/" title="Tin Tức - Tài liệu" type="application/rss+xml">
<link rel="alternate" href="https://www.nguoicodonvn2008.info/vi/news/rss/de-thi/" title="Tin Tức - Đề thi" type="application/rss+xml">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/assets/css/font-awesome.min.css" type="text/css">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/themes/default/css/bootstrap.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/themes/default/css/style.css" type="text/css">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/themes/default/css/style.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/themes/default/css/news.css" type="text/css">
<link rel="preload" as="style" href="https://www.nguoicodonvn2008.info/themes/default/css/custom.css" type="text/css">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/assets/js/jquery/jquery.min.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/assets/js/language/vi.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/assets/js/DOMPurify/purify3.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/assets/js/global.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/assets/js/site.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/themes/default/js/news.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/themes/default/js/main.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/themes/default/js/custom.js" type="text/javascript">
<link rel="preload" as="script" href="https://www.nguoicodonvn2008.info/themes/default/js/bootstrap.min.js" type="text/javascript">
<link rel="stylesheet" href="https://www.nguoicodonvn2008.info/assets/css/font-awesome.min.css">
<link rel="stylesheet" href="https://www.nguoicodonvn2008.info/themes/default/css/bootstrap.non-responsive.css">
<link rel="stylesheet" href="https://www.nguoicodonvn2008.info/themes/default/css/style.css">
<link rel="stylesheet" href="https://www.nguoicodonvn2008.info/themes/default/css/style.non-responsive.css">
<link rel="StyleSheet" href="https://www.nguoicodonvn2008.info/themes/default/css/news.css">
<link rel="stylesheet" href="https://www.nguoicodonvn2008.info/themes/default/css/custom.css">
<style type="text/css">
	body{background: #fff;}
</style>
    </head>
    <body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">.&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.</h2>
		<p class="pull-right"><a title=".&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;." href="https://www.nguoicodonvn2008.info/">https://www.nguoicodonvn2008.info</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Cách thay đổi hostname trong Linux</h1>
		<ul class="list-inline">
			<li>Thứ tư - 04/12/2024 23:27</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
		</div>
				<div class="imghome">
			<img alt="Cách thay đổi hostname trong Linux" src="https://st.quantrimang.com/photos/image/2016/04/27/lenh-linux-0-size-80x80-znd.png" width="460" class="img-thumbnail" />
		</div>
		<div class="clear"></div>
		<div id="bodytext" class="clearfix">
			<p style="text-align: justify;">Thay đổi hostname trên hệ thống Linux là một nhiệm vụ phổ biến đối với cả quản trị viên hệ thống và những người đam mê công nghệ. Bài viết này sẽ hướng dẫn bạn thực hiện quy trình trên hệ thống&nbsp;Ubuntu. Là một quản trị viên hệ thống thích sự linh hoạt và sức mạnh của Linux, bạn sẽ thấy nhiệm vụ này vừa đơn giản vừa thỏa mãn.</p>

<h2 id="mcetoc_1ie8ahkr232h" style="text-align: justify;">Hostname là gì?</h2>

<p style="text-align: justify;">Hostname là nhãn xác định máy của bạn trên mạng. Nó giống như tên máy tính của bạn, có thể được các thiết bị khác sử dụng để giao tiếp với máy. Có một hostname ý nghĩa sẽ giúp bạn quản lý mạng hiệu quả hơn.</p>

<h2 id="mcetoc_1ie8ahkr232i" style="text-align: justify;">Tại sao phải thay đổi hostname?</h2>

<p style="text-align: justify;">Có một số lý do khiến bạn có thể muốn thay đổi hostname của mình:</p>

<ul>
	<li style="text-align: justify;">Để phản ánh tốt hơn mục đích của máy (ví dụ: &quot;web server&quot; thay vì &quot;ubuntu-12345&quot;).</li>
	<li style="text-align: justify;">Để tuân thủ các quy ước đặt tên của tổ chức.</li>
	<li style="text-align: justify;">Do sở thích cá nhân và tổ chức tốt hơn.</li>
</ul>

<h2 id="mcetoc_1ie8ahkr232j" style="text-align: justify;">Kiểm tra hostname hiện tại</h2>

<p style="text-align: justify;">Trước khi thực hiện bất kỳ thay đổi nào, hãy kiểm tra hostname hiện tại.&nbsp;Mở terminal&nbsp;và nhập:</p>

<pre id="pre0">
<code>hostname</code></pre>

<p style="text-align: justify;">Bạn sẽ thấy hostname hiện tại được hiển thị. Ví dụ:</p>

<pre id="pre1">
<code>ubuntu-12345</code></pre>

<h2 id="mcetoc_1ie8ahkr232k" style="text-align: justify;">Đổi hostname tạm thời</h2>

<p style="text-align: justify;">Nếu bạn muốn đổi hostname tạm thời (cho đến lần khởi động lại tiếp theo), hãy sử dụng lệnh hostname theo sau là tên mới:</p>

<pre id="pre2">
<code>sudo hostname new-hostname</code></pre>

<p style="text-align: justify;">Thay thế new-hostname bằng hostname mong muốn của bạn. Ví dụ:</p>

<pre id="pre3">
<code>sudo hostname my-new-host</code></pre>

<div style="text-align: justify;">&nbsp;</div>

<p style="text-align: justify;">Để xác minh thay đổi, hãy nhập:</p>

<pre id="pre4">
<code>hostname</code></pre>

<p style="text-align: justify;">Bạn sẽ thấy hostname mới:</p>

<pre id="pre5">
<code>my-new-host</code></pre>

<p style="text-align: justify;">Tuy nhiên, thay đổi này sẽ không tồn tại sau khi khởi động lại. Để làm cho nó vĩnh viễn, hãy làm theo các bước dưới đây.</p>

<h2 id="mcetoc_1ie8ahkr232l" style="text-align: justify;">Đổi hostname vĩnh viễn</h2>

<p style="text-align: justify;">Để thay đổi hostname vĩnh viễn, bạn cần cập nhật một số file cấu hình.</p>

<h3 id="mcetoc_1ie8ahkr232m" style="text-align: justify;">1. Chỉnh sửa file /etc/hostname</h3>

<p style="text-align: justify;">Mở file /etc/hostname trong trình soạn thảo văn bản yêu thích. Nhiều người thích nano vì tính đơn giản của nó:</p>

<pre id="pre6">
<code>sudo nano /etc/hostname</code></pre>

<p style="text-align: justify;">Thay thế hostname hiện tại bằng hostname mới mong muốn của bạn. Lưu và đóng file (trong nano, bạn thực hiện việc này bằng cách nhấn&nbsp;<strong>CTRL+X</strong>, sau đó nhấn&nbsp;<strong>Y</strong>&nbsp;để xác nhận và&nbsp;<strong>Enter</strong>).</p>

<h3 id="mcetoc_1ie8ahkr232n" style="text-align: justify;">2. Chỉnh sửa file /etc/hosts</h3>

<p style="text-align: justify;">Tiếp theo, bạn cần cập nhật file /etc/hosts để ánh xạ hostname mới với địa chỉ IP localhost. Mở file bằng nano:</p>

<pre id="pre7">
<code>sudo nano /etc/hosts</code></pre>

<p style="text-align: justify;">Tìm dòng này:</p>

<pre id="pre8">
<code>127.0.1.1 old-hostname</code></pre>

<p style="text-align: justify;">Thay thế old-hostname bằng hostname mới của bạn:</p>

<pre id="pre9">
<code>127.0.1.1 my-new-host</code></pre>

<p style="text-align: justify;">Lưu và đóng file.</p>

<h3 id="mcetoc_1ie8ahkr232o" style="text-align: justify;">3. Áp dụng các thay đổi</h3>

<p style="text-align: justify;">Để áp dụng các thay đổi mà không cần khởi động lại, bạn có thể sử dụng lệnh hostnamectl:</p>

<pre id="pre10">
<code>sudo hostnamectl set-hostname my-new-host</code></pre>

<p style="text-align: justify;">Sau đó, khởi động lại service systemd-hostnamed để áp dụng các thay đổi:</p>

<pre id="pre11">
<code>sudo systemctl restart systemd-hostnamed</code></pre>

<h3 id="mcetoc_1ie8ahkr232p" style="text-align: justify;">4. Xác minh hostname mới</h3>

<p style="text-align: justify;">Để xác minh rằng hostname đã được thay đổi thành công, hãy chạy lệnh sau:</p>

<pre id="pre12">
<code>hostname</code></pre>

<p style="text-align: justify;">Bạn sẽ thấy hostname mới:</p>

<pre id="pre13">
<code>my-new-host</code></pre>

<p style="text-align: justify;">Ngoài ra, bạn có thể kiểm tra trạng thái hostnamectl:</p>

<pre id="pre14">
<code>hostnamectl</code></pre>

<p style="text-align: justify;">Lệnh này cung cấp thông tin chi tiết về hệ thống của bạn, bao gồm cả hostname mới.</p>

<p style="text-align: justify;">Thay đổi hostname trên hệ thống Ubuntu là một nhiệm vụ đơn giản nhưng quan trọng có thể giúp bạn sắp xếp mạng của mình. Nhiều người dùng thích những tác vụ tùy chỉnh nhỏ này trong Linux. Chúng mang lại cảm giác sở hữu và khả năng kiểm soát hệ thống. Thêm vào đó, luôn tuyệt khi thấy một máy được đặt tên có ý nghĩa thay vì một chuỗi ký tự ngẫu nhiên.</p>
		</div>
				<div id="author">
						<p>
				<strong>Nguồn tin:</strong>
				Quantrimang.com:
			</p>
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/cach-thay-doi-hostname-trong-linux-9482.html" title="Cách thay đổi hostname trong Linux">https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/cach-thay-doi-hostname-trong-linux-9482.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; .&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.
		</div>
		<div id="contact">
			<a href="mailto:admin@nguoicodonvn2008.info">admin@nguoicodonvn2008.info</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://www.nguoicodonvn2008.info/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
		</script>
		<div class="car-top">
  <span><img src="https://www.nguoicodonvn2008.info/themes/default/images/car.png" alt=""></span>
</div>
<script src="https://www.nguoicodonvn2008.info/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4c_e856T",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=0,nv_recaptcha_ver=2,nv_recaptcha_sitekey="",nv_recaptcha_type="image",XSSsanitize=1;</script>
<script src="https://www.nguoicodonvn2008.info/assets/js/language/vi.js"></script>
<script src="https://www.nguoicodonvn2008.info/assets/js/DOMPurify/purify3.js"></script>
<script src="https://www.nguoicodonvn2008.info/assets/js/global.js"></script>
<script src="https://www.nguoicodonvn2008.info/assets/js/site.js"></script>
<script src="https://www.nguoicodonvn2008.info/themes/default/js/news.js"></script>
<script src="https://www.nguoicodonvn2008.info/themes/default/js/main.js"></script>
<script src="https://www.nguoicodonvn2008.info/themes/default/js/custom.js"></script>
<script type="application/ld+json">
        {
            "@context": "https://schema.org",
            "@type": "Organization",
            "url": "https://www.nguoicodonvn2008.info",
            "logo": "https://www.nguoicodonvn2008.info/uploads/angel.gif"
        }
        </script>
<script src="https://www.nguoicodonvn2008.info/themes/default/js/bootstrap.min.js"></script>
<script type="text/javascript">
var $scrolltop = $('.car-top');
$scrolltop.on('click', function () {
    $('html,body').animate({
        scrollTop: 0
    }, 800);
    $(this).addClass("car-run");
    setTimeout(function(){ $scrolltop.removeClass('car-run');}, 1000);
    return false;
});
$(window).on('scroll', function ()
{ 
    if($(window).scrollTop() >= 200)
    {
        $scrolltop.addClass("show");
        $scrolltop.addClass("car-down");
    }
    else
    {
       $scrolltop.removeClass("show");
       setTimeout(function(){ $scrolltop.removeClass('car-down');}, 300);
    }
});
</script>
</body>
</html>