温馨提示×

Debian Minimal网络设置

小樊
55
2025-08-14 02:39:37
栏目: 智能运维

Debian Minimal系统的网络设置可通过以下方式完成:

一、静态IP配置

  1. 编辑网络接口文件

    sudo nano /etc/network/interfaces  
    

    添加以下内容(以eth0接口为例):

    auto eth0  
    iface eth0 inet static  
        address 192.168.1.100/24  
        gateway 192.168.1.1  
        dns-nameservers 8.8.8.8 8.8.4.4  
    

    说明/24表示子网掩码为255.255.255.0,需根据实际网络调整IP和网关。

  2. 重启网络服务

    sudo systemctl restart networking  
    

二、DHCP客户端配置

  1. 编辑网络接口文件
    sudo nano /etc/network/interfaces  
    
    修改为:
    auto eth0  
    iface eth0 inet dhcp  
    
    保存后重启网络服务:
    sudo systemctl restart networking  
    

三、使用netplan(适用于Debian 10+)

  1. 安装netplan
    sudo apt update && sudo apt install netplan.io  
    
  2. 编辑配置文件
    sudo nano /etc/netplan/01-netcfg.yaml  
    
    示例(静态IP):
    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  
    

四、验证网络

  • 查看IP地址
    ip addr show eth0  
    
  • 测试连通性
    ping -c 4 8.8.8.8  
    

注意事项

  • 确认接口名称(如eth0、ens33等),可通过ip link show查看。
  • 云服务器需在控制台配置安全组规则,允许对应端口的出入站流量。
  • 生产环境建议使用静态IP并关闭不必要的服务,最小化攻击面。

0