温馨提示×

centos下ifconfig怎么修改网关

小樊
44
2025-09-26 11:04:27
栏目: 智能运维

在 CentOS 系统中,您可以使用 nmclinmtui 命令行工具来修改网关。以下是使用这两个工具的方法:

方法1:使用 nmcli

  1. 查看当前连接的网络接口:
nmcli connection show
  1. 找到要修改网关的网络接口名称,例如:eth0

  2. 删除当前网络接口的 IPv4 路由:

nmcli connection modify eth0 ipv4.routes ""
  1. 添加新的网关:
nmcli connection modify eth0 ipv4.gateway <新网关地址>

<新网关地址> 替换为您要设置的新网关地址。

  1. 重新启动网络接口以应用更改:
nmcli connection up eth0

方法2:使用 nmtui

  1. 运行 nmtui 命令以打开网络管理器文本界面:
nmtui
  1. m 键选择 “Edit a connection”。

  2. 使用箭头键选择要修改的网络接口,然后按 Enter

  3. 在 “IPv4 CONFIGURATION” 部分,将 “Method” 更改为 “Manual”。

  4. 在 “Addresses” 下,将 “Address” 设置为 “IP Address”,并将 “Gateway” 设置为您要使用的新网关地址。

  5. OK 保存更改,然后按 Esc 返回到主菜单。

  6. 选择 “Activate a connection” 并按 Enter 以应用更改。

完成上述步骤后,您的 CentOS 系统应该已经成功修改了网关。您可以使用 ip route 命令查看新的路由设置。

0