ubuntu 18.04设置固定ip以及无线网卡配置。

2023-05-16

ubuntu从17.10开始,已放弃在/etc/network/interfaces里固定IP的配置,即使配置也不会生效,而是改成netplan方式 ,配置写在/etc/netplan/01-netcfg.yaml或者类似名称的yaml文件里,18.04的server版本安装好以后,配置文件是:/etc/netplan/50-cloud-init.yaml,修改配置以后不用重启,执行 netplan apply 命令可以让配置直接生效。以前的重启网络服务命令/etc/init.d/networking restart或者services network restrart也都会提示为无效命令。
为了方便使用树莓派,我准备将树莓派的网线口设置为固定IP,无线设置为DHCP。
首先查看无线网卡
在这里插入图片描述
其中的wlan0是无线网卡的名称。
$sudo vim /etc/netplan/50-cloud-init.yaml,配置文件可按如下内容修改。

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        eth0:
            #dhcp4: true
                        dhcp4:  false
                        addresses: [192.168.2.226/24]
                        gateway4: 192.168.2.1
                        nameservers:
                            addresses: [192.168.2.1]
                        optional: true
    wifis:
        wlan0:
                        dhcp4: true
                        optional: true
                        access-points:
                           "你的wifi名称":
                               password: "你的wifi密码"
    version: 2

其中,addresses里的 24是掩码,查询,对应关系见下图
在这里插入图片描述
修改完成后保存,netplan apply启动。

netplan apply

如果报错,根据报错提示修改50-cloud-init.yaml,直至不报错……
经过无数次修改,终于OK了……
在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ubuntu 18.04设置固定ip以及无线网卡配置。 的相关文章

随机推荐