虚拟机默认安装Linux,完成后是ens32,ens18,..这些网卡名称,以及默认使用DHCP,自动分配IP,网关。手动自定义更换
更换
虚拟机默认安装Linux后,网卡总是ens32,ens18这些网卡,以及IP是自动DHCP默认设置
查看网卡
Linux安装 net-tools
工具,可使用ifconfig,netstat,等工具
iconfig,ip,工具
使用ifcofnig
,ip addr
,等查看网卡
更换网卡IP
这里用得Debian 11系统
Debian网卡配置路径
/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
可以看到ens18
网卡,使用 dhcp
自动分配IP
手动配置
给默认ens18前面添加注释
修改后面配置
# 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
#新添加得 eth0网卡
auto eth0
iface eth0 inet static
address 188.8.8.4
netmask 255.255.255.0
gateway 188.8.8.1
说明
auto eth0 开机自启动网卡名称
iface eth0 inet static 定义网卡名+设置静态IP
address 188.8.8.4 设置ipv4地址
netmask 255.255.255.0 设置子网掩码
gateway 188.8.8.1 设置网关
修改grub引导
路径
/etc/default/grub
找到这行:GRUB_CMDLINE_LINUX=""
修改为
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
保存退出
重新生成grub引导配置文件
grub-mkconfig -o /boot/grub/grub.cfg
最后重启
reboot
查看网卡
ifconfig
可以看到已经变成eth0,网卡了,,如有问题欢迎留言评论