Закрываем ESXi от мира. ESXi Firewall

Если идти православным путем, вы не должны выпускать ESXi в мир, то есть доступ до самих хостов архитектурно должны быть в приватных сетях, как менеджмент, так и все остальное. Но иногда, нужно, что бы они были доступны и из мира. Что тогда? Тогда все "мамкины" хакеры и просто обыватели раз за разом, либо будут вас пытаться поломать, либо просто сканировать. Не говоря уже про то, что ребята из VMWare периодически пропускают критические уязвимости в связи с чем начинают выпускать все новые и новые патчи! Что делать? Закрывать все! Естественно!

Внимание: Внимательно отнеситесь к материалу статьи, действия с firewall могут привести к потере контроля над ESXi хостом и будет требовать прямого доступа к серверу.

Для начала вам необходимо включить SSH доступ, сделать это можно попав в веб интерфейс вашего хоста, далее зайти в сервисы и включить SSH. При этом система обязательно выведет вам предупреждение о том, что ssh теперь доступен! И нужно не забыть выключить его после всех манипуляций. Хорошо! И так, будем считать вы успешно зашли на хост, для начала необходимо понять включен ли на хосте firewall, и если нет, включить его. По-умолчанию правила фаервола разрешают все и всем.

esxcli network firewall get
esxcli network firewall ruleset allowedip list

Если изначально все было доступно всем, эти правила сохранятся, даже если мы включим firewall, потому как в разрешенных адресах указано All. Включаем firewall и ставим политику по умолчанию DROP.

esxcli network firewall load
esxcli network firewall set --default-action DROP
esxcli network firewall set --enabled true

Первое, что стоит закрыть это доступ по http/https протоколам, для этого пропишем следующие правила (если вам необходимо доступ с нескольких адресов, вы должны повторить для всех необходимых адресов правила в котором он добавляется).

esxcli network firewall ruleset set --ruleset-id=vSphereClient --allowed-all=False
esxcli network firewall ruleset allowedip add --ip-address=YOUR_IP_ADDR/32 --ruleset-id=vSphereClient
esxcli network firewall ruleset set --ruleset-id=vSphereClient --enabled=True

Но у нас остается ещё целая куча сервисов, что делать с этим? Получить их все, выбрать только названия написать небольшой цикл на bash и ограничить по шаблону правил выше. За исключением некоторых сервисов которые необходимы для работы системы и не представляют угрозы для нас.

esxcli network firewall ruleset list | awk '{print $1}' | grep -vE "(Name|-|ssh|dns|ntp)"

А так же, я взял табличку сервисов с сайта VMWare:

Product Port Protocol Source Target Purpose
ESXi 5.x 22 TCP Client PC ESXi Host SSH Server
ESXi 5.x 53 UDP ESXi 5.x DNS Server DNS Client
ESXi 5.x 68 UDP ESXi 5.x DHCP Server DHCP Client
ESXi 5.x 80 TCP Client PC ESXi Host Redirect Web Browser to HTTPS Service (443)
ESXi 5.x 88 TCP ESXi host Active Directory Server PAM Active Directory Authentication - Kerberos
ESXi 5.x 111 TCP ESXi/ESX Host NFS Server NFS Client – RPC Portmapper
ESXi 5.x 111 UDP ESXi/ESX Host NFS Server NFS Client – RPC Portmapper
ESXi 5.x 123 UDP ESXi/ESX Host NTP Time Server NTP Client
ESXi 5.x 161 UDP SNMP Server ESXi Host SNMP Polling. Not used in ESXi 3.x
ESXi 5.x 162 UDP ESXi Host SNMP Collector SNMP Trap Send
ESXi 5.x 389 TCP/UDP ESXi host LDAP Server PAM Active Directory Authentication - Kerberos
ESXi 5.x 427 UDP VI / vSphere Client ESXi/ESX Host CIM Service Location Protocol (SLP)
ESXi 5.x 443 TCP VI / vSphere Client ESXi/ESX Host VI / vSphere Client to ESXi/ESX Host management connection
ESXi 5.x 443 TCP ESXi/ESX Host ESXi/ESX Host Host to host VM migration and provisioning
ESXi 5.x 445 UDP ESXi host MS Directory Services Server PAM Active Directory Authentication
ESXi 5.x 445 TCP ESXi host MS Directory Services Server PAM Active Directory Authentication
ESXi 5.x 445 TCP ESXi host SMB Server SMB Server
ESXi 5.x 464 TCP ESXi host Active Directory Server PAM Active Directory Authentication - Kerberos
ESXi 5.x 514 UDP/TCP ESXi 5.x Syslog Server Remote syslog logging
ESXi 5.x 902 TCP/UDP ESXi 5.x ESXi Host Host access to other hosts for migration and provisioning
ESXi 5.x 902 TCP vSphere Client ESXi Host vSphere Client access to virtual machine consoles (MKS)
ESXi 5.x 902 UDP ESXi 5.x vCenter Server (UDP) Status update. Managed hosts send a regular heartbeat to the vCenter Server system. This port must not be blocked by firewalls between the server and the hosts or between hosts.
ESXi 5.x 1024 (dynamic) TCP/UDP ESXi Host Active Directory Server Bi-directional communication on TCP/UDP ports is required between the ESXi host and the Active Directory Domain Controller (via the netlogond process on the ESXi host). See Active Directory and Active Directory Domain Services Port Requirementsand the Microsoft Knowledge Base article179442.
ESXi 5.x 2049 TCP ESXi 5.x NFS Server Transactions from NFS storage devices
ESXi 5.x 2049 UDP ESXi 5.x NFS Server Transactions from NFS storage devices
ESXi 5.x 3260 TCP ESXi 5.x iSCSI storage server Transactions to iSCSI storage devices
ESXi 5.x 5900 to 5964 TCP ESXi 5.x ESXi Host RFB protocol, which is used by management tools such as VNC
ESXi 5.x 5988 TCP CIM Server ESXi Host CIM transactions over HTTP
ESXi 5.x 443 TCP ESXi vCenter Server Deploy VIBs for NSX
ESXi 5.x 5989 TCP vCenter Server ESXi Host CIM XML transactions over HTTPS
ESXi 5.x 5989 TCP ESXi 5.x vCenter Server CIM XML transactions over HTTPS
ESXi 5.x 8000 TCP ESXi 5.x (VM Target) ESXi (VM Source) Requests from vMotion
ESXi 5.x 8000 TCP ESXi 5.x (VM Source) ESXi (VM Target) Requests from vMotion
ESXi 5.x 808,100 TCP/UDP ESXi 5.x ESXi Host Traffic between hosts for vSphere Fault Tolerance (FT)
ESXi 5.x 8182 TCP/UDP ESXi 5.x ESXi Host Traffic between hosts for vSphere High Availability (vSphere HA)
ESXi 5.x 8200 TCP/UDP ESXi 5.x ESXi Host Traffic between hosts for vSphere Fault Tolerance (FT)
ESXi 5.x 8301 UDP ESXi 5.x ESXi Host DVS Port Information
ESXi 5.x 8302 UDP ESXi 5.x ESXi Host DVS Port Information
ESXi 5.x 31000 TCP SPS Server vCenter Server Internal Communication Port
ESXi 6.x 9 UDP vCenter Server Virtual Volumes Used by the Virtual Volumes feature
ESXi 6.x 22 TCP SSH Client ESXi Host Required for SSH access
ESXi 6.x 53 UDP ESXi Host DNS Server DNS client
ESXi 6.x 68 UDP DHCP Server ESXi Host DHCP client for IPv4
ESXi 6.x 80 TCP Web Browser ESXi Host Welcome page, with download links for different interfaces
ESXi 6.x 161 UDP SNMP Server ESXi Host Allows the host to connect to an SNMP server
ESXi 6.x 427 TCP/UDP CIM Server ESXi Host The CIM client uses the Service Location Protocol, version 2 (SLPv2) to find CIM servers
ESXi 6.x 443 TCP vSphere Web Client ESXi Host Client connections
ESXi 6.x 546 TCP/UDP DHCP Server ESXi Host DHCP client for IPv6
ESXi 6.x 547 TCP/UDP ESXi Host DHCP Server DHCP client for IPv6
ESXi 6.x 902 TCP/UDP VMware vCenter Agent ESXi Host vCenter Server agent
ESXi 6.x 2233 TCP ESXi Host vSAN Transport Used for RDT traffic (Unicast peer to peer communication) between vSAN nodes.
ESXi 6.x 3260 TCP ESXi Host Software iSCSI Client Supports software iSCSI
ESXi 6.x 5671 TCP ESXi Host rabbitmqproxy A proxy running on the ESXi host that allows applications running inside virtual machines to communicate to the AMQP brokers running in the vCenter network domain. The virtual machine does not have to be on the network, that is, no NIC is required. The proxy connects to the brokers in the vCenter network domain. Therefore, the outgoing connection IP addresses should at least include the current brokers in use or future brokers. Brokers can be added if customer would like to scale up.
ESXi 6.x ######## TCP CIM Server ESXi Host Server for CIM (Common Information Model)
ESXi 6.x 5989 TCP CIM Secure Server ESXi Host Secure server for CIM
ESXi 6.x 6999 UDP NSX Distributed Logical Router Service ESXi Host NSX Virtual Distributed Router service. The firewall port associated with this service is opened when NSX VIBs are installed and the VDR module is created. If no VDR instances are associated with the host, the port does not have to be open.This service was called NSX Distributed Logical Router in earlier versions of the product.
ESXi 6.x 8000 TCP ESXi Host ESXi Host vMotion
ESXi 6.x 8080 TCP vSANvp ESXi Host vSAN VASA Vendor Provider. Used by the Storage Management Service (SMS) that is part of vCenter to access information about vSAN storage profiles, capabilities, and compliance. If disabled, vSAN Storage Profile Based Management (SPBM) does not work.
ESXi 6.x ######## TCP\UDP Fault Tolerance ESXi Host Traffic between hosts for vSphere Fault Tolerance (FT).
ESXi 6.x ######## UDP DVSSync ESXi Host DVSSync ports are used for synchronizing states of distributed virtual ports between hosts that have VMware FT record/replay enabled. Only hosts that run primary or backup virtual machines must have these ports open. On hosts that are not using VMware FT these ports do not have to be open.
ESXi 6.x 12345, 23451 UDP ESXi Host vSAN Clustering Service Cluster Monitoring, Membership, and Directory Service used by vSAN.
ESXi 6.x 443 TCP ESXi Host vCenter Server Deploy VIBs for NSX
ESXi 6.x 44046, 31031 TCP ESXi Host HBR Used for ongoing replication traffic by vSphere Replication and VMware Site Recovery Manager.
ESXi Dump Collector 6500 UDP ESXi vCenter Server Network coredump server
ESXi Dump Collector 8000 TCP ESXi vCenter Server Network coredump web port
ESXi Syslog Collector 8001 TCP ESXi vCenter Server Network syslog server


Home »