在 CentOS 系统中,您可以使用 nmcli
或 nmtui
命令行工具来修改网关。以下是使用这两个工具的方法:
方法1:使用 nmcli
nmcli connection show
找到您要修改网关的网络接口名称,例如:eth0
。
删除当前连接:
nmcli connection delete <interface-name>
将 <interface-name>
替换为您在步骤2中找到的网络接口名称。
nmcli connection add type ethernet ifname <interface-name> con-name <new-connection-name> autoconnect yes ip4 192.168.1.100/24 gw4 192.168.1.1
将 <interface-name>
替换为您的网络接口名称,<new-connection-name>
替换为您想要为新的连接设置的名称,192.168.1.100/24
替换为您的 IP 地址和子网掩码,192.168.1.1
替换为您的网关地址。
nmcli connection up <new-connection-name>
将 <new-connection-name>
替换为您在步骤4中设置的新连接名称。
方法2:使用 nmtui
nmtui
选择 “Edit a connection” 并按 Enter。
选择您要修改的网络接口并点击 “Edit”。
在 “IPv4 CONFIGURATION” 部分,将 “Method” 更改为 “Manual”。
在 “Addresses” 下输入您的 IP 地址和子网掩码,例如:192.168.1.100/24
。
在 “Gateway” 下输入您的网关地址,例如:192.168.1.1
。
按下 “OK” 保存更改,然后退出 nmtui。
重新启动网络服务以应用更改:
systemctl restart network
完成以上步骤后,您的 CentOS 系统应该已经成功修改了网关。