(12)配置samba服務器
.....
(13)構建基于linux的vpn網絡
構建vpn幾乎是linux的最高級應用之一了,學會了這項技術,是足以使你自豪的資本。vpn的主要用途就是建立一個加密的通信機制,然后通過把所有的你的子網的信息按照特定的方式加密傳輸,構成一個邏輯上的虛擬的網絡。簡單的說,就是一個linux系統的ip層加密解決方案。這里面需要用到不少組件,下面一一介紹。
1、準備工作和安裝
1.1 從http://www.kernel.org下載2.4.x的內核,除了2.4.15版本(該版本有一個致命錯誤)。然后把該內核放置到:/usr/src中。(這里我們使用linux-2.4.18.tar.gz),然后釋放:tar zxvf linux-2.4.18.tar.gz
1.2 刪除原來的連接rm linux
1.3 ln –s linux-2.4.18.tar.gz linux
1.4 檢查當前的網卡和scsi的型號(參見內核升級一章)
1.5 cd linux (進入linux-2.4.18目錄)
1.6 make menugonfig
1.7 make dep
1.8 make bzimage
1.9 編譯工作做到這里就打??!
1.10 從http://www.swox.com/gmp 下載gmp庫的最新版本到/usr/local/src。
1.11 tar zxvf gmp-4.0.1.tar.gz
1.12 cd gmp-4.0.1
1.13 ./configure
1.14 make
1.15 make install
1.16 從http://www.freeswan.org下載freeswan-1.97.tar.gz(我們這里使用的版本)到/usr/local/src
1.17 tar zxvf freeswan-1.97.tar.gz
1.18 從http://www.strongsec.com/freeswan/ 下載x509patch-0.9.11-freeswan-1.97.tar.gz ,這個是補丁文件。釋放,進入x509補丁目錄,復制freeswan.diff到外面的freeswan源目錄,然后回到freeswan源目錄中運行:patch –p1 < freswan.diff
1.19 從http://www.openssl.org下載openssl-0.9.6b版本到/usr/local/src,釋放,進入目錄
1.20 ./config (如果原來系統中有openssl需要先uninstall再安裝,不過一般情況下你可能uninstall不下來8-)。如果無法uninstall,找到他們的路徑,在這里通過—prefix=參數指定路徑覆蓋舊版本的文件。這里嚴重建議:如果你沒有把握確定路徑,最好這樣做:到你用的發行包的開發商的ftp站點(如果你用turbolinux就去ftp.turbolinux.com用redhat就去ftp.redhat.com),用anonymous用戶和隨便一個電子郵件作為密碼登陸,找到你用的發行包版本的生機目錄,然后下載相應的rpm包,注意:這里的包至少應該是0.9.6b1以上的i386版本。下載完畢后用rpm –uvh更新。這樣做完了很干凈。
1.21 make (如果你用rpm包升級就不用這個步驟了)
1.22 make test (如果你用rpm包升級就不用這個步驟了)
1.23 make install (如果你用rpm包升級就不用這個步驟了)安裝完了以后執行openssl命令,輸入version看看是不是你剛剛安裝的版本。如果不是,可能沒有覆蓋原來安裝的舊版本。從1.20重新來過
1.24 然后回到freeswan的源目錄,運行:make menugo,在networking options中選擇關于iptables和ipsec相關的所有選項。其中ipsec是freeswan加上的,最好把前面括號中m(模塊方式)換成*(編譯進內核)。下列內核選項應該選上:
進入:networking options至少選擇上:
[*] network packet filtering (replaces ipchains)
[*] network packet filtering debugging (new)
進入:ip: netfilter configuration --->
<*> connection tracking (required for masq/nat) (new)
ftp protocol support (new)
irc protocol support (new)
注意:如果你需要使用dhcp功能,需要增加pachet socket mmapped io和socket filtering兩個選項,參見dhcp一章。
等等……
把下面的選項全部標記<*>
返回上一層菜單后,把列表選項最下面的凡是ipsec相關的選項全部選為<*>。另外的,如果你打算使用撥號連接請在網絡設備支持菜單選擇ppp支持(注意,你用的ppp程序一定要2.4版本以上的)
1.25 然后檢查網卡和硬盤選項是否正確,如果沒有問題就逐層退出,然后保存配置。
1.26 退出后將自動編譯內核,等待……
1.27 編譯完成后,來到/usr/src/linux目錄,運行:make modules;make modules_install
1.28 cp system..map /boot/system.map-2.4.18-vpn
1.29 cd arch/i386/boot
1.30 cp bzimage /boot/vmlinuz-2.4.18-vpn
1.31 cd /boot
1.32 rm system.map
1.33 ln –s system.map-2.4.18-vpn system.map
1.34 vi /etc/lilo.conf
增加一段:
boot=/dev/sda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
lba32
default=linux-vpn
image=/boot/vmlinuz
label=linux
initrd=/boot/initrd
read-only
root=/dev/sda5
image=/boot/vmlinuz-2.4.18-vpn
label=linux-vpn
initrd=/boot/initrd
read-only
root=/dev/sda5
1.35 運行lilo更新數據
1.36 reboot
1.37 啟動后,運行:ipsec setup restart 應該不報任何錯誤而正常出現freeswan的版本。
注意:還有一些必要的內核參數配置,這些配置可以在rc.local中實現。他們是:
echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter
echo 1 > /proc/sys/net/ipv4/ip_forward
如果你把下面兩項編譯成模塊(前面擴號是m而不是*):
ftp protocol support (new)
irc protocol support (new)
你需要在rc.local中加上:
modprobe ip_nat_ftp
安裝完了,接下來我們將說明幾種vpn的玩法。
2、配置frees/wan用于支持雙網關通信。也就是兩個異地的子網通過一對ipsec的vpn網關進行交互訪問。第一種玩法是網絡對網絡的vpn。一般的,某企業在甲乙兩地(距離相當遠)各有一個辦公室,每個辦公室各有一套lan,他們分別通過專線連接到internet網絡上。甲lan上是企業的管理中心,運行著企業的管理系統。而乙lan上的用戶也需要使用該管理系統,盡管乙lan可以通過internet(公網)連接過去,但是企業的老板說不行!我們的數據不能暴露在公網上,必須加密!好了,我們的vpn網絡就可以應用于該企業的這種需求。首先在甲乙兩個lan的出口各放置一臺我們的linux服務器,他們都安裝好了ipsec(前面說的安裝步驟一個都不少),兩個lan的數據分別通過各自的這臺機器(ipsec gateway)進入公網,凡是經過該網關的數據全部都是加密的。在效果上,兩個lan的用戶可以互相ping到對方的機器,盡管他們可能一個是192.168.1.0/24網段,另一個是192.168.10.0/24網段的。他們好像在同一個局域網中工作,沒有界限。公共網絡的加密部分對他們來說也是透明的。而兩個lan在公共網絡上交換的數據是密文的。這就是虛擬專用網vpn。
但愿你已經按照前面的步驟順利的安裝好了兩臺機器,下面我告訴你怎樣配置成網對網的環境。
2.1 我們先配置甲網的ipsec網關(該網關有兩個網卡,我們配置他們的地址分別為eth1:192.168.1.231和eth0:21.9.22.22)。安裝完成后,我們首先要做的事情是生成ca證書。(用到剛才安裝的openssl)
2.2 找到openssl.cnf文件,一般在/etc/ssl/中,也可能在/var/ssl中或/usr/ssl中(實在不行你就find / -name “openssl.cnf”找找嘛?。?,要是有好幾個,你要搞清楚哪個是你安裝的版本。改動其中的default_bits選項的值從1024到2048,然后改動default_days的值到3650。讓期限為10年!保存退出。
2.3 在/var/中建立一個目錄:/var/sslca,改變該目錄的權限為700(chmod 700 /var/sslca)
2.4 在你安裝的openssl目錄中找到ca.sh腳本。注意,應該是你當前運行的openssl版本的ca.sh
2.5 cd /var/sslca 進入到你剛才建立的目錄
2.6 比如你剛才找到的ca.sh在/usr/lib/ssl/misc/,那么就輸入/usr/lib/ssl/misc/ca.sh –newca,接下來你會被問到一系列問題。問題和回答類似于下面的樣子。如果你確認哪些你有把握更改就改,比如公司名稱、郵件、密碼等。不能確定的就按照下面的樣子抄上即可。
~/sslca#/usr/lib/ssl/misc/ca.sh -newca
ca certificate filename (or enter to create)
(enter)
making ca certificate ...
using configuration from /usr/lib/ssl/openssl.cnf
generating a 2048 bit rsa private key
........................................+++
........................................+++
writing new private key to './democa/private/./cakey.pem'
enter pem pass phrase:(enter password)
verifying password - enter pem pass phrase:(enter same password again)
-----
you are about to be asked to enter
information that will be incorporated
into your certificate request.
what you are about to enter is what is called a distinguished name or a dn.
there are quite a few fields but you can leave some blank
for some fields there will be a default value,
if you enter '.', the field will be left blank.
-----
country name (2 letter code) [au]:us(enter)
state or province name (full name) [some-state]:state(enter)
locality name (eg, city) []:city(enter)
organization name (eg, company) [internet widgits pty ltd]:21vianet(enter)
organizational unit name (eg, section) []:(enter)
common name (eg, your name) []:ca(enter)
email address []:[email protected](enter)
~/sslca#
2.7 下一步是給網關生成證書:
命令和要回答的問題如下:
~/sslca# /usr/lib/ssl/misc/ca.sh -newreq
using configuration from /usr/lib/ssl/openssl.cnf
generating a 2048 bit rsa private key
...................................+++
...............................+++
writing new private key to 'newreq.pem'
enter pem pass phrase:(enter password)
verifying password - enter pem pass phrase:(repeat password)
-----
you are about to be asked to enter information that will be incorporated
into your certificate request.
what you are about to enter is what is called a distinguished name or a dn.
there are quite a few fields but you can leave some blank
for some fields there will be a default value,
if you enter '.', the field will be left blank.
-----
country name (2 letter code) [au]:us(enter)
state or province name (full name) [some-state]:state(enter)
locality name (eg, city) []:city(enter)
organization name (eg, company) [internet widgits pty ltd]:exampleco(enter)
organizational unit name (eg, section) []:(enter)
common name (eg, your name) []:vpnserver.rd.xxx.com(enter)
email address []:[email protected](enter)
please enter the following 'extra' attributes
to be sent with your certificate request
a challenge password []:(enter)
an optional company name []:(enter)
request (and private key) is in newreq.pem
[email protected]:~/sslca$ /usr/lib/ssl/misc/ca.sh -sign
using configuration from /usr/lib/ssl/openssl.cnf
enter pem pass phrase:(password you entered for the ca certificate)
check that the request matches the signature
signature ok
the subjects distinguished name is as follows
countryname :printable:'us'
stateorprovincename :printable:'state'
localityname :printable:'city'
organizationname :printable:'21vianet'
commonname :printable:'vpnserver.rd.xxx.com'
emailaddress :ia5string:'[email protected]'
certificate is to be certified until feb 13 16:28:40 2012 gmt (3650 days)
sign the certificate? [y/n]:y(enter)
1 out of 1 certificate requests certified, commit? [y/n]y(enter)
write out database with 1 new entries
data base updated
(certificate snipped)
signed certificate is in newcert.pem
在以上步驟中一定要記住你輸入的密碼。如果哪一不錯了,想重新來過的話,記住刪除/var/sslca目錄下面的所有子目錄即可。
2.8 把文件名字改為你需要的
~/sslca# mv newcert.pem vpnserver.rd.xxx.com.pem
~/sslca# mv newreq.pem vpnserver.rd.xxx.com.key
2.9 編輯.key文件,刪除'-----begin certificate request-----'后面所有的東西,之后,這個文件應該從'-----begin rsa private key-----'至'-----end rsa private key-----'結束。
2.10 如果正常的安裝了x.509補丁,你應該可以看到/etc/ipsec.d及其下面的目錄。如果沒有,你就自己建立。然后按照下面的位置復制合適的文件:(此時你仍然在/var/sslca目錄中)
# cp vpnserver.rd.xxx.com.key /etc/ipsec.d/private
# cp vpnserver.rd.xxx.com.pem /etc/ipsec.d
# openssl x509 -in democa/cacert.pem -outform der -out rootca.der
# cp rootca.der /etc/ipsec.d/cacerts/rootca.der
# openssl x509 -in host.example.com.pem -outform der -out /etc/x509cert.der
# openssl ca -gencrl -out crl.pem
# cp crl.pem /etc/ipsec.d/crls
2.11在/etc/ipsec.secrets中加入一行:: rsa vpnserver.rd.xxx.com.key "password",然后刪除其他所有行。其中的password是你前面生成密要的時候回答問題輸入的密碼。
2.12編輯ipsec.conf文件類似下面的樣子:
# basic configuration
config setup
interfaces=%defaultroute
klipsdebug=none
plutodebug=none
plutoload=%search
plutostart=%search
uniqueids=yes
conn %default
keyingtries=1
compress=yes
disablearrivalcheck=no
authby=rsasig
leftrsasigkey=%cert
rightrsasigkey=%cert
left=%defaultroute
leftcert=vpnserver.rd.xxx.com.pem
auto=add
pfs=yes
conn roadwarrior
right=%any
conn roadwarrior-net
leftsubnet=192.168.1.0/255.255.255.0
right=%any
conn net-net
leftsubnet=192.168.1.0/255.255.255.0
right=%any
rightsubnet=192.168.10.0/255.255.255.0
conn world-net
leftsubnet=*
right=%any
rightsubnet=192.168.10.0/255.255.255.0
黑體字的部分是你需要根據你實際的環境更改的。我們用的兩端的子網是192.168.1.0/24和192.168.10.0/24。文件中vpnserver.rd.xxx.com.pem是ca證書。這個配置是通用的,也就是說可以適用lan-lan方式的倆接和遠端客戶端兩種方式。
2.13 下面配置分支機構的網關。這個機器也要事先安裝完全freeswan等軟件。
重新執行上面的2.7-2.9步驟生成分支機構的證書,注意:在回答問題的過程中,關于主機名稱的部分的輸入改變為你分支機構的網關機器名稱,比如:vpncliet.rd.xxx.com。
2.14 復制下列生成的文件到分支機構網關上的相應位置(比如通過軟盤復制):
cp vpnserver.rd.xxx.com.pem /etc/ipsec.d
cp vpnclient.rd.xxx.com.key /etc/ipsec.d/private
cp vpnclient.rd.xxx.com.pem /etc/ipsec.d
執行命令:openssl x509 –in vpnclient.rd.xxx.com.pem –
outform der –out /etc/x509cert.de
cp rootca.der /etc/ipsec.d/cacerts/rootca.der
cp crl.pem /etc/ipsec.d/crls
2.15 配置分支機構的/etc/ipsec.secrets 寫上一行:
rsa vpnclient.rd.xxx.com.key "password"。
其他行刪除。password就是前面回答問題的時候輸入的密碼。
2.16 配置/etc/ipsec.conf
# basic configuration
config setup
interfaces=%defaultroute
klipsdebug=none
plutodebug=none
plutoload=%search
plutostart=%search
uniqueids=yes
conn %default
keyingtries=0
compress=yes
disablearrivalcheck=no
authby=rsasig
rightrsasigkey=%cert
leftrsasigkey=%cert
right=%defaultroute
rightcert=vpnclient.rd.xxx.com.pem
auto=add
pfs=yes
conn roadwarrior
left=21.9.22.22
leftcert=vpnserver.rd.xxx.com.pem
conn roadwarrior-net
left=21.9.22.22
leftcert=vpnserver.rd.xxx.com.pem
leftsubnet=192.168.1.0/255.255.255.0
conn net-net
left=21.9.22.22
leftcert=vpnserver.rd.xxx.com.pem
leftsubnet=192.168.1.0/255.255.255.0
rightsubnet=192.168.10.0/255.255.255.0
其中黑體的部分是你可以根據實際情況修改的。
2.17 首先啟動server端的ipsec:ipsec setup restart,然后同樣啟動客戶端的ipsec
2.18 建立通道:ipsec auto –up net-net然后在server端可以用命令ipsec whack status應該可以看到新建立的幾個通道。此時,你在兩個子網中應該可以互相ping 通。
3、配置frees.wan用于支持遠程客戶端訪問。也就是允許一個windows客戶端,來通過vpn和公司內部的網絡進行通訊。
第2種vpn玩法其實就是把分支機構的lan換成一個單獨的,地址不固定的機器。這樣的應用適合總經理出差的時候從外地isp撥號上網連接到本部網絡的情況。期間,非但有認證,而且通過isp和公網的數據全部是加密的。這種方式在服務器端的配置和上面完全一樣(記得嗎?我們在行面給出的配置已經是兼顧了兩種用法)。這里需要做的是把總經理的筆記本配成vpn客戶端。他的筆記本應該是windows2000的并且升級到sp2。
3.1 首先重復2.7-2.9步驟生成證書,其中有關主機名的部分可以輸入你總經理的機器名。類似于:win.rd.xxx.com。當然,總經理的機器要是同名的。
3.2 在服務器端生成windows可以認的p12格式的密鑰。
openssl pkcs12 -export
-in win.rd.xxx.com.pem
-inkey win.rd.xxx.com.key
-certfile democa/cacert.pem
-out win.rd.xxx.com.p12
3.3 用命令察看環境:最好把結果輸出到文件記住,以后用得到。
openssl x509 -in democa/cacert.pem -noout -subject
3.4 把上面生成的p12文件傳送到總經理的機器上,放在一個正規的地方(這個文件很重要)。
3.5 在總經理的機器上從http://vpn.ebootis.de站點下載:ipsec.exe
3.6 在總經理的機器上從: http://agent.microsoft.com/windows2000/techinfo/reskit/tools/existing/ipsecpolo.asp站點下載windwos2000的ipsec資源工具。
3.7 安裝上述兩個軟件,并且把他們放在同一個目錄中。
3.8 建立一個ipsec的mmc:(希望你知道mmc是什么)
依次進入start/run/mmc,
file (or console) - add/remove snap-in
單擊 'add'
選 'certificates', 然后選 'add'
選 'computer account', 然后點 'next'.
選 'local computer', 然后點 'finish'.
選 'ip security policy management', 然后點 'add'.
選 'local computer', 然后點 'finish'
選 'close' 然后點 'ok'
3.9 增加一個證書
展開左側窗口中 'certificates (local computer)'
右鍵 'personal', 選 'all tasks' 然后點 'import'
點 next
輸入哪個.p12 文件的路徑 (就是剛才你從服務器網關復制過來的,瀏覽選擇也可), 然后點'next' 輸入export password(密碼), 然后點next 選'automatically select the certificate store based on the type of certificate', 然后點next 點finish, 如果有任何提示窗口彈出都選yes 退出mmc, 保存當前配置到管理工具中,這樣就不用每次都重新來過了。以上所做就增加了一個證書到總經理的機器上。
3.10設置ipsec工具:
編輯總經理機器上的ipsec.conf文件,把rightca的=后面寫成剛才openssl x509 -in democa/cacert.pem -noout –subject命令生成的結果。類似下面這樣:
conn roadwarrior
left=%any
right=(ip_of_remote_system)
rightca="c=us,s=state,l=city,o=21vianet,
cn=ca,[email protected]"
network=auto
auto=start
pfs=yes
conn roadwarrior-net
left=%any
right=(ip_of_remote_system)
rightsubnet=192.168.1.0/24
rightca="c=us,s=state,l=city,o=21vianet,
cn=ca,[email protected]"
network=auto
auto=start
pfs=yes
黑體部分要注意配置正確。
3.12運行ipsec.exe有下面輸出:
c:ipsec>ipsec
ipsec version 2.1.4 (c) 2001,2002 marcus mueller
getting running config ...
microsoft's windows xp identified
host name is: (local_hostname)
no ras connections found.
lan ip address: (local_ip_address)
setting up ipsec ...
deactivating old policy...
removing old policy...
connection roadwarrior:
mytunnel : (local_ip_address)
mynet : (local_ip_address)/255.255.255.255
partnertunnel: (ip_of_remote_system)
partnernet : (ip_of_remote_system)/255.255.255.255
ca (id) : c=us,s=state,l=city,o=exampleco,...
pfs : y
auto : start
auth.mode : md5
rekeying : 3600s/50000k
activating policy...
connection roadwarrior-net:
mytunnel : (local_ip_address)
mynet : (local_ip_address)/255.255.255.255
partnertunnel: (ip_of_remote_system)
partnernet : (remote_subnet)/(remote_netmask)
ca (id) : c=us,s=state,l=city,o=exampleco,...
pfs : y
auto : start
auth.mode : md5
rekeying : 3600s/50000k
activating policy...
c:ipsec>
這時候你從客戶端ping服務器后面的內網得到幾個'negotiating ip security'之后就可以ping通了。這樣總經理帶著這臺筆記本到有互聯網絡的地方就可以象在辦公室一樣連接到公司里了。
值的注意的是,出于安全性的問題,我們建議你關閉vpn網關上面的所有其他服務,并仔細配置防火墻。通常的,如果你希望把所有的流量都發送給主站網關,在從站就不需要增加iptables策略。否則,需要增加這樣一條策略:
iptables –t nat –a postrouting –o eth0 –j masquerade
在主站由于路由的原因,需要增加下面的策略:
iptables –t nat –a postrouting –o ipsec0 –s ! 192.168.10.0/255.255.255.0 –
j snat –to 192,168.1.231
iptables –t nat –a postrouting –o eth1 –s ! 192.168.10.0/255.255.255.0 –
j snat –to 192,168.1.231
每行中前面的黑體是子網網段,后面的是本網關的內側出口。
注:原版資料在http://vpn.ebootis.de/ 詳細資料在:http://www.natecarlson.com/include/showpage.php?cat=linux&page=ipsec-x509
(14)安裝另一種郵件系統postfix
任何一種知名的事物似乎一定有至少一個跟風之作(微軟的windows系列似乎例外,跟風者無一例外的夭折了),并且這些后來者往往有他們更出色的方面才能立足。在unix世界的郵件服務器領域,沒有哪個產品能夠有sendmail程序這么大的名氣,盡管它有一個非?;逎呐渲梦募?。同樣的,有不少人為了改進sendmail的缺點做了很多其他的郵件服務器產品,并且的它們都有各自鮮明的特色,并且吸引了不少用戶。其中佼佼者當屬qmail和postfix郵件系統了。這里我們之所以選擇postfix介紹,主要基于下面兩個原因:其一、postfix是一個和sendmail一樣的為高負載郵件服務器設計的mta(郵件傳輸代理),而qmail處理能力要差一些(它比較適合中小型的應用場合)。在某些情況下postfix甚至比sendmail速度快3倍。其二、postfix是按照兼容sendmail的設計路子來做的,相當的配置文件都可以直接使用。這樣原有的sendmail用戶可很容易的升級的postfix。這是一個很“優惠”的升級條件,吸引了很多的原來的sendmail用戶。
安裝和配置postfix郵件系統的最基本步驟如下:
1、從http://www.postfix.org下載postfix的最新版本。我們這里使用的版本是postfix1.1.5,文件名字叫作postfix-1.1.5.tar.gz,把這個文件下載到/usr/local/src里面
2、cd /usr/local/src
3、tar zxvf postfix-1.1.5.tar.gz釋放壓縮文件
4、cd postfix-1.1.5
5、vi install仔細閱讀該安裝文件和注意事項。
6、make clean
7、make
8、useradd postfix (或者是adduser postfix)增加一個新的用戶。然后用:vi /etc/passwd 編輯用戶文件的postfix一行,讓該行看起來類似:postfix:*:2126:2128:postfix:/no/where:/no/shell 其中號碼部分不要改動。這主要是為了安全性考慮。
9、groupadd postdrop 建立一個組,但是這個組不能包括任何一個用戶。/etc文件中的相關行類似于:postdrop:*:54321:
10、檢查/etc/mail/aliases里面有沒有postfix: root一行,沒有就加上。
11、# mv /usr/sbin/sendmail /usr/sbin/sendmail.off
12、# mv /usr/bin/newaliases /usr/bin/newaliases.off
13、# mv /usr/bin/mailq /usr/bin/mailq.off
14、# chmod 755 /usr/sbin/sendmail.off /usr/bin/newaliases.off /usr/bin/mailq.off
15、make install (新安裝)
16、make upgrade (升級)
在執行上述兩步(選擇其中一個)的時候,腳本會提問許多路徑什么的,建議不要做改動一路回車下來,除非你確定你知道改動默認值的必要性。
17、啟動是postfix start
注意:以上步驟10-14是從sendmail升級的時候用的。
很可能的,這樣安裝完了系統還不能收發郵件。首先,你應該安裝一個pop3郵件接收協議服務(參見pop3安裝)。另外的,需要按照下列步驟檢查一下相關的配置文件。
1、/etc/mail/access是允許訪問的控制文件,類似下面內容,注意:地址就別照抄了。
127.0.0.1 relay
21.9.22 relay
211.151.194.14 relay
事實上這個文件可以定義得相當復雜。模板和說明可以參照:/etc/postfix/access
2、編輯完成/etc/access文件,還要把它編譯成數據庫格式:makemap hash access.db < access
3、/etc/mail/aliases是別名文件,類似下面的內容:
mailer-daemon: postmaster
postmaster: root
bin: root
daemon: root
nobody: root
postfix: root
這個文件的模板和說明可以參見/etc/postfix/aliases。編輯完成后,用newaliases aliases轉換成數據庫格式。
4、/etc/mail/local-host-names寫了本地主機的名字,內容類似于:
rd.xxx.com
tls65.rd.xxx.com
5、主配置文件:/etc/postfix/main.cf ,看一下內容,比sendmial.cf強多了吧?每一項都有詳細的說明和示例。最主要的(僅能使運行的)配置項目在載面介紹一下。
5.1 mydomain
指明你的域名,在這里我們指定:
mydomain = test.com
5.2 myorigin
myorigin參數指明發件人所在的域名。如果你的用戶的郵件地址為[email protected],則 該參數指定@后面的域名。在這里我們指定:
myorigin = $mydomain
5.3 mydestination
mydestination參數指定postfix接收郵件時收件人的域名,換句話說,也就是你的postfix 系統要接收什么樣的郵件。通常與myorigin一樣:
mydestination = $mydomain
5.4 mynetworks_style
設置網絡類型,我們指定:
mynetworks_style = subnet
5.5mynetworks
定義可以使用的此smtp服務器發信的客戶ip地址,因為公司的ip范圍已知,所以我們指定:
mynetworks = 192.168.1.0/24
6、設定dns服務器的mx記錄。例如,在域test.com中,安裝postfix的服務器名字叫mail.test.com,則在本域的dns中設定mx記錄為mail.test.com
7、更改設定后不必重新啟動postfix,只需要用postfix reload命令重新加載配置即可。
8、post還支持虛擬域名,配置方法如下:
8.1 首先把otherdomain.com(要用的虛擬域名)的mx記錄指向mail.test.com(本域的郵件服務器),這個配置在負責解析otherdomain.com的dns做。
8.2 為了讓用戶可以使用[email protected]收發郵件,我們必須配置虛擬域,在main.cf文件中,我們添加以下內容:
virtual_maps = hash:/etc/postfix/virtual
這里假定用戶tom、test、white需要使用這個虛擬域名,當然首先要在系統中添加這幾個用戶(用useradd或adduser填加系統用戶),然后建立/etc/postfix/virtual文件并添加以下內容:
othername.com anything
[email protected] tom
[email protected] test
[email protected] white
之后,用postmap命令生成虛擬域數據庫:
postmap /etc/postfix/virtual
明白上面配置文件的例子,你就可以非常靈活的多域名郵件系統了。
五、日常維護
責任編輯提示:這篇文章是熱心網友所發,里面還有一些內容沒有完整,請與這位作者直接聯系。:)