Ubuntu 22.04LTS static IP configuration and source update

Ubuntu 22.04LTS static IP configuration and source update

1. Network mode confirmation

Note: The following operations are based on the VMWARE virtual environment, and it is necessary to confirm that the virtual network is configured in NAT mode.

Checking method: Edit --> Virtual Network Editor, enter the following page. Configure and remember the currently set gateway IP, subnet mask, and IP segment

Vmware Configuration Check

2. Static IP configuration

2-1. Switch administrator privileges

Turn on the virtual machine, enter the terminal, and switch to administrator mode:

# 执行后输入登录用户密码
sudo -i
# 初装系统root密码为随机密码,需要自行更改
passwd root
# 按照提示之后输入命令更改密码,提示successful为更新成功
# 之后登录执行以下指令直接进入管理员模式
su

Toggle command result

2-2. Modify network configuration

Ubuntu has introduced the Netplan network configuration tool since version 17.10, and manages it through netplan. The corresponding configuration files are as follows:

# 新安装的系统建议使用vi或nano编辑器修改文件内容,不支持vim
vi /etc/netplan/01-network-manager-all.yaml
nano /etc/netplan/01-network-manager-all.yaml

Configuration content:

# Let NetworkManager manage all devices on this system
network:
  ethernets:
    ens33:
      dhcp4: no
      dhcp6: no
      # 该项可选,不加也可行
      optional: true
      addresses:
      # 静态IP,需要在第一节配置的IP段内
       - 192.168.31.103/24
      routes:
       - to: default
       # 网关设置,需要和第一节检查的网关一致
         via: 192.168.31.2
      nameservers:
      # 网关配置格式还可采用该格式,多个地址采用英文逗号相隔
      # addresses: [114.114.114.114,8.8.8.8]
        addresses:
          - 114.114.114.114
          - 8.8.8.8
        search:
          - localhost
          - local
  version: 2
  renderer: NetworkManager

configuration content

2-3. Effective configuration

# 测试配置;正常如下
sudo netplan try

insert image description here

# 应用配置:不报错即可
sudo netplan apply

insert image description here

Check if it works:

ip addr

Network Configuration

Connectivity check:

ping www.baidu.com

ICMP authentication

2-4. Common tools installation

There are some tools that are commonly used during system use and are recommended to be installed, such as vim, net-tools (corresponding to the ifconfig command), and curl. Please refer to the installation for the content of this part.

# vim编辑器,vi的升级版
apt install vim -y
# ifconfig、netstat命令工具
apt install net-tools -y
# web服务器请求工具
apt install curl -y
# 执行以下指令一键安装
apt install vim -y;apt install net-tools -y;apt install curl -y

3. Mirror source update

3-1. List of available sources

Note: The sources set for different system versions are different, the following is for version 22.04.

1) Tsinghuayuan

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse

2) Aliyuan

deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

3) University of Science and Technology of China

deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

4) NetEase source

deb http://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse

3-2. Update source

Make a backup of the original source file:

mv /etc/apt/sources.list /etc/apt/sources.list.bak

Create a new source file:

# 填入上一节的任意一项可用源,之后执行Esc : 输入wq保存退出
vi /etc/apt/sources.list

File List

Update software sources:

apt update -y

update result

So far, the configuration is complete. The above is a summary and sharing of personal experience. If there are any mistakes, please correct me. If you find it useful, you can like it or bookmark it to encourage it~

Guess you like

Origin blog.csdn.net/qq_44281591/article/details/127195233