Ubuntu问题处理

Ubuntu20.04 修改网卡配置

ubuntu 从 17.10 开始,已放弃在 /etc/network/interfaces 里固定 IP 的配置,即使配置也不会生效,而是改成 netplan 方式 ,配置写在 /etc/netplan/01-netcfg.yaml 或者类似名称的 yaml 文件里”

  • Ubuntu20.04 服务器版的网络服务是 systemd-networkd
  • 桌面版(图形界面),使用 NetworkManager 服务;

man netplan 可以查看详细的功能说明。

下面是在树莓派4B 上的 Ubuntu20.04 Server版本上配置无线网卡的过程:

  1. 配置之前通过 ip a 查看 wlan0 网卡信息,没有 ip 地址;

  2. 修改 /etc/netplan/50-cloud-init.yaml 文件配置;

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    network:
    ethernets:
    eth0:
    dhcp4: true
    optional: true
    wifis:
    # 网卡名
    wlan0:
    dhcp4: true
    optional: true
    access-points:
    # 这里填写需要连接的 wifi 的 sid名称
    "FAST_250E":
    # 这里填写 wifi 密码
    password: "15xxxxx7"
    version: 2
  3. 配置好文件后,执行 netplan try --debug 命令没有错误的情况下会提示更新配置,按回车键接受新的配置;

  4. 查看当前网卡信息 ip a 确认 ip 信息;

可以通过查看 netplan 文件认识一下 netplan

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
ubuntu@ubuntu:~$ which netplan
/usr/sbin/netplan
ubuntu@ubuntu:~$ ll /usr/sbin/netplan
lrwxrwxrwx 1 root root 31 Dec 3 10:12 /usr/sbin/netplan -> ../share/netplan/netplan.script*
ubuntu@ubuntu:~$ file /usr/share/netplan/netplan.script
/usr/share/netplan/netplan.script: Python script, ASCII text executable
ubuntu@ubuntu:~$ netplan -h
usage: /usr/sbin/netplan [-h] [--debug] ...

Network configuration in YAML

optional arguments:
-h, --help show this help message and exit
--debug Enable debug messages

Available commands:

help Show this help message
apply Apply current netplan config to running system
generate Generate backend specific configuration files from /etc/netplan/*.yaml
get Get a setting by specifying a nested key like "ethernets.eth0.addresses", or "all"
info Show available features
ip Retrieve IP information from the system
set Add new setting by specifying a dotted key=value pair like ethernets.eth0.dhcp4=true
try Try to apply a new netplan config to running system, with automatic rollback
ubuntu@ubuntu:~$

从上面信息可知,netplan 是一个 python 程序,使用 yaml 文件格式配置。

ubuntu 设置 root 用户密码

ubuntu 查看防火墙

ufw => uncomplicated firewall 简单防火墙

1
2
3
4
5
6
7
8
9
10
11
root@www:~# systemctl status ufw
● ufw.service - Uncomplicated firewall
Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2022-04-19 18:12:32 CST; 2 weeks 0 days ago
Docs: man:ufw(8)
Main PID: 554 (code=exited, status=0/SUCCESS)
CPU: 6ms

Apr 19 18:12:31 ubuntu systemd[1]: Starting Uncomplicated firewall...
Apr 19 18:12:32 ubuntu systemd[1]: Finished Uncomplicated firewall.

默认是启动的。

解决apt-get /var/lib/dpkg/lock-frontend 问题

运行 apt-get 时报如下错

1
2
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

解决方案:

1
2
3
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/lib/dpkg/lock
sudo rm /var/cache/apt/archives/lock

可以依次删除,或者删除一条后,执行apt-get,一般会继续报错并提到上面的其他文件的,然后依据报错提示文件删除即可。

或者使用下面的思路来处理。

用 lsof 命令看看这几个文件是被哪个进程锁住的啊,然后先杀掉那几个进程。

1
lsof /var/lib/dpkg/lock-frontend

因为可能是 apt 其他进程在运行,所以会锁住dpkg file,要么等待完成,要么提前删除文件或者结束该进程。

也可以

1
2
3
ps -ef | grep apt

kill -9 <进程ID>
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2022-2023 ligongzhao
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信