Debian関係の技術日誌

IPアドレスの固定

IPアドレスを固定化する。
サーバー用途で使用するならIPアドレスの固定化は必須と言える。

まず、ネットワークインターフェースを調べる。

$ ip a

有線LANならeth0 や enp1s0、無線LANならwlan0 などのネットワークインターフェース名が表示されるハズ。

次に/etc/network/interface を編集する。
以下のようにeth0やenp1s0などの表示されたネットワークインターフェース部分を編集する。

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

auto enp1s0
iface enp1s0 inet static
   address 192.168.1.101
   netmask 255.255.255.0
   gateway 192.168.1.1
   dns-nameservers 192.168.1.1 8.8.8.8

address の部分に固定IPアドレスを書き、
netmaskにネットマスクを
gatewayにゲートウェイアドレス、
dns-nameserversにDNSサーバーアドレスを書く。

次に/etc/resolv.conf を編集する。

nameserver 192.168.1.1
search local.example.jp

nameserver は interface にも書いたのでのここで書かなくても良いが
search はローカルLANで補完するDNS名を書く。
これで例えば ping host01 とすれば
host01.local.example,jp を探してくれるようになる。

次に/etc/nsswitch.conf を編集する。

# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         files systemd
group:          files systemd
shadow:         files systemd
gshadow:        files systemd

hosts:          files dns myhostname mdns4_minimal [NOTFOUND=return]
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

hostsの行がデフォルトではdnsが最後になっているのでこれを二番目に移動させておく。
これでローカルLAN内にDNSサーバがある場合はそちらを参照してくれる。

マシンを再起動して終了。

コメントは受け付けていません。

挨拶

このサイトの著者:
NEVER_NOTHING(なっしんぐ)

フリーランスのITエンジニア
京都出身/東京在住