一、修改更新源
✏️ Note
基于debian12操作
1.1 https源无法拉去解决方法
如果遇到无法拉取 https 源的情况,请先使用 http 源并安装:
sudo apt install apt-transport-https ca-certificates -y1.2 更新源
sudo nano /etc/apt/sources.list清华源
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware二、包安装
apt update
apt install vim wget curl tree tcpdump iotop ntpsec-ntpdate fping mtr iperf3 netcat-openbsd nmap socat httpie iproute2 ethtool nethogs iftop bmon tshark vnstat net-tools bash-completion -y
bash-completion #命令补全
### 基础诊断
```bash
# ping家族
ping、ping6
fping(批量ping)
# DNS相关
dig、nslookup
host
drill--
# 路由追踪
traceroute、traceroute6--
tracepath、tracepath6--
mtr(实时诊断)
# 端口和连接
netcat(nc)
nmap
telnet
socat(NC加强版)
# HTTP测试
curl
wget
httpie
# 网络统计
netstat(ss替代)--
iproute2(ip命令)
ifconfig(net-tools)--
ethtool
```
### 高级工具
```bash
# 带宽测试
iperf3
nethogs(按进程流量)
iftop(实时流量)
bmon
# 包分析
tcpdump
tshark(Wireshark命令行)
ngrep--
# 质量测试
---iperf3代替
qperf
netperf
pathchar
# 监控
vnstat(基于接口流量统计)
bwm-ng--
iptraf-ng--
```
## 3. Dockerfile 示例(基于Alpine)
```dockerfile
FROM alpine:latest
# 安装基础工具
RUN apk add --no-cache \
# 基础网络
iputils \
iproute2 \
net-tools \
# DNS工具
bind-tools \
# 高级诊断
mtr \
iperf3 \
tcpdump \
nmap \
netcat-openbsd \
# HTTP工具
curl \
wget \
# 监控工具
iftop \
nethogs \
bmon \
# 包管理
openssh-client三、账号设置
3.1 添加普通用户和设置密码
# 添加admin用户
useradd -m -s /bin/bash admin
# 设置admin用户密码
passwd admin3.2 添加sudo权限
# 方法一 (推荐)
usermod -aG sudo admin
# 方法二 (该方法sudo无需密码)
echo "admin ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers3.3 删除root密码
passwd -d root3.4 删除临时用户
userdel -r <用户名>四、主机名修改
修改为主机喜欢的或 特定编号的即可
五、SSH配置
cat <<EOF >> /etc/ssh/sshd_config
# 禁用了DNS反向解析
UseDNS no
# 记录SSH日志消息
SyslogFacility AUTHPRIV
# 允许root用户登入
PermitRootLogin yes
# 允许免密登入
PermitEmptyPasswords yes
EOF六、静态IP
# 1)编辑配置文件
sudo vim /etc/network/interfaces
# 2)追加以下内容
auto ens33
iface ens33 inet static
address 172.16.186.133
netmask 255.255.255.0
gateway 172.16.186.2
dns-nameservers 172.16.186.2
# 3)重启网络服务
sudo systemctl restart networking.service网卡配置
auto ens33
iface ens33 inet dhcp
#iface ens33 inet static
#address 172.16.186.133
#netmask 255.255.255.0
#gateway 172.16.186.2
#dns-nameservers 172.16.186.2
# 其他网卡
allow-hotplug ens6
iface ens6 inet dhcp七、其他
7.1 禁用IPV6
vim /etc/sysctl.conf
# 在Uncomment the next line to enable packet forwarding for IPv6前一行添加以下内容:
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1
net.ipv6.conf.eth0.disable_ipv6 = 1
# 注意将eth0替换为自己网卡的名称
sysctl -p7.2 修改网卡名称
# 1)编辑grub文件
vim /etc/default/grub
# 2)找到[GRUB_CMDLINE_LINUX=""]这一行修改为一下内容
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
# 3)更新grub
update-grub
7.3 虚拟机能telnet
vim /etc/default/grub
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8 earlyprintk=ttyS0,115200n8 consoleblank=0 noibrs iommu=pt"
# Debian/Ubuntu 系统
sudo update-grub
# Red Hat/CentOS 系统
sudo grub2-mkconfig -o /boot/grub2/grub.cfg7.4 支持老版本ssh
vim /etc/ssh/sshd_config
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa