若您的 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、前缀与网关。
步骤 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"步骤 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 的输出。