透過靜態 mac-addr 到 IP 映射的 Internet 共享

透過靜態 mac-addr 到 IP 映射的 Internet 共享

我可以透過在我的 ubuntu 機器和第二台機器之間連接乙太網路電纜,然後將“IPv4”設定為“共用到其他電腦”,在我的 ubuntu 14.04 和另一台機器之間建立網路。建立的網路的 IP 類似於 10.42.0.x。我這樣做不是為了共享互聯網,而是為了在兩台機器之間創建網絡,而且效果非常好。

為了讓兩台電腦使用主機名稱相互定址,我將使用各自的 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.confvia 中指定 via MAC:

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

免責聲明:我實際上對 dnsmasq 並不熟悉,但 DHCP 範例直接來自我的系統。

相關內容