在 Ubuntu 中,您可以使用 ifconfig 命令来查看和配置网络接口。但是,请注意,ifconfig 在较新的 Ubuntu 版本中已被弃用,建议使用 ip 命令。不过,如果您仍然想使用 ifconfig,可以按照以下步骤操作:
打开终端(快捷键:Ctrl + Alt + T)。
首先,使用以下命令查看所有网络接口:
ifconfig -a eth0 的网络接口:sudo ifconfig eth0 down sudo ifconfig eth0 up sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 将 192.168.1.100 替换为您想要的 IP 地址,将 255.255.255.0 替换为子网掩码。
/etc/network/interfaces 文件:sudo nano /etc/network/interfaces 在文件中找到您的网络接口(例如 eth0),然后更改 gateway 行。例如:
auto eth0 iface eth0 inet static address 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.1 将 192.168.1.100 替换为您想要的 IP 地址,将 255.255.255.0 替换为子网掩码,将 192.168.1.1 替换为您的网关地址。
sudo service networking restart 或者,您可以重启计算机以使更改生效。
再次强调,建议使用 ip 命令而不是 ifconfig。如果您想使用 ip 命令,请告诉我,我可以为您提供相应的帮助。