静的 MAC アドレスから IP へのマッピングによるインターネット共有

静的 MAC アドレスから IP へのマッピングによるインターネット共有

Ubuntu マシンと 2 台目のマシンの間にイーサネット ケーブルを接続し、「IPv4」を「他のコンピューターと共有」に設定することで、Ubuntu 14.04 と別のマシンの間にネットワークを作成できます。作成されたネットワークの IP は 10.42.0.x のようになります。インターネットを共有するためではなく、2 台のマシン間にネットワークを作成するためにこれを行っていますが、これは非常にうまく機能しています。

2 台のマシンがホスト名を使用して相互にアドレス指定するには、それぞれの IP で /etc/hosts を編集します。最近のルーターに搭載されている MAC から IP へのマッピングを使用して、これをもっと簡単にしたいと思います。これを実現する最も簡単な方法は何でしょうか?

答え1

通常、MACアドレスに基づくIPアドレスの割り当ては、DHCPサーバーおよびその構成ファイルは にあります/etc/dhcp/dhcpd.conf。以下の例では、ゲスト用に IP アドレスのプールを予約し、残りは MAC に基づいて割り当てられます。

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# option definitions common to all supported networks...

default-lease-time 86400;
max-lease-time 93000;
option domain-name "xxxxxx.com";
option domain-name-servers 192.168.111.1;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.111.255;
option routers 192.168.111.1;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# The Basic DHCP allocated addresses

subnet 192.168.111.0 netmask 255.255.255.0 {
  range 192.168.111.3 192.168.111.50;
}

# Some specifically declared static IP addresses

host Wireless-R {
  hardware ethernet 00:22:6B:82:01:55;
  fixed-address 192.168.111.57;
}

host Doug-XPS {
  hardware ethernet 00:23:4d:a6:ed:c4;
  fixed-address 192.168.111.100;
}

host Doug-XPS {
  hardware ethernet 00:23:4d:a6:ed:c4;
  fixed-address 192.168.111.100;
}

host Doug-XPS2 {
  hardware ethernet 00:21:9B:F9:21:26;
  fixed-address 192.168.111.101;
}

host S10 {
  hardware ethernet A0:F3:C1:10:22:EA;
  fixed-address 192.168.111.102;
}

あるいは、dnsmasq を使用することを好む場合、またはすでにデフォルトで使用している場合は、次の/etc/dnsmasq.conf方法で MAC 経由で指定できます。

doug-xps=00:23:4d:a6:ed:c4,192.168.111.100

免責事項: 私は実際には dnsmasq に精通していませんが、DHCP の例は私のシステムから直接取得したものです。

関連情報