当我尝试连接到我的 VPS 时,它有时拒绝连接,有时不改变配置则无法连接。
$ ssh vps -vvvv
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/**/.ssh/config
debug1: /Users/**/.ssh/config line 4: Applying options for *
debug1: /Users/**/.ssh/config line 8: Applying options for vps
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 102: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to **.**.**.** [**.**.**.**] port **.
debug1: connect to address **.**.**.** port **: Connection refused
ssh: connect to host **.**.**.** port **: Connection refused
然而,虽然它没有响应,但sshd
它本身似乎正在运行。
$ service --status-all | grep ssh
[ + ] ssh
$ ps auxf | grep ssh
root 8368 0.0 0.0 49272 660 ? Ss 2014 0:00 /usr/sbin/sshd -D
$ uptime
22:33:26 up 66 days, 6:34, 6 users, load average: 0.18, 0.24, 0.13
(注意:这些命令不通过 ssh 执行)
此外,Apache 等其他服务也正常运行,并且可以通过 HTTP 访问。您知道发生了什么吗?
$ sudo iptables -L -n -v
Chain INPUT (policy ACCEPT 5156 packets, 4606K bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 1 packets, 231 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 3494 packets, 693K bytes)
pkts bytes target prot opt in out source destination
$ sudo lsof -i:3843
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 8368 root 3u IPv4 384433104 0t0 TCP *:3843 (LISTEN)
sshd 8368 root 4u IPv6 384433106 0t0 TCP *:3843 (LISTEN)
$ free -m
total used free shared buffers cached
Mem: 1024 368 655 0 0 107
-/+ buffers/cache: 261 762
Swap: 1024 92 931
$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.10
DISTRIB_CODENAME=maverick
DISTRIB_DESCRIPTION="Ubuntu 10.10"
$ tail -500 /var/log/auth.log | grep -i ssh
Jan 10 21:27:30 ******** sshd[8368]: Received signal 15; terminating.
Jan 10 21:28:41 ******** sshd[229]: Received signal 15; terminating.
Jan 10 21:28:41 ******** sshd[304]: Server listening on 0.0.0.0 port 3843.
Jan 10 21:28:41 ******** sshd[304]: Server listening on :: port 3843.
Jan 10 21:28:43 ******** sshd[304]: Received signal 15; terminating.
Jan 10 21:28:43 ******** sshd[391]: Server listening on 0.0.0.0 port 3843.
Jan 10 21:28:43 ******** sshd[391]: Server listening on :: port 3843.
$ sudo ufw allow 3843/tcp
Traceback (most recent call last):
File "/usr/sbin/ufw", line 89, in <module>
ui = ufw.frontend.UFWFrontend(pr.dryrun)
File "/usr/lib/python2.6/dist-packages/ufw/frontend.py", line 158, in __init__
self.backend = UFWBackendIptables(dryrun)
File "/usr/lib/python2.6/dist-packages/ufw/backend_iptables.py", line 45, in __init__
ufw.backend.UFWBackend.__init__(self, "iptables", d, files)
File "/usr/lib/python2.6/dist-packages/ufw/backend.py", line 66, in __init__
self.iptables_version = ufw.util.get_iptables_version(self.iptables)
File "/usr/lib/python2.6/dist-packages/ufw/util.py", line 644, in get_iptables_version
(rc, out) = cmd([exe, '-V'])
File "/usr/lib/python2.6/dist-packages/ufw/util.py", line 273, in cmd
out = sp.communicate()[0]
File "/usr/lib/python2.6/subprocess.py", line 688, in communicate
self.wait()
File "/usr/lib/python2.6/subprocess.py", line 1182, in wait
pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
File "/usr/lib/python2.6/subprocess.py", line 455, in _eintr_retry_call
return func(*args)
OSError: [Errno 10] No child processes
答案1
可能与上游服务提供商有关?
执行 NMAP 查看端口是否打开或被过滤,这应该会告诉您端口是否被防火墙保护。
您还可以进行嗅探来查看流量的行为方式。
答案2
“有时”这个方面让我想到了路由问题。我会tcpdump
在服务器和客户端接口上采取一些措施,同时还要观察ip route
沿途的情况。