出站 SSH 连接被拒绝

出站 SSH 连接被拒绝

我正在将 Ansible 集成到一个项目中,以便与 Cisco 路由器/交换机交互。我的问题似乎与 Ansible 或我的配置本身无关,但是,我发现如果我手动尝试与设备建立 SSH 连接,它也会被拒绝。

场景如下:

  • 主机:Red Hat Linux Box
  • 目标:主机名为 0042router 的 Cisco 路由器(已使用 IP 测试)

我的Ansible 命令如下:

ansible all -m raw -a "executable='' sh cdp neigh" -i hosts

我的主办方列表:

[routers]
router_one ansible_host = 0042router

运行此程序时,我遇到了以下问题输出

router_one | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: ssh: connect to host 0042router port 22: Connection refused\r\n", 
    "unreachable": true
}

我可以用同样的方式尝试 pingAnsible

ansible all -m ping -i hosts

输出相同的消息,但奇怪的是我可以从我的服务器 ping 通路由器

PING 0042router.company.com (10.x.xx.xxx) 56(84) bytes of data.
64 bytes from 0042router.company.com (10.x.xx.xxx): icmp_seq=1 ttl=247 time=8.28 ms
64 bytes from 0042router.company.com (10.x.xx.xxx): icmp_seq=2 ttl=247 time=8.12 ms
64 bytes from 0042router.company.com (10.x.xx.xxx): icmp_seq=3 ttl=247 time=8.03 ms

然而我无法通过 SSH 连接到路由器从我的服务器的 shell:

ssh: connect to host 0042router port 22: Connection refused

我发现Ansible但是,不使用基于 ICMP 的 ping,所以这可以解释为什么我无法从 Ansible 完成 ping 但可以从服务器完成,但我不确定是什么阻止了出站 SSH 连接。

我应该寻找什么?我可以从 SecureCRT 通过端口 22 上的 SSH2 访问 0042router,没有任何问题。


问题后发现

  • /etc/hosts.deny没有否认任何事情。

相关内容