Ubuntu2204初始化

配置允许root登录

Ubuntu安装后默认root不允许登录,需要使用普通用户登录后配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
## sudo 切换到root
xcjyc@ubuntu2204:~$ sudo -i
[sudo] password for xcjyc:
root@ubuntu2204:~#

## 设置root密码
root@ubuntu2204:~# passwd root
New password:
Retype new password:
passwd: password updated successfully

## 修改ssh配置,允许root ssh登录
root@ubuntu2204:~# vim /etc/ssh/sshd_config
#Port 22 ## 建议修改端口
PermitRootLogin yes
PasswordAuthentication yes
#UseDNS no ## 设置为NO,可加速登录
#GSSAPIAuthentication no ## 设置为NO,可加速登录

更改软件安装源

Ubuntu 默认使用的软件源位于国外,如果要获得更快的下载速度,我们可以通过更改软件源来解决这个问题。打开https://developer.aliyun.com/mirror/ubuntu ,根据ubuntu版本,复制相应的源配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
root@ubuntu2204:~# cp /etc/apt/sources.list /etc/apt/sources.list.bak

root@ubuntu2204:~# vim /etc/apt/sources.list
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

更新源列表,运行 “apt update”

==安装软件前,更新源后再安装!==

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
root@ubuntu2204:~# apt update
Hit:1 https://mirrors.aliyun.com/ubuntu jammy InRelease
Get:2 https://mirrors.aliyun.com/ubuntu jammy-security InRelease [110 kB]
Get:3 https://mirrors.aliyun.com/ubuntu jammy-updates InRelease [119 kB]
Hit:4 https://mirrors.aliyun.com/ubuntu jammy-backports InRelease
Get:5 https://mirrors.aliyun.com/ubuntu jammy-updates/restricted Sources [65.0 kB]
Get:6 https://mirrors.aliyun.com/ubuntu jammy-updates/multiverse Sources [19.0 kB]
Ign:7 https://mirrors.aliyun.com/ubuntu jammy-updates/main amd64 Packages
Get:8 https://mirrors.aliyun.com/ubuntu jammy-updates/restricted amd64 Packages [1754 kB]
Get:9 https://mirrors.aliyun.com/ubuntu jammy-updates/restricted Translation-en [295 kB]
Ign:10 https://mirrors.aliyun.com/ubuntu jammy-updates/universe amd64 Packages
Get:11 https://mirrors.aliyun.com/ubuntu jammy-updates/multiverse amd64 Packages [42.7 kB]
Get:12 https://mirrors.aliyun.com/ubuntu jammy-updates/multiverse Translation-en [10.4 kB]
Get:7 https://mirrors.aliyun.com/ubuntu jammy-updates/main amd64 Packages [1562 kB]
Get:10 https://mirrors.aliyun.com/ubuntu jammy-updates/universe amd64 Packages [1075 kB]
Fetched 5053 kB in 9s (561 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
52 packages can be upgraded. Run 'apt list --upgradable' to see them.

修改网卡名称为eth0

修改/etc/default/grub文件,在GRUB_CMDLINE_LINUX增加“net.ifnames=0”

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
28
29
30
31
32
33
34
35
36
root@ubuntu2204:~# vim /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="net.ifnames=0"

root@ubuntu2204:~# grub-mkconfig -o /boot/grub/grub.cfg
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-102-generic
Found initrd image: /boot/initrd.img-5.15.0-102-generic
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
done

root@ubuntu2204:~# reboot

root@ubuntu2204:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:fb:bc:2d brd ff:ff:ff:ff:ff:ff
altname enp2s1
altname ens33
inet 10.0.0.131/24 metric 100 brd 10.0.0.255 scope global dynamic eth0
valid_lft 1782sec preferred_lft 1782sec
inet6 fe80::20c:29ff:fefb:bc2d/64 scope link
valid_lft forever preferred_lft forever

配置IP地址

网上配置文件为YAML格式,存放在/etc/netplan/**.yaml文件中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@ubuntu2204:~# ls /etc/netplan/
00-installer-config.yaml

root@ubuntu2204:~# vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
dhcp4: false
addresses:
- 10.0.0.7/24
gateway4: 10.0.0.2
nameservers:
addresses:
- 10.0.0.2
- 223.5.5.5
version: 2

检查配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
##  DNS检查
root@ubuntu2204:~# resolvectl status
Global
Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub

Link 2 (eth0)
Current Scopes: DNS
Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 10.0.0.2
DNS Servers: 10.0.0.2 223.5.5.5

## 网关检查
root@ubuntu2204:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

若找不到ping命令,先安装net-toools,inetutils-ping工具包

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
28
29
30
31
root@ubuntu2204:~# apt update 

root@ubuntu2204:~# apt search net-tools
Sorting... Done
Full Text Search... Done
atm-tools/jammy 1:2.5.1-4build2 amd64
Base programs for ATM in Linux, the net-tools for ATM

ddnet-tools/jammy 15.9.1-1 amd64
Tools for DDNet

hobbit-plugins/jammy 20201127 all
plugins for the Xymon network monitor

iproute2/jammy,now 5.15.0-1ubuntu2 amd64 [installed,automatic]
networking and traffic control tools

net-tools/jammy,now 1.60+git20181103.0eebece-1ubuntu5 amd64 [installed]
NET-3 networking toolkit

root@ubuntu2204:~# apt search inetutils-ping
Sorting... Done
Full Text Search... Done
inetutils-ping/jammy-security,jammy-updates,now 2:2.2-2ubuntu0.1 amd64 [installed]
ICMP echo tool



root@ubuntu2204:~# ping www.baidu.com
PING www.a.shifen.com (183.2.172.42): 56 data bytes
64 bytes from 183.2.172.42: icmp_seq=0 ttl=128 time=57.860 ms

修改时区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 两种方法可修改时区
root@ubuntu2204:~# timedatectl set-timezone Asia/Shanghai

root@ubuntu2204:~# tzselect
在这里我们选择亚洲(Asia),确认之后选择中国(China),最后选择北京(Beijing),选择yes

root@ubuntu2204:~# timedatectl
Local time: Wed 2024-05-15 16:19:04 CST
Universal time: Wed 2024-05-15 08:19:04 UTC
RTC time: Wed 2024-05-15 08:19:04
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

Ubuntu2204初始化
https://www.xcjyc.top/2024/04/18/Ubuntu初始化/
作者
XCJYC
发布于
2024年4月18日
许可协议