温馨提示×

Debian下ifconfig如何设置静态IP

小樊
36
2025-11-02 00:47:52
栏目: 智能运维

在Debian系统中,要设置静态IP地址,你需要编辑网络接口配置文件。以下是具体步骤:

  1. 打开终端。

  2. 使用文本编辑器打开网络接口配置文件。在这个例子中,我们将使用nano编辑器。你可以使用你喜欢的任何文本编辑器。将<interface>替换为你要配置的网络接口名称,例如eth0ens33

sudo nano /etc/network/interfaces
  1. 在文件中找到你要配置的网络接口。如果你使用的是DHCP,它可能看起来像这样:
iface <interface> inet dhcp
  1. 将其更改为静态IP配置。将<address><netmask><gateway><dns-nameservers>替换为适当的值。例如:
iface <interface> inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 8.8.4.4
  • address:分配给网络接口的静态IP地址。
  • netmask:子网掩码。
  • gateway:默认网关。
  • dns-nameservers:DNS服务器地址,可以用空格分隔多个值。
  1. 保存并关闭文件。

  2. 重启网络服务以应用更改:

sudo systemctl restart networking

或者,你可以重启计算机:

sudo reboot

现在,你的Debian系统应该已经使用指定的静态IP地址进行网络连接了。你可以使用ifconfig命令查看新的IP地址配置。

0