方法一
sudo vim /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
auto eth0
iface etho inet static //配置eth0使用默认的静态地址
address 192.168.31.13 //设置eth0的IP地址
netmask 255.255.255.0 //配置eth0的子网掩码
gateway 192.168.31.2 //配置当前主机的默认网关
sudo vim /etc/resolv.conf
# Generated by NetworkManager
domain
nameserver 8.8.8.8
nameserver 114.114.114.114
/etc/init.d/networking restart #重启网卡
ping qq.com # 测试外网是否ok
这个方法不知道为什么在我pve虚拟机失效了,死活保存不了,估计是networking.service和NetworkManager冲突了,之前在物理机应该是ok的。
用右上角图形化修改的话,又上不了外网,困扰了一段时间。
更新
在/etc/network/interfaces 写上DNS服务器应该就ok了。。否则每次重启网卡reslov.conf会变为interfaces的
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.31.110
PREFIX=24
GATEWAY=192.168.31.2
DNS1=114.114.114.114
方法二
命令行输入
nmtui
进入图形化界面
这里操作比较简单
测试
更新
2023年12月4日 11:09:24
后来了解到NetworkManager的配置方式
cd /etc/NetworkManager/system-connections
#查看你的网卡,并编辑
[ipv4]
address1=192.168.31.188/24,192.168.31.1
dns=8.8.8.8;223.5.5.5;
method=manual
#重启
nmcli connection reload eth0
nmcli connection up eth0