實驗01:構建FTP服務器vim
.實驗目標服務器
根據公司的業務發展要求,須要面向Internet 搭建一臺FTP文件服務器,以提供公測軟 網絡
件、市場資料的下載,以及員工的一些資源上傳分享併發
1. 測試默認安裝vsftpd的結果dom
匿名用戶與本地用戶是否能夠登陸tcp
匿名用戶與本地用戶登陸的家目錄在哪裏ide
匿名用戶與本地用戶登陸後的權限測試
匿名用戶登陸對共享根目錄禁止有寫入權限,不然禁止匿名帳戶登陸!ui
2.禁止匿名用戶登陸spa
修改FTP默認端口爲2121
禁錮本地用戶在本身家目錄
3.驗證黑/白名單
4.本地用戶登陸到/data/ftproot目錄
up上傳/下載,down僅下載。拒絕全部用戶登陸包括匿名用戶
最多20個併發,每IP地址最多2個併發
限制下載速度限制爲100KB/s
. 實驗步驟
1、測試默認安裝vsftpd的結果
實驗要求:測試默認安裝vsftpd的結果
匿名用戶與本地用戶是否能夠登陸
匿名用戶與本地用戶登陸的家目錄在哪裏
匿名用戶與本地用戶登陸後的權限
(一)服務端設置
一)IP設置
1. 設置ip地址
[root@dhcpser ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:0c:29:48:71:56 (MAK地址)
IPADDR=192.168.10.253 (ip地址)
NETMASK=255.255.255.0 (子網掩碼)
~
2. 設置網關及主機名
[root@dhcpser ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=dhcpser.tarena.com (主機名)
GATEWAY=192.168.10.254 (網關地址)
3. 配置搜索域
[root@dhcpser ~]# vim /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.10.253 dhcpser.tarena.com dhcpser (搜索域)
4. 重啓服務
[root@dhcpser ~]# service network restart
[root@dhcpser ~]# chkconfig network on
5. 驗證
[root@dhcpser ~]# ifconfig eth0(驗證ip地址)
[root@dhcpser ~]# route -n(驗證網絡)
[root@dhcpser ~]# hostname (驗證主機名)
[root@dhcpser ~]# ping dhcpser.tarena.com(驗證搜索域)
二)安裝軟件包
1 檢測是否安裝dhcp
[root@dhcpser ~]# rpm -q dhcp
放入RHEL5.9 iso鏡像
2. 查看安裝軟件
[root@dhcpser ~]# cd /misc/cd/Server
[root@dhcpser Server]# ls *vsftpd*
vsftpd-2.0.5-28.el5.x86_64.rpm
3. 安裝vsftpd
[root@localhost Server]# rpm -ivh vsftpd-2.0.5-28.el5.x86_64.rpm
warning: vsftpd-2.0.5-28.el5.x86_64.rpm: Header V3 DSA signature:
NOKEY, key ID 37017186
Preparing...
########################################### [100%]
1:vsftpd
########################################### [100%]
4. 檢測安裝結果
[root@dhcpser Server]# rpm -q vsftpd
vsftpd-2.0.5-28.el5
5. 啓動vsftpd服務
[root@dhcpser Server]# service vsftpd restart
[root@dhcpser Server]# chkconfig vsftpd on //開機自啓
6. 文件輸出
[root@localhost ~]# ls -lh /etc > /var/ftp/pub/etc.txt
7.新建用戶
[root@localhost ~]# useradd kaka
[root@localhost ~]# echo "redhat" | passwd --stdin kaka
Changing password for user kaka.
passwd: all authentication tokens updated successfully.
(二)客戶端測試
1. 匿名訪問的用戶ftp
[root@localhost ~]# ftp 192.168.10.253//使用ftp命令訪問FTP服務器
Connected to 192.168.10.253.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.253:root): ftp //匿名FTP用戶
331 Please specify the password.
Password: //密碼任意
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,10,253,234,9)
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 11571 Sep 13 20:02 etc.txt
226 Directory send OK.
ftp> get etc.txt //下載
local: etc.txt remote: etc.txt
227 Entering Passive Mode (192,168,10,253,213,17)
150 Opening BINARY mode data connection for etc.txt (11571 bytes).
226 File send OK.
11571 bytes received in 8.9e-05 seconds (1.3e+05 Kbytes/s)
ftp> !ls
anaconda-ks.cfg etc.txt install.log.syslog
Desktop install.log
ftp> put install.log //上傳
local: install.log remote: install.log
227 Entering Passive Mode (192,168,10,253,142,214)
550 Permission denied. //失敗
ftp> quit
221 Goodbye.
2. 本地用戶訪問
[root@localhost ~]# lftp 192.168.10.253
lftp 192.168.10.253:~> user kaka
口令:
lftp kaka@192.168.10.253:~> put install.log //上傳
33139 bytes transferred //成功
lftp kaka@192.168.10.253:~> ls
-rw-r--r-- 1 500 500 33139 Sep 13 20:26 install.log
tp kaka@192.168.10.253:~> get etc.txt //下載
get: etc.txt: file already exists and xfer:clobber is unset
//成功
tp kaka@192.168.10.253:~>!ls
anaconda-ks.cfg etc.txt install.log.syslog
Desktop install.log
. 結果
匿名用戶與本地用戶均可以登陸
匿名用戶登陸到/var/ftp,只能下載不能上傳
本地用戶登陸到本地用戶的家目錄,能夠上傳和下載
. 問題和經驗總結
故障現象:用戶登陸失敗
[root@localhost ~]# ftp 192.168.10.253
ftp: connect: No route to host
ftp>
解決辦法:關閉防火牆
[root@localhost ~]# service iptables stop
解決辦法:查看服務器IP地址及端口號
[root@localhost~]#vim /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# ifconfig
二.禁止匿名用戶登陸修改FTP默認端口及禁錮本地用戶在本身家目錄
實驗要求:禁止匿名用戶登陸
修改FTP默認端口爲2121
禁錮本地用戶在本身家目錄
(一)在服務端配置
1. 修改/etc/vsftpd/文件
[root@dhcpser ~]# cd /etc/vsftpd/
[root@dhcpser vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
[root@dhcpser vsftpd]#cp vsftpd.conf vsftpd.conf.bak//備份配置文件
[root@dhcpser vsftpd]# vim vsftpd.conf
...
12 anonymous_enable=NO //關閉匿名FTP訪問
...
119 listen_port=2121
120 chroot_local_user=YES //禁錮本地用戶 --> 宿主目錄
注:
anonymous_enable=YES//(默認)容許匿名登陸
anon_upload_enable=YES//容許匿名上傳文件
anon_mkdir_write_enable=YES//容許匿名建立目錄
anon_other_write_enable=YES//容許其餘寫入權限
write_enable=YES//(默認)容許寫入(全局)
anon_umask=022//設置上傳文件權限掩碼
[root@dhcpser vsftpd]# service vsftpd restart
關閉 vsftpd: [肯定]
爲 vsftpd 啓動 vsftpd: [肯定]
2. 重啓vsftpd服務
[root@dhcpser vsftpd]# service vsftpd restart
關閉 vsftpd: [肯定]
爲 vsftpd 啓動 vsftpd: [肯定]
3. 查看端口
[root@dhcpser vsftpd]# netstat -tulnp | grep vsftpd
tcp 0 0 0.0.0.0:2121 0.0.0.0:* LISTEN 4879/vsftpd
(二)客戶端測試
[root@localhost ~]# ftp 192.168.10.253 2121
Connected to 192.168.10.253.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.253:root): ftp //匿名用戶
331 Please specify the password.
Password:
530 Login incorrect.
Login failed. //登陸失敗
ftp> quit
221 Goodbye.
[root@localhost ~]# ftp 192.168.10.253 2121
Connected to 192.168.10.253.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.253:root): kaka //本地用戶
331 Please specify the password.
Password:
230 Login successful. //成功
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/" //登入位置已變爲「/」,
//實際是kaka的宿主目錄
ftp> ls
227 Entering Passive Mode (192,168,10,253,113,26)
150 Here comes the directory listing.
-rw-r--r-- 1 500 500 33139 Sep 13 20:26 install.log
226 Directory send OK.
三.黑/白名單
實驗要求:驗證黑/白名單
(一)服務端
1. 新建用戶
[root@dhcpser ~]# useradd jerry
[root@dhcpser ~]# useradd mike
[root@dhcpser ~]# echo "redhat" | passwd --stdin jerry
Changing password for user jerry.
passwd: all authentication tokens updated successfully.
[root@dhcpser ~]# echo "redhat" | passwd --stdin mike
Changing password for user mike.
passwd: all authentication tokens updated successfully.
2. 黑名單文件:/etc/vsftpd/ftpusers
[root@dhcpser ~]# vim /etc/vsftpd/ftpusers
kaka
3. 查看
[root@dhcpser ~]# grep kaka /etc/vsftpd/ftpusers
kaka
(二)客戶端
1. 驗證kaka可否登陸FTP
[root@localhost ~]# ftp 192.168.10.253 2121
Connected to 192.168.10.253.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.253:root): kaka
530 Permission denied.
Login failed.
ftp> quit
221 Goodbye.
結論:不能登陸
(一)服務端
4. 黑/白名單:/etc/vsftpd/user_list
[root@dhcpser ~]# vim /etc/vsftpd/user_list
jerry
5. 查看
[root@dhcpser ~]# grep jerry /etc/vsftpd/user_list
jerry
(二)客戶端
2. 驗證jerry可否登陸FTP
[root@localhost ~]# ftp 192.168.10.253 2121
Connected to 192.168.10.253.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.253:root): jerry
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp> quit
221 Goodbye.
結論:不能登陸
6. 修改/etc/vsftpd/vsftpd.conf文件
[root@dhcpser ~]# vim /etc/vsftpd/vsftpd.conf
...
121 userlist_deny=NO
7. 啓動vsftpd服務
oot@dhcpser ~]# service vsftpd restart
關閉 vsftpd: [肯定]
爲 vsftpd 啓動 vsftpd: [肯定]
(二)客戶端
3. 驗證jerry可否登陸FTP
[root@localhost ~]# ftp 192.168.10.253 2121
Connected to 192.168.10.253.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.253:root): jerry
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> quit
221 Goodbye.
結論:登陸成功
4. 驗證mike可否登陸FTP
[root@localhost ~]# ftp 192.168.10.253 2121
Connected to 192.168.10.253.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (192.168.10.253:root): kike
530 Permission denied.
Login failed.
ftp> quit
221 Goodbye
驗證結論:登陸失敗
注:實驗完畢,請將主配置文件121 userlist_deny=NO註釋,將user_list和ftpusers裏
面添加的帳戶去掉
. 問題和經驗總結
黑名單文件:/etc/vsftpd/ftpusers
黑/白名單:/etc/vsftpd/user_list
1)將user_list做爲黑名單(缺省)
userlist_enable=YES//(默認)啓用user_list列表文件
userlist_deny=YES//(默認)
2)改將user_list做爲白名單
userlist_enable=YES//(默認)啓用user_list列表文件
userlist_deny=NO//將user_list做爲白名單
四.鏈接限制、下載速度限制
實驗要求:本地用戶登陸到/data/ftproot目錄
up上傳/下載,down僅下載。拒絕全部用戶登陸包括匿名用戶
最多20個併發,每IP地址最多2個併發
限制下載速度限制爲100KB/s
(一).客戶端
1. 新建用戶
[root@dhcpser ~]# useradd down
[root@dhcpser ~]# echo "redhat" | passwd --stdin up
Changing password for user up.
passwd: all authentication tokens updated successfully.
[root@dhcpser ~]# echo "redhat" | passwd --stdin down
Changing password for user down.
passwd: all authentication tokens updated successfully.
2. 修改/etc/vsftpd/vsftpd.conf文件
...
12 anonymous_enable=NO
...
18 write_enable=YES
...
117 userlist_enable=YES
...
121 userlist_deny=NO //將user_list做爲白名單
122 local_root=/data/ftproot
123 max_clients=20 //容許的最大併發鏈接數
124 max_per_ip=2 //每一個IP地址最多容許多少鏈接
125 local_max_rate=100000 //本地用戶下載速度,Byte/s
3.啓動vsftpd服務
[root@dhcpser ~]# service vsftpd restart
關閉 vsftpd: [肯定]
爲 vsftpd 啓動 vsftpd: [肯定]
4. 設置權限
[root@dhcpser ~]# setfacl -m u:up:rwx /data/ftproot/
5. Up,down加入黑/白名單:/etc/vsftpd/user_list
[root@dhcpser ~]# vim /etc/vsftpd/user_list
up
Down
[root@dhcpser ~]# tail -n 2 /etc/vsftpd/user_list
up
down
5.建下載測試文件
[root@dhcpser ~]# dd if=/dev/zero of=/data/ftproot/local.tgz
bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 7.60703 seconds, 138 MB/s
. 結果驗證
[root@dhcpser~]#wget
ftp://up:redhat@192.168.10.253:2121/local.tgz
--2014-09-1423:54:47--
ftp://up:*password*@192.168.10.253:2121/local.tgz
=> `local.tgz'
Connecting to 192.168.10.253:2121... 已鏈接。
正在以 up 登陸 ... 登陸成功!
==> SYST ... 完成。 ==> PWD ... 完成。
==> TYPE I ... 完成。 ==> 不須要 CWD。
==> SIZE local.tgz ... 1048576000
==> PASV ... 完成。 ==> RETR local.tgz ... 完成。
長度:1048576000 (1000M)
0% [ ] 6,963,200 97.7K/seta 2h 53m
. 問題和經驗總結
建下載測試文件
dd if=/dev/zero of=/var/ftp/anon.tgz bs=1M count=100
dd if=/dev/zero of=/home/用戶名/local.tgz bs=1M count=100