2008年9月22日 星期一

Debian DHCP server設定

  • 安裝dhcp server套件

    debian:~# apt-get install dhcpd

  • 基本設定

    指定listen的介面

    debian:~# vi /etc/default/dhcp
    INTERFACES="eth0"

    debian:~# vi /etc/init.d/dhcp
    # Defaults
    INTERFACES="eth0"

  • DHCP模式

    1. 單純DHCP:同一區網內,一電腦為DHCP Server,並單純做IP的指派,介面設定為eth0即可

      debian:~# vi /etc/dhcpd.conf

      add/fix

      option domain-name-servers 140.134.4.1; #設定dns
      default-lease-time 600; #設定租約
      max-lease-time 7200;

      #network/netmask 這邊是用子網路切割140.134.210.128/25

      subnet 140.134.210.128 netmask 255.255.255.128 {
      range 140.134.210.240 140.134.210.245; #ip範圍
      option routers 140.134.210.254; #GATEWAY
      option subnet-mask 255.255.255.128; # netmask
      option broadcast-address 140.134.210.255; #broadcast
      }

      "option routers 140.134.210.254;"的設定如果將ip改成DHCP Server的電腦,就會變成DHCP/NAT的模式

    2. DHCP/NAT:eth0為外網設定eth1為內網,並需將listen的介面改成eth1,並利用iptables做nat的轉換

      network--eth0 eth1-- local

      debian:~# vi /etc/dhcpd.conf

      add/fix

      option domain-name-servers 140.134.4.1; #設定dns
      default-lease-time 600; #設定租約
      max-lease-time 7200;

      subnet 192.168.20.0 netmask 255.255.255.0 {
      range 192.168.20.101 192.168.20.200; #ip範圍
      option routers 192.168.20.1; #GATEWAY,eth1的ip
      option subnet-mask 255.255.255.0; # netmask
      option broadcast-address 192.168.20.255; #broadcast
      host inside {
      hardware ethernet 08:00:27:C9:D0:47; #靜態DHCP設定
      fixed-address 192.168.20.100;#指定ip
      }
      }

      設定iptables nat,如不做此設定local網路會無法上網

      debian:~# echo "1" > /proc/sys/net/ipv4/ip_forward
      debian:~# iptables -t nat -A POSTROUTING -s 192.168.20.0/24 -j MASQUERADE

1 則留言:

陳亮宇 提到...

謝謝你寫下這分文件!