20151104_威聯通QNAP TS-453mini NAS開啟PPPOE及NAT

NAS 型號 TS-453mini

韌體版本:4.2

方法:

1.先由網頁APP CENTER 安裝PPPOE程式,並啟動PPPOE,設定好撥接帳號密碼,測試撥接可否成功。

2.以SSH連到NAS

3.修改 /etc/config/qpkg.conf

加入以下文字


[autorun]

Name = autorun

Version = 0.1

Author = PolinWei

Date = 2013-06-08

Shell = /share/Public/qnapautorun.sh

Install_Path = /share/Public

Enable = TRUE

說明:開機時會自動執行public 目錄內的qnapautorun.sh

4.建立qnapautorun.sh檔

先在/home下建一個admin目錄,本目錄會重新開機後會消失。

在/home/admin目錄qnapautorun.sh

內容如下


#!/bin/sh

#Try to config the network as i needed!

#dial pppoe first to create the wan port,which connect through the eth0

pppoe-stop

pppoe-start

#set all the other port to lan port

#ifconfig eth1 169.254.99.100 netmask 255.255.255.0

#ifconfig eth2 169.254.100.100 netmask 255.255.255.0

#ifconfig eth3 169.254.101.100 netmask 255.255.255.0

#iptable setting ,share the network

iptables -F

iptables -P INPUT ACCEPT

iptables -P FORWARD ACCEPT

#need to wait for the ppp link

iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE #open nat

說明:

因為測試發現QNAP 自行撥接的PPPOE連線無法正常做NAT分享,所以在qnapautorun.sh內,PPPOE要先掛斷再重新再撥接

修改執行屬性(一定要先改屬性,等搬到/share/public 目錄後就不能改屬性了)


chmod +x /home/admin/qnapautorun.sh

將qnapautorun.sh 搬到 /share/Public 內


mv /home/admin/qnapautorun.sh /share/Public

說明:

因為NAS重新開機後/home/admin 目錄會消失,所以要放到/share/Public 內

ETH1和ETH2均使用虛擬IP,並且不要預設閘道,
啟用NAS的DHCP功能(在ETH1的設定畫面內),NAS就可同時具有DHCP及NAT功能了。

 

自訂DHCP 伺服器(固定IP與黑名單)

DHCP 設定檔位於  /etc/dhcpd.conf

DHCP 執行程式位於 /etc/init.d/dhcpd.sh,且執行時會自動重新產生/etc/dhcpd.conf
(語法:dhcpd.sh start/restart/stop)

但以上二個檔案均無法修改(改好重新開機就會回復)

所以需複製一個dhcpd.sh 到/share/Public內,並修改以下二行

#把自動產生dhcpd.conf的指令關閉

#/usr/sbin/create_dhcpd_conf

#把自訂的dhcpd.conf 複製到/etc


cp /share/Public/dhcpd.conf /etc/dhcpd.conf

 

同時將以下指令加到/share/Public/qnapautorun.sh 最後一行

#for dhcpd to load custom config in /share/Public/dhcpd.con

/share/Public/dhcpd.sh restart

接著就可以自訂dhcpd.conf了

 

拒絕某一MAC取得IP(用於SEEDNET 070網路電話盒)


host voip  {
hardware ethernet   00:1e:d8:18:85:62;;
deny booting;
}

設定固定IP


host sammyhome {
hardware ethernet d0:50:99:8F:09:C7;
fixed-address 192.168.2.1;
}

dhcpd.conf 完整內容如下


max-lease-time 86400;
default-lease-time 86400;
ddns-update-style ad-hoc;
allow booting;
allow bootp;
class "pxeclients" {
match if substring(option vendor-class-identifier,0,9)="PXEClient";
next-server 0.0.0.0;
filename "pxelinux.0";
}
subnet 192.168.0.0 netmask 255.255.252.0 {
range 192.168.1.100 192.168.1.200;
option routers 192.168.2.80;
option domain-name  "oat.tw";
option netbios-name-servers 192.168.2.80;
option domain-name-servers 168.95.1.1, 8.8.8.8;
}
host myclient {
hardware ethernet 00:08:9B:F0:60:FE;
deny booting;
}

host voip {

hardware ethernet 00:1e:d8:18:85:62;
deny booting;
}
host sammyhome {
hardware ethernet d0:50:99:8F:09:C7;
fixed-address 192.168.2.1;
}

關閉dhcpd程式

kill -HUP `pidof dhcpd`

 

dhcp分配記錄檔位置

/var/state/dhcp/dhcpd.leases

/etc/config/dhcp/dhpcd.leases

 

跳至工具列