分类 Linux 下的文章
firewall开启关闭端口
firewalld 是 Linux 系统中一款动态防火墙管理工具,替代了传统的 iptables 静态配置方式,支持运行时配置与永久配置分离、区域(Zone)隔离、富规则(Rich Rule)等高级特性,广泛应用于 CentOS、RHEL、Fedora 等发行版。
系统资源下载(ISO镜像、更新源)
Ubuntu
源地址查看:
官方(较慢)
http://www.ubuntu.org.cn/download
https://www.ubuntukylin.com/downloads/index-cn.html华为
https://mirrors.huaweicloud.com/home
阿里
https://developer.aliyun.com/mirror/ubuntu/?spm=a2c6h.25603864.0.0.5f0d28b9BeBlwE
清华
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
网易
http://mirrors.163.com/.help/ubuntu.html
Ubuntu 20.04 设置静态IP

本文为Ubuntu 20.04的静态IP配置步骤
参考链接
查询当前获取的IP信息
ifconfig
#若命令执行失败,则需安装net-tools
apt install net-tools
安装速度慢可更新为国内源(参考链接)
(开始被随机分配的ip为 10.10.2.36 ,我此处直接将主机获取的IP设置为静态。)
第一步:备份
cp /etc/netplan/01-network-manager-all.yaml /home/zl/
注:Ubuntu 20.04的网络配置文件位于/etc/netplan目录下的01-network-manager-all.yaml文件中;
第二步:编辑文件
nano /etc/netplan/01-network-manager-all.yaml
完成后按 ctrl+x 退出,按 y 保存,回车(或ctrl+o,回车保存,再ctrl+x退出);
也可使用vi /etc/netplan/01-network-manager-all.yaml或vim /etc/netplan/01-network-manager-all.yaml编辑器(vim需另外安装 apt-get install vim)。
cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.28.231/24]
optional: true
gateway4: 192.168.28.1
nameservers:
addresses: [192.168.28.1]
version: 2
第三步:使配置生效
netplan apply
可在控制台ping 10.10.2.1 (网关)检查是否配置成功(也可ping www.baidu.com外网测试);
若使用xshell远程修改将会卡顿一下,重新连接后说明设置成功;
root@zl-desktop:/etc/netplan# ifconfig
enp1s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.10.2.36 netmask 255.255.0.0 broadcast 10.10.255.255
inet6 fe80::5728:2cb6:cb94:2dff prefixlen 64 scopeid 0x20<link>
ether 00:0a:eb:97:41:23 txqueuelen 1000 (以太网)
RX packets 40927 bytes 33368325 (33.3 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 22185 bytes 1458899 (1.4 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp2s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 00:e0:a0:13:6e:8f txqueuelen 1000 (以太网)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (本地环回)
RX packets 528 bytes 62177 (62.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 528 bytes 62177 (62.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@zl-desktop:/etc/netplan#
root@zl-desktop:/etc/netplan# nano 01-network-manager-all.yaml
root@zl-desktop:/etc/netplan#
root@zl-desktop:/etc/netplan# netplan apply
root@zl-desktop:/etc/netplan#
root@zl-desktop:/etc/netplan# ifconfig
enp1s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.10.2.36 netmask 255.255.255.0 broadcast 10.10.2.255
inet6 fe80::20a:ebff:fe97:4123 prefixlen 64 scopeid 0x20<link>
ether 00:0a:eb:97:41:23 txqueuelen 1000 (以太网)
RX packets 41765 bytes 33438435 (33.4 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 22843 bytes 1537103 (1.5 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp2s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 00:e0:a0:13:6e:8f txqueuelen 1000 (以太网)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (本地环回)
RX packets 799 bytes 88147 (88.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 799 bytes 88147 (88.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@zl-desktop:/etc/netplan#
root@zl-desktop:/etc/netplan# ping 10.10.2.1
PING 10.10.2.1 (10.10.2.1) 56(84) bytes of data.
64 字节,来自 10.10.2.1: icmp_seq=1 ttl=64 时间=0.793 毫秒
64 字节,来自 10.10.2.1: icmp_seq=2 ttl=64 时间=1.05 毫秒
64 字节,来自 10.10.2.1: icmp_seq=3 ttl=64 时间=0.968 毫秒
64 字节,来自 10.10.2.1: icmp_seq=4 ttl=64 时间=0.960 毫秒
64 字节,来自 10.10.2.1: icmp_seq=5 ttl=64 时间=0.977 毫秒
^C
--- 10.10.2.1 ping 统计 ---
已发送 5 个包, 已接收 5 个包, 0% 包丢失, 耗时 4028 毫秒
rtt min/avg/max/mdev = 0.793/0.950/1.052/0.085 ms
root@zl-desktop:/etc/netplan# ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 字节,来自 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=55 时间=38.5 毫秒
64 字节,来自 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=55 时间=38.3 毫秒
64 字节,来自 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=55 时间=37.5 毫秒
64 字节,来自 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=55 时间=38.1 毫秒
64 字节,来自 14.215.177.38 (14.215.177.38): icmp_seq=5 ttl=55 时间=38.2 毫秒
64 字节,来自 14.215.177.38 (14.215.177.38): icmp_seq=6 ttl=55 时间=38.4 毫秒
^C
--- www.a.shifen.com ping 统计 ---
已发送 6 个包, 已接收 6 个包, 0% 包丢失, 耗时 5006 毫秒
rtt min/avg/max/mdev = 37.518/38.174/38.460/0.316 ms
root@zl-desktop:/etc/netplan#
Ubuntu 更换国内源的方法
Ubuntu 更换国内源
查看系统版本
lsb_release -c
> Codename: focal #focal 说明是ubuntu20.04
ubuntu版本名与系统名对应关系,使用错误的版本源会导致依赖缺失和版本不对。
系统名 版本名
ubuntu20.04 focal
ubuntu18.04 bionic
ubuntu16.04 xenial
ubuntu14.04 trusty
首先备份原来的源
进入root用户
su
mv /etc/apt/sources.list /etc/apt/sources.list.bak
或 cp /etc/apt/sources.list /etc/apt/sources.list.bak
再输入以下命令打开sources.list配置文件更换源,以Ubuntu20.04为例。
sudo vim /etc/apt/sources.list
#配置内容如下-阿里源 Ubuntu20.04
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
#更新源
sudo apt-get update
再重新下载安装速度就很快啦。
ubuntu默认的下载源是国外地址,国内下载非常慢。
ubuntu下载源定义在 /etc/apt/sources.list 文件中,通过将下载源替换为阿里源,随后运行sudo apt-get update重新加载下载源,之后下载都默认从阿里云下载了,速度就非常快。