Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux

 

Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux
Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux

使用图形界面更改 IP 地址很容易,但是您知道 Linux 还允许您使用命令行中的简单命令更改网卡的 IP 地址吗?

这个技巧应该适用于所有基于 Debian 的 Linux 发行版,包括 Ubuntu。要开始,ifconfig请在终端提示符下键入,然后按 Enter。此命令列出系统上的所有网络接口,因此请记下要更改其 IP 地址的接口的名称。

Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux
Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux

要更改设置,您还可以使用 ifconfig 命令,这次带有一些附加参数。以下命令将名为“eth0”的网络接口更改为使用 IP 地址 102.168.0.1,并分配子网掩码 255.255.255.0:

sudo ifconfig eth0 192.168.0.1 netmask 255.255.255.0
Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux
Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux

当然,您可以替换为您想要的任何值。如果您再次运行 ifconfig,您将看到您的界面现在已经采用了您分配给它的新设置。

Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux
Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux

如果还需要更改网络接口使用的默认网关,可以使用 route 命令。例如,以下命令将“eth0”接口的默认网关设置为 192.168.0.253:

sudo route add default gw 192.168.0.253 eth0
Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux
Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux

要查看您的新设置,您需要显示路由表。在提示符处键入以下命令,然后按 Enter:

route -n
Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux
Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux

 

这就是从终端更改 IP 地址的全部内容。

 

 

本文:Linux: 命令行更改 IP 地址, How to Change Your IP Address From the Command Line in Linux

 

 

 

 

 

Loading

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.