温馨提示×

Debian Minimal网络设置怎样

小樊
55
2025-08-12 02:24:51
栏目: 智能运维

Debian Minimal网络设置常用方法如下:

一、使用传统配置文件(适用于Debian 9及之前版本)

编辑 /etc/network/interfaces 文件:

  • 静态IP
    auto eth0  
    iface eth0 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  
    
  • DHCP
    auto eth0  
    iface eth0 inet dhcp  
    

保存后重启网络:sudo systemctl restart networking

二、使用netplan(适用于Debian 10及更高版本)

安装netplan:sudo apt install netplan.io
编辑配置文件(如 /etc/netplan/01-netcfg.yaml):

network:  
  version: 2  
  renderer: networkd  
  ethernets:  
    eth0:  
      dhcp4: no  
      addresses: [192.168.1.100/24]  
      gateway4: 192.168.1.1  
      nameservers:  
        addresses: [8.8.8.8, 8.8.4.4]  

应用配置:sudo netplan apply

三、使用NetworkManager(图形化或命令行)

安装:sudo apt install network-manager

  • 命令行配置
    nmcli con mod 'Wired connection 1' ipv4.addresses 192.168.1.100/24  
    nmcli con mod 'Wired connection 1' ipv4.gateway 192.168.1.1  
    nmcli con mod 'Wired connection 1' ipv4.dns "8.8.8.8"  
    nmcli con up 'Wired connection 1'  
    
  • 图形化配置:通过 nm-connection-editor 工具编辑。

四、临时配置(重启后失效)

  • IP地址sudo ip addr add 192.168.1.100/24 dev eth0
  • 网关sudo ip route add default via 192.168.1.1
  • DNS:编辑 /etc/resolv.conf 添加 nameserver 8.8.8.8

验证配置

  • 查看IP:ip addr show eth0
  • 测试连通性:ping 8.8.8.8

注意:根据实际网络接口名称(如 enp0s3 等)调整配置中的 eth0,确保配置文件语法正确。

0