温馨提示×

如何在Debian Context中设置网络

小樊
51
2025-08-27 17:22:26
栏目: 智能运维

在Debian Context中设置网络,可根据不同版本和使用习惯选择以下方法:

  • 编辑配置文件(传统方法,适用于所有版本)
    • 静态IP配置:编辑/etc/network/interfaces文件,添加如auto eth0\niface eth0 inet static\naddress 192.168.1.100\nnetmask 255.255.255.0\ngateway 192.168.1.1\ndns-nameservers 8.8.8.8 8.8.4.4的内容。
    • DHCP配置:编辑/etc/network/interfaces文件,添加auto eth0\niface eth0 inet dhcp
    • 保存后重启网络服务:sudo systemctl restart networking
  • 使用netplan(适用于Debian 10及更高版本)
    • 编辑/etc/netplan/01-netcfg.yaml文件,例如静态IP配置为network:\n version: 2\n renderer: networkd\n ethernets:\n eth0:\n dhcp4: no\n addresses: [192.168.1.100/24]\n gateway4: 192.168.1.1\n nameservers:\n addresses: [8.8.8.8, 8.8.4.4]
    • 应用配置:sudo netplan apply
  • 使用NetworkManager(图形化或命令行,适用于桌面环境)
    • 图形界面:点击系统托盘中的NetworkManager图标,选择“编辑连接”,按提示配置IP、网关、DNS等。
    • 命令行:使用nmcli工具,如nmcli con add type ethernet con-name "连接名" ifname eth0 ipv4.addresses "192.168.1.100/24" ipv4.gateway "192.168.1.1" ipv4.dns "8.8.8.8 8.8.4.4" ipv4.method manual,然后nmcli con up "连接名"

0