Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIAi2 WildChat-4.8M (AI2)

How to block traffic to port 53 on my Single Node OpenShift server running RHCOS?

  1. User

    How to block traffic to port 53 on my Single Node OpenShift server running RHCOS?

  2. 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 / iptables on RHCOS directly

    RHCOS (Red Hat CoreOS) is a minimal, immutable OS, but you can apply firewall rules using firewalld or iptables. However, RHCOS does not have firewalld enabled by default; using direct iptables or creating a systemd unit to apply rules is common.

    Steps using iptables:

    1. Gain root access on the node

      sudo -i
      
    2. Check if the port is open (optional)

      ss -tuln | grep :53
      
    3. 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
      
    4. Save iptables rules so they persist after reboot

      RHCOS uses iptables but 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:

    1. 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
    
    1. 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
    
    1. Apply this MachineConfig:
    oc apply -f 99-block-port53.yaml
    
    1. Reboot the node to have the changes take effect.

    Note: Replace worker in the label with master if 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.