Debian 12/13 系统安装完成后的基础配置指南

作者:admin 日期:2023年03月20日
Linux 系统使用多年后,最终还是比较倾向 Debian 系列。
  • 系统稳定,生命周期长
  • 软件包管理成熟(apt)
  • 社区生态完善
  • 硬件兼容性持续提升
  • 适合服务器、虚拟化、数据库、应用服务等生产环境
但是 Debian 默认安装完成后,为了满足生产环境要求,还需要进行一些初始化配置。
图形安装到软件选择界面可以只要选择ssh 和 基本系统软件就够了。


一、配置服务器网络

1. 查看网卡名称

Debian 12/13 默认可能使用 systemd predictable network interface naming。

查看网卡:

ip a

例如:

ens192
enp1s0
eth0

根据实际网卡名称配置。


2. 配置静态 IP

传统 Debian 网络配置:

编辑:

nano /etc/network/interfaces

如果安装时候选择基础软件是有nano命令的,如果没,就用vi


示例:

auto ens192
iface ens192 inet static
    address 192.168.1.192
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 223.5.5.5 8.8.8.8

说明:

dns-nameservers 可以写在一起,223.5.5.5 是阿里的,8.8.8.8是谷歌的 ,这样配置哪都不堵。


3. 重启网络服务

systemctl restart networking

检查:

ip addr

ip route

ping www.baidu.com

注意:

Debian 12/13 如果安装时选择了 NetworkManager,建议使用:

nmcli


查看:

systemctl status NetworkManager

例如配置:

nmcli connection show

修改:

nmcli connection modify ens33 ipv4.addresses 192.168.1.192/24
nmcli connection modify ens33 ipv4.gateway 192.168.1.1
nmcli connection modify ens33 ipv4.method manual

nmcli connection up ens33


二、开启 SSH 远程管理

1. 安装 SSH 服务

部分最小化安装可能没有 ssh:

apt install openssh-server -y

查看状态:

systemctl status ssh

2. 允许 root 登录

Debian 默认:

  • root禁止密码SSH登录
  • 推荐普通用户sudo管理

如果生产环境需要root直接登录:

编辑:

vim /etc/ssh/sshd_config

修改:

PermitRootLogin yes

如果使用密码:

PasswordAuthentication yes

重启:

systemctl restart ssh

测试:

ssh root@服务器IP

安全建议

生产环境不建议长期开放:

PermitRootLogin yes

更推荐:

创建管理员:

adduser admin

加入sudo:

usermod -aG sudo admin




三、配置 Debian 软件源

1. 查看系统版本

cat /etc/debian_version

或者:

cat /etc/os-release

Debian版本:

版本代号Debian 12bookwormDebian 13trixie

Debian 12 软件源

编辑:

nano /etc/apt/sources.list

阿里云:

deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware

deb https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware

deb https://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware

deb https://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free non-free-firmware

Debian 13 软件源

阿里云:

deb https://mirrors.aliyun.com/debian/ trixie main contrib non-free non-free-firmware

deb https://mirrors.aliyun.com/debian/ trixie-updates main contrib non-free non-free-firmware

deb https://mirrors.aliyun.com/debian-security trixie-security main contrib non-free non-free-firmware

deb https://mirrors.aliyun.com/debian/ trixie-backports main contrib non-free non-free-firmware

清华源 Debian13

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-updates main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ trixie-backports main contrib non-free non-free-firmware


deb https://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware

更新:

apt update

升级:

apt upgrade -y

完整升级:

apt full-upgrade -y


四、设置服务器主机名

查看:

hostname

修改为 db-server01

hostnamectl set-hostname db-server01

修改hosts:

vim /etc/hosts

例如:

192.168.1.192 db-server01



五、生产服务器时间配置

建议完整执行:

1. 设置时区

timedatectl set-timezone Asia/Shanghai

2. 安装chrony

apt install chrony -y

3. 配置国内NTP源

编辑:

nano /etc/chrony/chrony.conf

修改:

pool ntp.aliyun.com iburst
pool ntp.tencent.com iburst
pool cn.pool.ntp.org iburst

例如:

server ntp.aliyun.com iburst
server ntp.tencent.com iburst

4. 重启chrony

systemctl restart chrony

5. 设置开机启动

systemctl enable chrony

6. 验证

chronyc sources

MS Name/IP address     Stratum Poll Reach LastRx Last sample

===============================================================================

^+ 203.107.6.88         2  6  17  40  -855us[-2831us] +/-  22ms

^+ 106.55.184.199        2  6  17  40 +1348us[ -628us] +/-  60ms

^* 111.230.189.174        2  6  17  39 +4084us[+2108us] +/-  41ms

^- time.cloudflare.com      3  6  27  37 +7519us[+7519us] +/- 130ms

^- 139.199.214.202        2  6  17  39 +3023us[+3023us] +/-  57ms

^- time.cloudflare.com      3  6  17  37  +13ms[ +13ms] +/- 126ms

date

Fri Jul 31 04:42:30 PM CST 2026



七、防火墙配置

Debian默认没有开启防火墙。

安装:

apt install ufw

开启:

ufw enable

允许SSH:

ufw allow 22/tcp

查看:

ufw status

生产环境建议:

只开放必要端口:

例如:

22 SSH
80 HTTP
443 HTTPS
5432 PostgreSQL
3306 MySQL
1433 SQLServer


← 上一篇:这些年我看过的电影[持续更新] 下一篇:Windows 激活 →