問題描述
部署完vsftpd后使用虛擬用戶登入成功后查看目錄提示425 Security: Bad IP connecting.
,報錯內容如下:
[root@host-172-17-2-118 ~]# ftp 172.17.2.118
Connected to 172.17.2.118 (172.17.2.118).
220 (vsFTPd 3.0.2)
Name (172.17.2.118:root): admin
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (192,168,1,22,39,115).
425 Security: Bad IP connecting.
排查思路
既然能登入ftp,說明網絡連接和用戶應該沒有問題
- 查看vsftpd.conf 配置中的目錄是否存在,用戶屬主是否正確。
- 使用
ftp 127.0.0.1
登入嘗試是否能獲取目錄信息。
定位問題
嘗試使用ftp 127.0.0.1
登入ftp后使用dir發現是能獲取到目錄和文件信息的,所以判斷還是網絡層面出了問題,檢查端口和防火牆后發現問題原因可能沒那么簡單;通過查詢各類資料,在一篇阿里雲的文章中找到了答案:https://developer.aliyun.com/article/601945 。
大概的意思是因為我們的服務器是運行在OpenStack上,訪問服務器的IP都經過了NAT(類似於阿里雲的專有網絡),在被動模式下客戶端獲取到的是實例的私網IP,導致無法進行通信(具體原因可查看上述文章)。
解決步驟
編輯vsftpd.conf關閉IPv6,並指定服務器外網訪問地址(我這里是OpenStack,所以指定實例的彈性IP)
listen=YES
listen_ipv6=NO
pasv_address=172.17.2.118
- 其中
pasv_address
需要指定彈性公網IP。
驗證
[root@host-172-17-2-118 vsftpd]# ftp 172.17.2.118
Connected to 172.17.2.118 (172.17.2.118).
220 (vsFTPd 3.0.2)
Name (172.17.2.118:root): admin
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (172,17,2,118,39,98).
150 Here comes the directory listing.
drwxrwxrwx 2 1004 0 8192 Apr 02 2021 089
226 Directory send OK.