Debian 配置网络

  • 查看网络名称

    ip addr
    

    ls /sys/class/net/
    

    结果

    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
      inet 127.0.0.1/8 scope host lo
         valid_lft forever preferred_lft forever
      inet6 ::1/128 scope host
         valid_lft forever preferred_lft forever
    2: ens7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
      link/ether 56:6f:97:a2:00:0a brd ff:ff:ff:ff:ff:ff
      altname enp0s7
      inet 192.168.56.159/24 brd 192.168.56.255 scope global ens7
         valid_lft forever preferred_lft forever
      inet6 fdc5:d60e:2656:0:546f:97ff:fea2:a/64 scope global dynamic mngtmpaddr
         valid_lft forever preferred_lft forever
      inet6 fe80::546f:97ff:fea2:a/64 scope link
         valid_lft forever preferred_lft forever
    
  • 手动设置IP上网,在底部添加

    vi /etc/network/interfaces
    

    写入如下配置

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    source /etc/network/interfaces.d/*
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    allow-hotplug ens7
    iface ens7 inet static
            address 192.168.56.159
            netmask 255.255.255.0
            gateway 192.168.56.1
            # dns-* options are implemented by the resolvconf package, if installed
            dns-nameservers 192.168.57.6 218.2.2.2
    
  • 指定网卡重启
    停用网卡

    ifdown ens7
    

    启用网卡

    ifup ens7
    
  • 网络重启

    systemctl restart networking