設定 alternatives

已棄用的內容

本頁記錄 iptables-legacy alternative;它已於 Fedora CoreOS 43 及更新版本中移除。本頁的範例與操作說明已*不再適用*於目前的 Fedora CoreOS 版本。此內容僅保留供歷史參考。

由於 alternatives 設定在系統上的儲存方式存在一項 持續追蹤中的問題,Fedora CoreOS 系統無法使用一般的 alternatives 指令來設定它們。

在問題解決前,可改為直接設定 /etc/alternatives 中的符號連結。例如,若要使用 iptables 指令的舊版變體:

variant: fcos
version: 1.7.0
storage:
  links:
    - path: /etc/alternatives/iptables
      target: /usr/sbin/iptables-legacy
      overwrite: true
      hard: false
    - path: /etc/alternatives/iptables-restore
      target: /usr/sbin/iptables-legacy-restore
      overwrite: true
      hard: false
    - path: /etc/alternatives/iptables-save
      target: /usr/sbin/iptables-legacy-save
      overwrite: true
      hard: false
    - path: /etc/alternatives/ip6tables
      target: /usr/sbin/ip6tables-legacy
      overwrite: true
      hard: false
    - path: /etc/alternatives/ip6tables-restore
      target: /usr/sbin/ip6tables-legacy-restore
      overwrite: true
      hard: false
    - path: /etc/alternatives/ip6tables-save
      target: /usr/sbin/ip6tables-legacy-save
      overwrite: true
      hard: false

使用 alternatives 指令

從以 Fedora 41 為基礎的 Fedora CoreOS 開始,可以使用 alternatives 指令設定預設指令。

使用 systemd 單元設定預設 iptables 後端的 Butane 設定範例
variant: fcos
version: 1.7.0
systemd:
  units:
    - name: custom-iptables-default.service
      enabled: true
      contents: |
        [Unit]
        Description=Set the default backend for iptables
        [Service]
        ExecStart=/usr/sbin/alternatives --set iptables /usr/sbin/iptables-legacy
        RemainAfterExit=yes
        [Install]
        WantedBy=multi-user.target
我們不建議將預設 iptables 後端設定為 iptables-legacy。這裡僅作為範例。

也可以手動執行 alternatives 指令來設定執行時所使用的預設指令。

手動設定預設 iptables 後端的範例
# Check the link info
alternatives --display iptables
iptables --version

# Configure iptables to point to iptables-nft
sudo alternatives --set iptables /usr/sbin/iptables-nft

# Verify iptables version is iptables-nft
alternatives --display iptables
iptables --version