一、Ubuntu 16.04网卡配置
1、Ubuntu 16.04配置网卡命令:
root@dream:/etc/network# vim /etc/network/interfaces
2、Ubuntu 16.04网卡常规配置:
二、Ubuntu 22.04网卡配置
1、Ubuntu 22.04配置网卡命令:
Ubuntu 16.04是编辑“interfaces”文件,而Ubuntu 22.04是编辑“00-installer-config.yaml”文件。
root@dream:/etc/netplan# vim /etc/netplan/00-installer-config.yaml root@dream:/etc/netplan# netplan apply
2、查看Ubuntu 22.04网卡配置:
当安装Ubuntu22.04时没有手动设置IP,默认自动获取IPv4地址:
当安装Ubuntu 22.04时手动设置了IP,进入系统后查看“00-installer-config.yaml”文件如下:
3、Ubuntu 22.04网卡配置命令实操:
1 dream@dream:~$ su 2 Password: 3 root@dream:/home/dream# ls /etc/net* 4 /etc/netconfig /etc/networks 5 6 /etc/netplan: 7 00-installer-config.yaml 8 9 /etc/network: 10 if-pre-up.d if-up.d 11 12 /etc/networkd-dispatcher: 13 carrier.d degraded.d dormant.d no-carrier.d off.d routable.d 14 root@dream:/home/dream# cd /etc/netplan/ 15 root@dream:/etc/netplan# ll 16 total 12 17 drwxr-xr-x 2 root root 4096 Aug 3 14:53 ./ 18 drwxr-xr-x 97 root root 4096 Aug 3 10:24 ../ 19 -rw-r--r-- 1 root root 117 Aug 3 10:21 00-installer-config.yaml 20 root@dream:/etc/netplan# vim /etc/netplan/00-installer-config.yaml 21 root@dream:/etc/netplan# netplan apply 22 root@dream:/etc/netplan#
手动修改“00-installer-config.yaml”文件参考如下:
enp0s3,网卡名。
dhcp4,false是设置静态IP,非自动获取。
192.168.34.177/24,IP地址和子网掩码,可以找IP地址计算器来算出子网掩码。
routes,via,这里是填网关。不是“gateway4”。
nameservers,addresses,这里是填dns服务器。
1 # This is the network config written by 'subiquity' 2 network: 3 ethernets: 4 enp0s3: 5 dhcp4: false 6 addresses: 7 - 192.168.34.177/24 8 routes: 9 - to: default 10 via: 192.168.34.209 11 nameservers: 12 addresses: 13 - 192.168.34.209 14 version: 2
截图:
另一种配置方式参考:
1 # This is the network config written by 'subiquity' 2 network: 3 ethernets: 4 enp0s3: 5 dhcp4: false 6 addresses: [192.168.34.177/24] 7 routes: 8 - to: default 9 via: 192.168.34.209 10 nameservers: 11 addresses: [192.168.34.209] 12 version: 2
截图:
输入“netplan apply”使配置生效,可以“reboot”重启一下系统。
当遇到如这样的报错时说明格式对齐有问题:
/etc/netplan/00-installer-config.yaml:10:7: Invalid YAML: inconsistent indentation。
跟着上面两种配置的对齐方式可处理即可,这是Ubuntu 22.04和23.04的一个小坑,可以用WinSCP等软件传一个配置好的“00-installer-config.yaml”文件进来也行。
1 #报错1 2 root@dream:/etc/netplan# vim /etc/netplan/00-installer-config.yaml 3 root@dream:/etc/netplan# netplan apply 4 /etc/netplan/00-installer-config.yaml:10:7: Invalid YAML: inconsistent indentation: 5 nameservers: 6 ^ 7 root@dream:/etc/netplan# 8 #报错2 9 root@dream:/etc/netplan# vim /etc/netplan/00-installer-config.yaml 10 root@dream:/etc/netplan# netplan apply 11 /etc/netplan/00-installer-config.yaml:7:4: Invalid YAML: inconsistent indentation: 12 routes: 13 ^ 14 root@dream:/etc/netplan#
查看“netplan”文件:
root@dream:/etc/netplan# whereis netplan netplan: /usr/sbin/netplan /usr/lib/netplan /etc/netplan /usr/share/netplan /usr/share/man/man5/netplan.5.gz root@dream:/etc/netplan#
“man”一下“netplan”,或者用WinSCP等软件把netplan.5.gz取出看看:
root@dream:/etc/netplan# man netplan
标签:16.04,dream,netplan,网卡,etc,Ubuntu,config,root From: https://www.cnblogs.com/dayetonghaocai/p/17605493.html