2015/4/20

【樹莓派】架設DHCP Server

首先安裝DHCP Server套件
sudo apt-get install isc-dhcp-server
安裝完畢系統會嘗試帶起服務,但設定都還沒弄好所以會看到錯誤訊息,忽略即可。
[FAIL] Starting ISC DHCP server: dhcpd[....] check syslog for diagnostics. ... failed!
 failed!
invoke-rc.d: initscript isc-dhcp-server, action "start" failed.

設定eth0網卡IP為192.168.0.1,修改/etc/network/interfaces文件
#iface eth0 inet dhcp
allow-hotplug eth0
iface eth0 inet static
  address 192.168.0.1
  netmask 255.255.255.0
  gateway 192.168.0.1

設定dhcp組態文件/etc/dhcp/dhcpd.conf,文件中有很多範例可以參考,依據自己需求挑一個合適的範本進行設定,這裡讓Server會配發192.168.0.200到192.168.0.253之間的IP給Client端
subnet 192.168.0.0 netmask 255.255.255.0 {
  range 192.168.0.200 192.168.0.253;
  option routers 192.168.0.1;
  option broadcast-address 192.168.0.255;
  default-lease-time 600;
  max-lease-time 7200;
  option domain-name-servers 168.95.1.1;
}

編輯/etc/default/isc-dhcp-server文件,指定提供DHCP服務的網卡,找到INTERFACES敘述,填上eth0
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#       Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACES="eth0"

最後重新啟動服務,看到ok就表示服務正常啟動了
sudo service isc-dhcp-server restart
[ ok ] Stopping ISC DHCP server: dhcpd.
[ ok ] Starting ISC DHCP server: dhcpd.

這時接上一台電腦應該就會自動獲取RPi指派的IP了,可以搭配【無線網路轉送有線網路橋接】設定封包轉送服務,這樣RPi就可以當作一台簡易的無線轉有線橋接器!

沒有留言:

張貼留言