xinetd 取代了 inetd + tcp_wrappers,提供存取控制、強化日誌與資源管理功能,已成為 Internet 標準超級守護行程。本文希望寫一份 Solaris 上的傻瓜式安裝設定手冊。
伺服器為 Sun-Fire-280R,作業系統 SunOS 5.8 Generic_117350-02。xinetd 版本 2.3.10,可自 ftp.sunfreeware.com 下載,該套件已加入 --with-libwrap、--with-loadavg、--with-inet6 編譯選項。Solaris 預設使用 xinetd 的服務可分為:標準網際網路服務(telnet、ftp)、資訊服務(finger、netstat、systat)、郵件服務(imap、pop3 等)、RPC 服務、BSD 服務、內部服務、安全服務(irc)與其他(tftp、uucp)等。更多資訊見 https://www.xinetd.org/。
安裝:gzip -d 解壓後 pkgadd -d 安裝,無報錯即完成。安裝後文件位於 /usr/local/doc/xinetd,命令位於 /usr/local/sbin(xinetd、xconv.pl、itox)。
設定主要涉及兩個檔案:需修改的 /etc/init.d/inetsvc 與需產生的 /etc/xinetd.conf。
1)產生 /etc/xinetd.conf:此檔由 /etc/inetd.conf 轉換而來,命令為 /usr/local/sbin/xconv.pl < /etc/inetd.conf > /etc/xinetd.conf。事先可在 inetd.conf 移除不需要的埠(如 finger、login),轉換後的 xinetd.conf 會更簡潔(本例只保留 telnet 與 ftp)。
2)修改 /etc/init.d/inetsvc:其一,把 pkill 比對的 'in.namedinetd' 改為 'in.namedxinetd';其二,把 /usr/sbin/inetd -s & 改為 /usr/local/sbin/xinetd -s &。
3)測試:先 /etc/init.d/inetsvc stop 停止原服務,再 start 啟動新服務,以 ps -ef | grep xinetd 確認 xinetd 正常運行。若啟動有問題,通常是 xinetd.conf 設定的原因。
於 /etc/xinetd.conf 加入 service ssh 區塊,設定 socket_type=stream、user=root、server=/usr/local/sbin/sshd、port=22、server_args=-i,並以 only_from 指定允許的 IP(如 192.0.0.109)。重啟機器確認 xinetd 載入正常後,只有該 IP 能 SSH 登入,其餘 IP 皆被拒。注意:SSH 安裝後不需再在 /etc/rc2.d 加入 S99sshd,因為 xinetd 已能啟動 ssh,否則將無法達到限制 IP 的效果。
設定完成後以 nmap 掃描,僅 22/tcp 開放 ssh,且登入來源被限制為內網的 192.0.0.109,安全目標達成。