How to block traffic to port 53 on my Single Node OpenShift server running RHCOS?
- User
How to block traffic to port 53 on my Single Node OpenShift server running RHCOS?
- Assistant
To block traffic to port 53 on your Single Node OpenShift server running RHCOS, you'll typically want to block the port at the node OS level since OpenShift itself doesn’t provide a direct way to block arbitrary ports cluster-wide.
Here’s a recommended approach:
Option 1: Use
firewalld/iptableson RHCOS directlyRHCOS (Red Hat CoreOS) is a minimal, immutable OS, but you can apply firewall rules using
firewalldoriptables. However, RHCOS does not havefirewalldenabled by default; using directiptablesor creating a systemd unit to apply rules is common.Steps using iptables:
-
Gain root access on the node
sudo -i -
Check if the port is open (optional)
ss -tuln | grep :53 -
Add iptables rule to block all incoming traffic to port 53 (UDP and TCP)
# Block TCP port 53 iptables -I INPUT -p tcp --dport 53 -j REJECT # Block UDP port 53 iptables -I INPUT -p udp --dport 53 -j REJECT -
Save iptables rules so they persist after reboot
RHCOS uses
iptablesbut does not have a default persistent save method like normal Red Hat systems; you generally need to use a systemd service or use OpenShift machine config.
Option 2: Use MachineConfig to apply iptables rules persistently
Since RHCOS is immutable, direct manual changes will not survive node reboot. The OpenShift way is to use a MachineConfig resource to modify the node’s configuration permanently.
Example MachineConfig to block port 53:
- Create an iptables rule script, e.g.
/etc/iptables-block-port53.sh:
#!/bin/bash iptables -I INPUT -p tcp --dport 53 -j REJECT iptables -I INPUT -p udp --dport 53 -j REJECT- Create a MachineConfig that:
- Places the above script on the node
- Adds a systemd unit that runs this script on boot
Sample MachineConfig YAML:
apiVersion: machineconfiguration.openshift.io/v1 kind: MachineConfig metadata: name: 99-block-port53 labels: machineconfiguration.openshift.io/role: worker # change to master if single node master spec: config: ignition: version: 3.2.0 storage: files: - path: /etc/iptables-block-port53.sh mode: 0755 contents: source: data:text/plain;base64,I2EvYmluL2Jhc2gKaXB0YWJsZXMgLUkgSU5QVVQgLXAgdGNwIC0tZHBvcnQgNTMgLWogUkVqZWNUCmlwdGFibGVzIC1JIElOUFVUIC1wIHVkcCAtLWRwb3J0IDUzIC1qIFJFamVjdA== systemd: units: - name: block-port53.service enabled: true contents: | [Unit] Description=Block incoming traffic to TCP/UDP port 53 Wants=network-online.target After=network-online.target [Service] Type=oneshot ExecStart=/etc/iptables-block-port53.sh [Install] WantedBy=multi-user.target- Apply this MachineConfig:
oc apply -f 99-block-port53.yaml- Reboot the node to have the changes take effect.
Note: Replace
workerin the label withmasterif your single node is a master node (likely in Single Node OpenShift).
Option 3: Block port 53 using OpenShift NetworkPolicies
NetworkPolicies can restrict traffic between pods but do not control or block traffic to the node’s ports like port 53 on the host OS.
If your goal was to block DNS traffic between pods or ingress into pods on port 53, then you could write NetworkPolicies — but for blocking node port traffic, this is not applicable.
Summary
- To block traffic to port 53 on the node itself, update iptables rules on RHCOS.
- Since RHCOS is immutable, use a MachineConfig to apply iptables rules persistently.
- Manual iptables changes will be lost after reboot.
- NetworkPolicies do not operate on node IP traffic or node ports.
If you want, I can also help provide the full commands step-by-step or troubleshoot the application of a MachineConfig for your cluster.
-