「Dhcpd」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(ページの作成:「{{Lowercase title}} Category:ネットワーク de:Dhcpd en:Dhcpd ru:Dhcpd {{Related articles start}} {{Related|dhcpcd}} {{Related articles end}} dhcpd...」)
 
12行目: 12行目:
 
== インストール ==
 
== インストール ==
 
[[公式リポジトリ]]の {{pkg|dhcp}} パッケージを[[インストール]]してください。
 
[[公式リポジトリ]]の {{pkg|dhcp}} パッケージを[[インストール]]してください。
  +
  +
== 使用方法 ==
  +
  +
''dhcpd'' にはユニットファイル {{ic|dhcpd4.service}} が含まれており、これを使ってデーモンを[[有効化|制御]]できます。全ての[[ネットワーク設定#ネットワークインターフェイス|ネットワークインターフェイス]]でデーモンが起動します。[[#一つのインターフェイスだけを使う]] も見て下さい。
   
 
== 設定 ==
 
== 設定 ==
40行目: 44行目:
 
subnet 139.96.30.0 netmask 255.255.255.0 {
 
subnet 139.96.30.0 netmask 255.255.255.0 {
 
range 139.96.30.150 139.96.30.250;
 
range 139.96.30.150 139.96.30.250;
  +
}
  +
}}
  +
  +
特定のデバイスで固定 IP アドレスを使う必要がある場合、以下の構文を使います:
  +
  +
{{hc|/etc/dhcpd.conf|
  +
option domain-name-servers 8.8.8.8, 8.8.4.4;
  +
option subnet-mask 255.255.255.0;
  +
option routers 139.96.30.100;
  +
subnet 139.96.30.0 netmask 255.255.255.0 {
  +
range 139.96.30.150 139.96.30.250;
  +
  +
host macbookpro{
  +
hardware ethernet 70:56:81:22:33:44;
  +
fixed-address 139.96.30.199;
  +
}
 
}
 
}
 
}}
 
}}
51行目: 71行目:
 
設定後、[[Systemd#ユニット使う|systemctl]] を使って {{ic|dhcpd4.service}} を起動することで ''dhcpd'' デーモンを起動できます。任意で、ブート時に自動的に起動するように有効化してください。
 
設定後、[[Systemd#ユニット使う|systemctl]] を使って {{ic|dhcpd4.service}} を起動することで ''dhcpd'' デーモンを起動できます。任意で、ブート時に自動的に起動するように有効化してください。
   
  +
=== 一つのインターフェイスだけを使う ===
Now, to any computer you connect to the {{ic|eth0}} will be assigned an IPv4 address (from {{ic|139.96.30.150}} to {{ic|139.96.30.250}} in this example).
 
 
== Tips and Tricks ==
 
=== Listening on only one interface ===
 
 
If your computer is already part of one or several networks, it could be a problem if your computer starts giving ip addresses to machines from the other networks. It can be done by either configuring dhcpd or starting it as a daemon with [[Systemd#Using units|systemctl]].
 
If your computer is already part of one or several networks, it could be a problem if your computer starts giving ip addresses to machines from the other networks. It can be done by either configuring dhcpd or starting it as a daemon with [[Systemd#Using units|systemctl]].
   
 
==== dhcpd の設定 ====
 
==== dhcpd の設定 ====
In order to exclude an interface, you must create an empty declartion for the subnet that will be configured on that interface.
+
In order to exclude an interface, you must create an empty declaration for the subnet that will be configured on that interface.
   
 
This is done by editing the configuration file (for example):
 
This is done by editing the configuration file (for example):
68行目: 85行目:
   
 
==== サービスファイル ====
 
==== サービスファイル ====
  +
デフォルトではインターフェイスを一つだけ使用する ''dhcpd'' のサービスファイルは存在しないため、作成する必要があります:
There is no service files provided by default to use ''dhcpd'' only on one interface so you need to create one:
 
   
 
{{hc| /etc/systemd/system/dhcpd4@.service|<nowiki>
 
{{hc| /etc/systemd/system/dhcpd4@.service|<nowiki>
86行目: 103行目:
 
</nowiki>}}
 
</nowiki>}}
   
  +
上記は、特定のインターフェイスに bind するテンプレートユニットです。例えば {{ic|dhcp4d@''eth0''.service}} などとして使います (''eth0'' は {{ic|ip link}} で確認できるインターフェイスに置き換えて下さい)。
Now you can start ''dhcpd'' as a daemon which only listen to a specific interface, for example {{ic|eth0}}.
 
  +
# systemctl start dhcpd4@eth0.service
 
  +
=== PXE ===
  +
  +
PXE の設定は以下の2つのオプションで行います:
  +
  +
{{hc|/etc/dhcpd.conf|<nowiki>
  +
next-server 192.168.0.2;
  +
filename "/pxelinux.0";
  +
</nowiki>}}
  +
  +
This section can either be in an entire {{ic|subnet}} or just in a {{ic|host}} definition. {{ic|next-server}} is the IP of the TFTP Server, and {{ic|filename}} is the filename of the image to boot. For more information see [[PXE]].

2015年7月10日 (金) 10:37時点における版

関連記事

dhcpd は Internet Systems Consortium による DHCP サーバーです。LAN 上でルーターとして動作するマシンなどで有用です。

インストール

公式リポジトリdhcp パッケージをインストールしてください。

使用方法

dhcpd にはユニットファイル dhcpd4.service が含まれており、これを使ってデーモンを制御できます。全てのネットワークインターフェイスでデーモンが起動します。#一つのインターフェイスだけを使う も見て下さい。

設定

使用したいインターフェイスに固定 IPv4 アドレスを割り当ててください (このページでは例として eth0 を使います)。アドレスの最初の3バイトを他のインターフェイスのアドレスと全く同じにすることはできません。

# ip link set up dev eth0
# ip addr add 139.96.30.100/24 dev eth0 # arbitrary address
ヒント: Usually, the one of next three subnets is used for private networks, which are specially reserved and won't conflict with any host in the Internet:
  • 192.168/16 (subnet 192.168.0.0, netmask 255.255.0.0)
  • 172.16/12 (subnet 172.16.0.0, netmask 255.240.0.0)
  • 10/8 (for large networks; subnet 10.0.0.0, netmask 255.0.0.0)
See also RFC 1918.

起動時に固定 ip を割り当てるには、ネットワーク設定#固定 IP アドレスを参照。

デフォルトの dhcpd.conf にはアンコメントされている例がたくさん含まれているので、ファイルを移動してください:

# mv /etc/dhcpd.conf /etc/dhcpd.conf.example

最小限の設定ファイルは以下のようになります:

/etc/dhcpd.conf
option domain-name-servers 8.8.8.8, 8.8.4.4;
option subnet-mask 255.255.255.0;
option routers 139.96.30.100;
subnet 139.96.30.0 netmask 255.255.255.0 {
  range 139.96.30.150 139.96.30.250;
}

特定のデバイスで固定 IP アドレスを使う必要がある場合、以下の構文を使います:

/etc/dhcpd.conf
option domain-name-servers 8.8.8.8, 8.8.4.4;
option subnet-mask 255.255.255.0;
option routers 139.96.30.100;
subnet 139.96.30.0 netmask 255.255.255.0 {
  range 139.96.30.150 139.96.30.250;

  host macbookpro{
   hardware ethernet 70:56:81:22:33:44;
   fixed-address 139.96.30.199;
  }
}

domain-name-servers option contains addresses of DNS servers which are supplied to clients. In our example we are using Google's public DNS servers. If you know a local DNS servers (for example, provided by your ISP), you should use it. If you've configured your own DNS on a local machine, then use its address in your subnet (e. g. 139.96.30.100 in our example).

subnet-mask and routers defines a subnet mask and a list of available routers on the subnet. In most cases for small networks you can use 255.255.255.0 as a mask and specify an IP address of the machine on which you're configuring DHCP server as a router.

subnet blocks defines options for separate subnets, which are mapped to the network interfaces on which dhcpd is running. In our example this is one subnet 139.96.30.0/24 for single interface eth0, for which we defined the range of available IP addresses. Addresses from this range will be assigned to the connecting clients.

設定後、systemctl を使って dhcpd4.service を起動することで dhcpd デーモンを起動できます。任意で、ブート時に自動的に起動するように有効化してください。

一つのインターフェイスだけを使う

If your computer is already part of one or several networks, it could be a problem if your computer starts giving ip addresses to machines from the other networks. It can be done by either configuring dhcpd or starting it as a daemon with systemctl.

dhcpd の設定

In order to exclude an interface, you must create an empty declaration for the subnet that will be configured on that interface.

This is done by editing the configuration file (for example):

/etc/dhcpd.conf
# No DHCP service in DMZ network (192.168.2.0/24)
subnet 192.168.2.0 netmask 255.255.255.0 {
}

サービスファイル

デフォルトではインターフェイスを一つだけ使用する dhcpd のサービスファイルは存在しないため、作成する必要があります:

 /etc/systemd/system/dhcpd4@.service
[Unit]
Description=IPv4 DHCP server on %I
Wants=network.target
After=network.target

[Service]
Type=forking
PIDFile=/run/dhcpd4.pid
ExecStart=/usr/bin/dhcpd -4 -q -pf /run/dhcpd4.pid %I
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

上記は、特定のインターフェイスに bind するテンプレートユニットです。例えば dhcp4d@eth0.service などとして使います (eth0ip link で確認できるインターフェイスに置き換えて下さい)。

PXE

PXE の設定は以下の2つのオプションで行います:

/etc/dhcpd.conf
next-server 192.168.0.2;
filename "/pxelinux.0";

This section can either be in an entire subnet or just in a host definition. next-server is the IP of the TFTP Server, and filename is the filename of the image to boot. For more information see PXE.