LoginSignup
45
40

More than 3 years have passed since last update.

「/etc/hosts」ファイルについて

Last updated at Posted at 2020-02-18

最近の勉強で学んだ事を、ノート代わりにまとめていきます。
主に自分の学習の流れを振り返りで残す形なので色々、省いてます。
Webエンジニアの諸先輩方からアドバイスやご指摘を頂けたらありがたいです!

/etc/hosts ファイル

hostsファイルは使う事は多いのですがキチンと理解できていなかったのでしっかりとまとめる。
「/etc/hosts」ファイルは、ホスト名とIPアドレスを対応させるためのファイル

/etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost

各行に、IPアドレスと、それに対応するホスト名を設定できる!

インターネット上では、DNSサーバがドメインとIPの組み合わせを記録するようになっています。ただ、コンピュータ内のhostsファイルはDNSより優先的に参照されるようになっています。そのため、コンピュータ内の設定はDNSより優先されます。

hostsファイルの場所

Macのhostsファイルは /private/etc/hosts に配置されています。/private/etc から /etc を参照するシンボリックリンクがあるため、/etc/hosts からも参照・編集可能です。

/private/etc/hosts
または
/etc/hosts

Linuxを含むUnix系のOSの場合、/etc/hosts に配置されています。

Windowsの場合、C:¥windows¥system32¥drivers¥etc に配置されています。

hostsファイルの編集

$sudo vi /etc/hosts

IP アドレスとホスト名を入力したら良い

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
 127.0.0.1       localhost
 192.168.0.10    example.com

参考記事

/etc/hosts」ファイル
hostsファイルの場所やら編集/設定するメモ(mac、linux、windows)
【Mac】hostsファイルの場所と変更方法!ターミナルとテキストエディットどちらでも!
/etc/hosts ファイルの設定

45
40
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
45
40