Featured image of post 在 ESXi 建立自訂 Firewall Rule

在 ESXi 建立自訂 Firewall Rule

ESXi 的 firewall 預設只開放少數必要的出入站流量。如果需要讓 ESXi 主機本身連到特定 port(例如把系統 log 轉送到 Graylog),就需要新增自訂規則。

本文以開放 ESXi outbound TCP/UDP port 5140(Graylog syslog)為例。

準備:啟用 SSH

在 vSphere 介面啟用 ESXi SSH,登入後進行後續操作。

建立規則設定檔

ESXi 的 firewall 規則以 XML 格式存放在 /etc/vmware/firewall/。新增規則只需複製一份現有範本再修改:

1
2
cd /etc/vmware/firewall
cp vltd-firewall.xml graylog-syslog.xml

修改 graylog-syslog.xml,定義 TCP 和 UDP 兩條規則:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<ConfigRoot>
<service id='0000'>
   <id>graylog-syslog-tcp</id>
   <rule id='0000'>
      <direction>outbound</direction>
      <protocol>tcp</protocol>
      <porttype>dst</porttype>
      <port>5140</port>
   </rule>
   <enabled>false</enabled>
   <required>false</required>
</service>
<service id='0001'>
   <id>graylog-syslog-udp</id>
   <rule id='0000'>
      <direction>outbound</direction>
      <protocol>udp</protocol>
      <porttype>dst</porttype>
      <port>5140</port>
   </rule>
   <enabled>false</enabled>
   <required>false</required>
</service>
</ConfigRoot>

重新載入 Firewall 規則

1
esxcli network firewall refresh

確認新規則已出現:

1
2
3
# esxcli network firewall ruleset list | grep graylog
graylog-syslog-tcp             false
graylog-syslog-udp             false

啟用規則

用 CLI 指定規則 ID 啟用,或在 vSphere Web GUI 的 Manage > Security & users > Firewall 勾選:

1
esxcli network firewall ruleset set --ruleset-id=graylog-syslog-udp --enabled=true

References

Licensed under CC BY-NC-SA 3.0 TW
最後更新 2026-05-07
comments powered by Disqus