1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

hostnameの変更方法とそれに伴うsudo: unable to resolve hostの対応方法

Last updated at Posted at 2018-07-02

実行環境はUbuntu16.04です。

[root]
$ cat /etc/lsb-release

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS"

ホスト名の変更

一時的に変更する場合

[root]
$ hostname xxx

恒久的に変更する場合

[root]
$ hostnamectl set-hostname xxx

/etc/hostsの更新

ホスト名を変更するとsudoで実行した場合に sudo: unable to resolve host xxxと表示されます。
これはホスト名が解決できなかったことを示すエラーです。

ホスト名は/etc/hostsで管理されているので、以下のようにして新しく作成したhostnameを追記してあげます。

$ sudo sh -c 'echo 127.0.1.1 $(hostname) >> /etc/hosts'

by @nishina555

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?