这里指的是server版的网卡配置
Ubuntu网卡更改名称:ens3=>eth0
步骤1:首先切换到 root 账号,然后 vi /etc/default/grub;
步骤2:修改参数 GRUB_CMDLINE_LINUX 添加 net.ifnames=0 biosdevname=0;
步骤3:然后保存文件,执行命令update-grub
步骤2和步骤3合并 命令执行:
sed -i -r 's#^(GRUB_CMDLINE_LINUX=")"$#\1net.ifnames=0 biosdevname=0"#' /etc/default/grub && update-grub
步骤4:编辑文件 /etc/network/interface 保存后重启ubuntu
步骤5:最后验证是否修改成功
新版本配置
ubuntu 18.04的网络配置的方式相较于原来的版本有了很大的改动,并且server版的和Desktop 版本的是不一样的。
Server版本
新的版本采用了netplan 管理网络,在命令行中配置有点差别,配置文件在
/etc/netplan/*.yaml
*.yaml 就是那个配置文件,不同的计算机文件名称是不同的。
例如可以这样配置:
network:
version: 2
ethernets:
eno1:
addresses: [192.168.0.111/24]
gateway4: 192.168.0.1
dhcp4: no
nameservers:
addresses: [192.168.0.1,223.5.5.5]
一定要注意缩进。
在这里可以设置静态ip和DNS,设置完成后运行命令:
sudo netplan apply
就更新了网络的设置
旧版本如下配置
网卡配置文件:/etc/network/interface
修改方式:
1.切换到root用户修改
2.使用sudo命令授权
默认配置文件内容:
cheng@ubuntu:~$ sudo cat /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
auto eth0
iface eth0 inet dhcp
修改,添加静态地址:
cheng@ubuntu:~$ sudo 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
auto eth0
iface eth0 inet static
address 192.168.40.14
gateway 192.168.40.1
netmask 255.255.255.0
重启网络:
cheng@ubuntu:~$ sudo /etc/init.d/networking --help
Usage: /etc/init.d/networking {start|stop|reload|restart|force-reload}
cheng@ubuntu:~$ sudo /etc/init.d/networking restart
[ ok ] Restarting networking (via systemctl): networking.service.
添加一块网卡eth1
auto eth1
iface eth1 inet static
address 192.168.40.15
netmask 255.255.255.0
gateway 192.168.40.1