幫助中心

伺服器、網路和帳戶的分步教程。

網路與 IP

Linux 新增 IP 地址教程:在 Ubuntu、Debian、CentOS 與 Rocky Linux 綁定額外 IPv4

Linux 新增 IP 地址教程:在 Ubuntu、Debian、CentOS 與 Rocky Linux 綁定額外 IPv4

若您的 JUSTG 雲伺服器已新增額外 IP,或您為 JUSTG 獨立伺服器申請了 /24 IP 段,必須先在 Linux 新增 IP 地址,該 IP 才能響應流量。本文說明如何用 ip addr add 臨時綁定額外 IPv4、如何在 Ubuntu 用 netplan、Debian 用 /etc/network/interfaces、CentOS/Rocky/AlmaLinux 用 nmcli 永久設定、IP 位於不同子網時如何設定來源路由,以及如何用迴圈綁定整段 /24。示例使用文件專用地址,請替換成客戶中心顯示的 IP、字首與閘道器。

網路設定錯誤可能讓 SSH 斷線。請只綁定分配給您的地址,並提前準備好控制檯。雲伺服器請使用 VNC 控制檯:客戶中心 → My Services(我的服務)→ 開啟該 VPS(Product Details 頁面)→ 在“Server Information”標籤頁的 VPS 面板中點選“VNC”。同一個 VNC 控制檯也可在 Enduser Panel 中開啟(Manage 卡片 → Virtualizor → “Enduser Panel”)。獨立伺服器請使用客戶中心的 IPMI 控制檯。如找不到控制檯可提交工單。

步驟 1:確認網路介面名稱與目前的 IP

ip 的精簡模式會列出每個介面與其地址。請記下主 IP 所在的介面(常見為 eth0、ens3 或 enp1s0)以及預設閘道器。

ip -br a
ip route show default

步驟 2:用 ip addr add 臨時新增 IP(測試用)

測試新地址最快的方法是臨時新增。重啟後就會消失,因此適合用來初步確認。

# add the extra IPv4 (not persistent, lost after reboot)
ip addr add 203.0.113.11/24 dev eth0

# confirm and test outgoing traffic from the new address
ip -br a show eth0
ping -c 3 -I 203.0.113.11 1.1.1.1

# remove it again if needed
ip addr del 203.0.113.11/24 dev eth0

如果以新來源地址 ping 成功,代表該 IP 已正確路由到您的伺服器,可以改為永久設定。

步驟 3:在 Ubuntu 用 netplan 永久新增額外 IP

Ubuntu 的網路設定存放在 /etc/netplan/ 下的 YAML 檔案。把新地址加入該介面的 addresses 列表,縮排只能使用空格。

# /etc/netplan/50-cloud-init.yaml (the file name may differ)
network:
  version: 2
  ethernets:
    eth0:
      addresses:
        - 203.0.113.10/24
        - 203.0.113.11/24
      routes:
        - to: default
          via: 203.0.113.1
      nameservers:
        addresses: [1.1.1.1, 8.8.8.8]
netplan try      # rolls back automatically if you lose access and do not confirm
netplan apply

若伺服器由 cloud-init 部署,重啟後設定被覆蓋,可停用 cloud-init 的網路管理:

echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

步驟 4:在 Debian 用 /etc/network/interfaces 新增 IP

使用 ifupdown 的 Debian 允許同一介面有多個 iface 段,每多一個段就多一個地址。

# /etc/network/interfaces
auto eth0
iface eth0 inet static
    address 203.0.113.10/24
    gateway 203.0.113.1

iface eth0 inet static
    address 203.0.113.11/24

建議在 VNC 控制檯中應用,或在維護時段直接重啟:

systemctl restart networking

步驟 5:在 CentOS、Rocky Linux、AlmaLinux 用 nmcli 新增 IP

這些系統使用 NetworkManager。連線名稱可能是 System eth0、eth0 或 Wired connection 1,請先列出確認。+ 代表附加地址,而不是取代主 IP。

nmcli con show                       # find the connection name
nmcli con mod "System eth0" +ipv4.addresses 203.0.113.11/24
nmcli con up "System eth0"
nmcli -g ipv4.addresses con show "System eth0"

完成後執行 ip -br a,確認介面上兩個地址都存在。

步驟 6:IP 位於不同子網時設定來源路由

如果額外 IP 屬於另一個有獨立閘道器的子網,響應資料包可能以錯誤的來源從主閘道器送出而被丟棄。策略路由可讓來自額外 IP 的流量走它自己的閘道器:

# extra IP 198.51.100.10 with its own gateway 198.51.100.1
ip addr add 198.51.100.10/24 dev eth0
ip route add default via 198.51.100.1 dev eth0 table 100
ip rule add from 198.51.100.10 table 100
ip rule show

要在重啟後保留,請使用對應的永久設定:

# netplan: add under eth0
      routes:
        - to: default
          via: 203.0.113.1
        - to: default
          via: 198.51.100.1
          table: 100
      routing-policy:
        - from: 198.51.100.10
          table: 100

# nmcli (CentOS / Rocky / AlmaLinux)
nmcli con mod "System eth0" +ipv4.routes "0.0.0.0/0 198.51.100.1 table=100" \
  +ipv4.routing-rules "priority 100 from 198.51.100.10 table 100"
nmcli con up "System eth0"
若額外 IP 段是路由到您的主 IP、沒有獨立閘道器,就不需要策略路由,改用 /32 字首新增地址即可。

步驟 7:在 JUSTG 獨立伺服器上綁定整段 /24

一段 /24 共有 256 個地址。請依分配資訊確認閘道器與可用範圍;以下示例中 .1 為閘道器,.2 到 .254 可用。用迴圈一次新增以便測試:

# example: 198.51.100.0/24, gateway 198.51.100.1, usable .2 - .254
for i in $(seq 2 254); do
  ip addr add 198.51.100.$i/24 dev eth0
done
ip -4 -o addr show dev eth0 | wc -l

永久設定時,用命令生成配置內容,不必手動輸入 253 行:

# Ubuntu (netplan): print the address lines, then paste them under "addresses:"
for i in $(seq 2 254); do echo "        - 198.51.100.$i/24"; done

# Debian (/etc/network/interfaces): one line inside the eth0 stanza
    up for i in $(seq 2 254); do ip addr add 198.51.100.$i/24 dev eth0; done

# CentOS / Rocky / AlmaLinux (NetworkManager)
ADDRS=$(for i in $(seq 2 254); do printf "198.51.100.%s/24," "$i"; done)
nmcli con mod "System eth0" +ipv4.addresses "${ADDRS%,}"
nmcli con up "System eth0"

重啟後執行 ip -4 -o addr show dev eth0 | wc -l 計算數量,確認所有地址都已恢復。

常見問題

如何為 VPS 獲取更多 IPv4?

每臺 JUSTG 雲伺服器含 1 個 IPv4。如需新增 IPv4,請提交工單聯絡技術支援;獨立伺服器另有 /24 IP 段可選。所有云伺服器也都免費提供 IPv6。

新 IP 已出現在 ip -br a,但從外部連不到,該檢查什麼?

對照分配資訊確認字首與閘道器、確認防火牆允許該地址上的服務,並用 ping -I 測試。若仍失敗,可能該 IP 尚未路由到您的伺服器。

伺服器對外連線時使用哪個地址?

預設使用該子網的主要(第一個)地址。應用程式可以綁定特定 IP,也可以在路由上設定 src 引數。

如仍無法解決,請提交工單聯絡 JUSTG 技術支援,並附上 IP 分配資訊與 ip -br a 的輸出。

這篇文章有幫助嗎?
幫助中心
網路與 IP VPS 網速測試:用 iperf3、Speedtest CLI 與 curl 測試伺服器頻寬與延遲 完整的 VPS 網速測試要回答兩個問題:伺服器能收發多少頻寬,以及資料包在伺服器與使用者之間傳輸要多久。本文說明如何在執行 Debian/Ubuntu 或 CentOS/Rocky/AlmaLinux 的 JUSTG 雲伺服器或獨立伺服器上,使用 iperf3… 網路與 IP Linux VPS 開啟 TCP BBR 擁塞控制教程(Debian、Ubuntu、CentOS、Rocky Linux) TCP BBR 是 Google 開發的擁塞控制演算法,自 Linux 核心 4.9 起內建。在高延遲的長距離線路上,例如從 JUSTG 約翰內斯堡或莫斯科機房的伺服器傳送資料到亞洲使用者,預設的 CUBIC 演算法只要遇到少量丟包就會大幅降速;BBR… 網路與 IP 什麼是原生 IP?如何查詢伺服器 IP 的歸屬地 原生 IP 是指註冊在伺服器實際所在國家網路名下的 IP 地址,因此 whois 記錄和 IP 地理位置資料庫顯示的都是這個國家。用 whois 加一次地理位置查詢,一分鐘就能查清任意伺服器 IP 的歸屬地,方法見下文。JUSTG 東京和首爾雲伺服器均配備日本、韓國原生… 網路與 IP 如何檢測 VPS 能否解鎖 Netflix、Disney+ 和 AI 服務 流媒體和 AI 服務根據伺服器的公網 IP 判斷你所在的位置,因此檢測 VPS 是否“解鎖”,先確認 IP 所屬國家,再直接在伺服器上逐項測試。本文介紹 Windows Server(透過 RDP 在瀏覽器中測試)和 Linux(用 curl 測試)兩種方法,並附上 JUSTG…
AlipayUnionPayVISAMastercardPayPalUSDTstripe