參考網站:
Banana Pi R1 (BPi-R1) Part 2 有線router設定 講 iT
Banana Pi Router – BPi-R1 Manual for HW setup and basic router functionalities
1.安裝 DHCP Server 來派送 IP
# apt-get install dnsmasq
2. 備份設檔
# cp /etc/dnsmasq.conf /etc/dnsmasq.conf.$(date +%F)[@more@]3. 修改設定檔 /etc/dnsmasq.conf
加入下面的設定到檔案的最後
# Client 端的 DNS Server 設定
dhcp-option=6,140.111.66.1,168.95.1.1
# DHCP Server 所在的 IP
listen-address=192.168.85.1
# 發送 IP 的網路介面
interface=eth0.102
# IP 派送的範圍及時間
dhcp-range=192.168.85.101,192.168.85.150,12h
進行修改
# sed -i ‘$a dhcp-option=6,140.111.66.1,168.95.1.1nlisten-address=192.168.85.1ninterface=eth0.102ndhcp-range=192.168.85.101,192.168.85.150,12h’ /etc/dnsmasq.conf
4. 讓設定生效,修改 /etc/default/dnsmasq
# cp /etc/default/dnsmasq /etc/default/dnsmasq.$(date +%F)
# sed -i ‘s|#DNSMASQ_OPTS=”–conf-file=/etc/dnsmasq.alt”|DNSMASQ_OPTS=”–conf-file=/etc/dnsmasq.conf”|’ /etc/default/dnsmasq
# sed -i ‘s/^CONFIG_DIR/#CONFIG_DIR/’ /etc/default/dnsmasq
5. 開啟 NAT 的 IP Forward,修改 /etc/sysctl.conf
# cp /etc/sysctl.conf /etc/sysctl.conf.$(date +%F)
# sed -i ‘$a net.ipv4.ip_forward = 1’ /etc/sysctl.conf
6. 在 /etc/rc.local 中加入下面這一行
iptables -t nat -A POSTROUTING -s 192.168.85.0/24 -o eth0.101 -j MASQUERADE
進行修改
# sed -i ‘/exit 0/ i iptables -t nat -A POSTROUTING -s 192.168.85.0/24 -o eth0.101 -j MASQUERADE’ /etc/rc.local
更詳細的防火牆設定可以查詢相關資料。