2007年10月9日 星期二

【Debian】安裝OpenVPN

會想裝openvpn的理由主要是想從學校連回家裡的samba抓檔案,算是很單純的動機吧(茶)

1. 安裝openvpn

apt-get install openvpn

2. 建立Certificate Authority(CA)和產生certificates與金鑰
(1) 先切換目錄至/usr/share/doc/openvpn/examples/easy-rsa,執行

. ./vars (注意!! . 和 . 之間有空一格)

(2) 建立CA,產生出來檔案會放置在./keys/目錄

./clean-all
./build-ca

執行結束後會產生 ca.crtca.key 兩個檔案

(3) 建立 server 用的 certificate & key

./build-key-server server

會出現幾個問題,其中的"Common Name"設server(當然也可以設定自己所要的名稱,只是產 生的檔名會不同而已)則產生 01.pemserver.crtserver.csrserver.key

(4) 建立 client 用的 certificate & key

./build-key client1

跟server差不多,也會出現問題。Common Name設成client1會產生 client1.crtclient1.csrclient1.key
以此類推,可以產生其他的client key,ex client2、client3…

(5) 產生 Diffie Hellman parameters

./build-dh

會產生 dh1024.pem

3. 增強OpenVPN的安全性
產生一個secret key

openvpn --genkey --secret ta.key

會在所在目錄上產生 ta.key(之後設定檔會用到)

4. server端的設定
(1) 複製certificates & keys到/etc/openvpn (其實只要跟設定檔同目錄就好,只是一般設定檔是放置於此)

cp ./keys/ca.* /etc/openvpn/
cp ./keys/server.* /etc/openvpn/
cp ./keys/dh1024.pem /etc/openvpn/
cp ./ta.key /etc/openvpn/
(注意!! 以上指令均是預設所在目錄為/usr/share/doc/openvpn/examples/easy-rsa/下)

(2) 產生設定檔 server.conf

cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
gzip -d /etc/openvpn/server.conf.gz

(3) 編輯 server.conf
設定檔內要有以下內容

local 對外的public-IP //這邊要設定外面連線得到的IP,設為區網的private-IP會無法連線成功
port 1194 //vpn server的port。這是預設就有的,沒太大問題

proto udp //使用協定

dev tun //使用tun device。另有tap,在比較複雜的環境所用的。

tls-server //這行是檔案裡沒有的,請自行加上
ca ca.crt //此設定為之前所產生CA檔名
cert server.crt //設定為所產生的certificate檔名
key server.key //設定為所產生的key檔名

tls-auth ta.key 0

dh dh1024.pem

server 10.8.0.0 255.255.255.0 //設定vpn網域。前為network,後為netmask。可自行設定,不與現有的network相同即可

ifconfig-pool-persist ipp.txt

push "route 192.168.1.0 255.255.255.0" //將設定的network加入路由。若想與網域其他電腦連線則須加入此設定

push "redirect-gateway" //client連線後自動給定一個default gateway

push "dhcp-option DNS 10.8.0.1" //client連線後的DNS設定。預設是為vpn server本身為DNS,若不是則要改為其他的DNS IP。

duplicate-cn

keepalive 10 120 //每10秒ping1次,若120秒內沒收到封包則認定斷線

comp-lzo //在vpn link上啟用壓縮

max-clients 10 //最大client數

user nobody //vpn daemon執行身分
group nogroup //vpn daemon執行群組

persist-key
persist-tun

status openvpn-status.log //status log檔名設定

log openvpn.log //log檔名設定

verb 3

(4) 啟動VPN Server
若模組tun尚未載入(用lsmod查看),則需先執行modprobe tun

/etc/init.d/openvpn start

若沒出現錯誤訊息,表示啟動成功。

(5) Firewall 及 NAT 設定

iptables -A INPUT -p UDP -i ppp0 --dport 1194 -j ACCEPT //開放對外介面pp0的udp port 1149
iptables -A INPUT -i tun+ -j ACCEPT

iptables -A FORWARD -i tun+ -j ACCEPT

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o ppp0 -j MASQUERADE //對vpn網域的封包作masquerade

(6) Bind9設定
在/etc/bind/named.conf.options加入:

allow-query {127.0.0.1; 192.168.1.0/24; 10.8.0.0/24;};

存檔後重新啟動bind9。

5. client端的設定(以windows為例)
(1) openvpn for windows安裝完成後,將ca.crtca.keyclient1.crtclient1.csrclient1.keydh1024.pemta.key複製到c:/Program Files/OpenVPN/config中

(2) 將c:/Program Files/OpenVPN/sample-config的client.ovpn複製到c:/Program Files/OpenVPN/config

(3) 修改client.ovpn設定
client

dev tun
proto udp
remote vpn server的public-IP 1194

nobind
persist-key
persist-tun

tls-client
ca ca.crt
cert client1.crt
key client1.key

tls-auth ta.key 1

ns-cert-type server
comp-lzo

儲存後,開啟"服務"將OpenVPN Service啟動,TAP-Win32 Adapter即會連上vpn server並取得其ip設定


Reference:
OpenVPN , DebianWiki Taiwan:http://www.debian.org.tw/index.php/OpenVPN

2007年9月16日 星期日

【Debian】重灌後預計要掛上的套件

  • apache2
  • php5
  • mysql
  • openvpn
  • mldonkey
  • samba
  • hostapd
  • madwifi-source
  • madwifi-tools
  • bridge-utils
  • dhcp3
  • bind
  • iproute2
  • pppoeconf
  • vim

【Debian】預定的硬碟規劃

目前計畫裝上新買的seagate 320G(SATAII) 企業版 及之前桌機用的 seagate 80G(SATA)
並將原本的主硬碟 WD 40G(IDE) 淘汰,動物園 Seagate 160G(IDE)則繼續使用

所以目前硬碟架構為:
  • Seagate 320G 企業版 (SATAII)
    • SWAP : 1G
    • /var : 10G
    • /usr : 10G
    • / : 10G
    • /home : 89G
    • /shared_data : 200G
  • Seagate 80G (SATA)
    • /anime_dock : 80G
  • Seagate 160G (IDE)
    • /p2p : 160G

2007年9月15日 星期六

【Debian】madwifi以AP模式運作之設定

執行 wlanconfig ath0 create wlandev wifi00 wlanmode ap 即可

【Debian】bridge 安裝與設定

.安裝bridge-utils套件
執行 apt-get install bridge-utils 即可

.設定bridge
執行下列步驟:
brctl addbr br0
brctl addif br0 eth1
brctl addif br0 ath0

之後執行ifup br0 即可啟動bridge

PS. 記得要先至/etc/network/interfaces中做好br0的設定

【Debian】interfaces設定

#primary network interface (eth0) 對外介面
auto eth0
iface eth0 inet static
address 192.168.100.1
netmask 255.255.255.0
broadcast 192.168.100.255
network 192.168.100.0
gateway 192.168.100.1

#bridge interface (連接eth0及ath0)
auto br0
inface br0 inet static
address 192.168.1.254
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
bridge_port eth1 ath0

【Debian】madwifi 快速安裝法

執行 vi /etc/apt/sources.list

依自己所要的版本加入:
# Unstable
deb ftp://ftp.au.debian.org/debian unstable main contrib non-free
deb-src ftp://ftp.au.debian.org/debian unstable main contrib non-free

# Testing
deb ftp://ftp.au.debian.org/debian testing main contrib non-free
deb-src ftp://ftp.au.debian.org/debian testing main contrib non-free

# Stable
deb ftp://ftp.au.debian.org/debian stable main contrib non-free
deb-src ftp://ftp.au.debian.org/debian stable main contrib non-free

存檔離開後執行下列步驟
apt-get update
apt-get install madwifi-source madwifi-tools
m-a prepare
m-a a-i madwifi

以上完成即可產生apt_pci module

最後執行 modprobe ath_pci 將module掛上就完成安裝囉!!

PS. 執行 echo ath_pci >> /etc/modules, 在下次重開機時就會自動將ath_pci掛載好囉