
/etc/ssh/sshd_config の既存の行「Port 22」のすぐ下に行「Port 110」を追加し、/etc/init.d/sshd restart
sshd が両方のポート (22 と 110) をリッスンしているのを確認しようとしました。しかし、netstat -anp は、sshd がデフォルト ポート (22) のみをリッスンしていることを示しました。
後で試してみたところbash -x /etc/init.d/sshd restart
、sshd がすぐにポート 110 にバインドされるのを見て驚きました。もう一度実行すると、/etc/init.d/sshd restart
変更が無視されました。再起動しても変更が無視されるため、行き詰まって完全に困惑しています。
アップデートこの奇妙な行動は低いポート(<1024)のみ
これは CentOS 6 サーバー上にあります。
詳細
以下は /etc/ssh/sshd_config への変更です:
grep ^Port /etc/ssh/sshd_config
Port 22
Port 110
netstatの出力bash -x /etc/init.d/sshd restart
netstat -anp | grep -i listen|grep sshd|grep -v :::
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 7031/sshd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7031/sshd
netstatの出力/etc/init.d/sshd restart
netstat -anp | grep -i listen|grep sshd|grep -v :::
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 8962/sshd
sshd をポート 110 にバインドさせる別の方法は、次のようにデバッグ モードで実行することです/usr/sbin/sshd -de
(listening on port 22,110
行に注意してください。また、両方のポートに接続してテストも行いました)。
/usr/sbin/sshd -de
debug1: sshd version OpenSSH_5.3p1
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: read PEM private key done: type DSA
debug1: private host key: #1 type 2 DSA
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-de'
Set /proc/self/oom_score_adj from 0 to -1000
debug1: Bind to port 22 on 0.0.0.0.
Server listening on 0.0.0.0 port 22.
debug1: Bind to port 22 on ::.
Server listening on :: port 22.
debug1: Bind to port 110 on 0.0.0.0.
Server listening on 0.0.0.0 port 110.
debug1: Bind to port 110 on ::.
Server listening on :: port 110.
答え1
SELinuxシステムは1024未満のポートのポートバインディングを制限しています
semanage port -l | grep ssh
ssh_port_t tcp 22
別のポートを追加できます
semanage port -a -t ssh_port_t -p tcp 110
そうすればすぐに問題が解決するでしょう。