Friday, May 4, 2012

DHCP NAT on FreeBSD

 結果還是放棄 Linux server 方案了

KVM 的 Bridge tune 很久還是 tune 不通 orz

最後跟 Apua 借了兩台 VM

=================================

DHCP


# whereis isc-dhcp42-server
isc-dhcp42-server: /usr/ports/net/isc-dhcp42-server


請一邊服用    Handbook  說明


先改 dhcpd.conf 設定檔


# vim /usr/local/etc/dhcpd.conf


option domain-name "example.org";
option domain-name-servers 10.0.0.5;   # 我自己的 IP
option subnet-mask 255.255.255.0;


default-lease-time 600;
max-lease-time 7200;

subnet 10.0.0.0 netmask 255.255.255.0 {   # 要 Listen 的 subnet
  range 10.0.0.10 10.0.0.20;              # 發這段出去
  option routers 10.0.0.5;                # 從我家流出去
}

host ftp {       # 定義一組 host <=> MAC <=> static IP
  hardware ethernet 00:50:56:b4:01:4c;
  fixed-address 10.0.0.14;
}

改 /etc/rc.conf

#vim /etc/rc.conf

# for NAT
pf_enable="YES"
pflog_enable="YES"
gateway_enable="YES"

# 要 listen 的網卡的 interface 設好
ifconfig_em1="inet 10.0.0.5 netmask 255.255.255.0"

# 開啟 dhcpd 
dhcpd_enable="YES"

# 要 listen 這張
dhcpd_ifaces="em1"

dhcpd_conf="/usr/local/etc/dhcpd.conf"
dhcpd_withumask="022"


最後一步,開啟服務

# /usr/local/etc/rc.d/isc-dhcpd start

error log in /var/log/messages 

要 listen 的 subnet 跟發出去的 range 要一樣,我卡這關卡好久XD






NAT 

這裡用 pf 來設,handbook 上面是用另一套 ipfw

在 pf.conf 裏面加上

#vim /etc/pf.conf

ext_if="em0"               # 接外網
int_if="em1"               # 接內網
ext_ip="my public IP"      # public IP
int_ip="10.0.0.5"          # DHCP 發的
lan_net="10.0.0.0/24"      # subnet

nat on $ext_if from { $lan_net } to any -> ($ext_if)


No comments:

Post a Comment