一、修改接口静态IP
查看/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 ens18
iface ens18 inet dhcp
# This is an autoconfigured IPv6 interface
iface ens18 inet6 auto
修改默认的接口ens18的IPV4的dhcp
# The primary network interface
allow-hotplug ens18
#static表示使用固定ip,dhcp表述使用动态ip
iface ens18 inet static
#设置ip地址
address 192.168.X.XXX
#设置子网掩码
netmask 255.255.255.0
#设置网关
getway 192.168.X.1
#设置网段
network 192.168.X.0
#设置广播地址
broadcast 192.168.X.255
#设置首选dns
dns-nameservers 192.168.X.1
二、重启网络
sudo systemctl restart NetworkManager.service
如果重启后无法ping通网络,可以尝试在/etc/network/interfaces
最后加入后,重启
up ip route add default via 192.168.X.1
如果无法进行DNS解析,需要手动配置/etc/resolv.conf
#设置dns
nameserver 192.168.X.1
评论区