在 ESXi 5.0 主机上更改 SSH 所用端口
search cancel

在 ESXi 5.0 主机上更改 SSH 所用端口

book

Article ID: 305138

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

免责声明:本文为 Changing the port used by SSH on an ESXi 5.0 host (2011818) 的翻译版本。尽管我们会不断努力为本文提供最佳翻译版本,但本地化的内容可能会过时。有关最新内容,请参见英文版本。


某些环境对特定服务所用端口有要求。本文提供了允许 ESXi 5.0 将不同端口用于 SSH 的步骤。

Environment

VMware vSphere ESXi 5.0

Resolution

进行修改后,这些修改通常在重新引导后不会持久保留。您需要占位符以在引导时复制这些文件。例如,可以使用 VMFS 卷。

要修改用于 SSH 的端口,请执行以下操作:

  1. 打开所需防火墙端口。有关详细信息,请参见 User defined xml firewall configurations are not persistent across ESXi host reboots (2007381)

    以下示例显示了已打开 TCP 端口 2222 的规则集 .xml 文件:

    <ConfigRoot>
    <service>
    <id>SSH 2222</id>
    <rule id = '0000'>
    <direction>inbound</direction>
    <protocol>tcp</protocol>
    <porttype>dst</porttype>
    <port>2222</port>
    </rule>
    <enabled>true</enabled>
    <required>false</required>
    </service>
    </ConfigRoot>

  2. /etc/services 复制到永久存储(可以与防火墙规则存储的位置相同,如 /vmfs/volumes/datastore1/hostname_etc/)。
  3. 在永久存储上编辑服务的副本,并更改 SSH 的端口。

    ssh 2222/tcp # SSH Remote Login Protocol
    ssh 2222/udp # SSH Remote Login Protocol

  4. 编辑 /etc/rc.local 以便在引导时将创建的文件复制回主机。将以下行添加到文件的末尾,例如:

    #Copy the new firewall rule from vmfs place holder to file system
    cp /vmfs/volumes/datastore1/etc/ssh_2222.xml /etc/vmware/firewall/
    #refresh firewall rules
    esxcli network firewall refresh
    #Copy the modified services file from vmfs place holder to file system
    cp /vmfs/volumes/datastore1/etc/services /etc/services
    #Restart inetd to get the changes
    kill -HUP `cat /var/run/inetd.pid`

  5. 重新引导主机,然后尝试连接到所选端口上的主机以验证更改是否已成功。


Additional Information

Changing the port used by SSH on an ESXi 5.0 host