下载Debian12
下载链接1(163镜像站):https://mirrors.163.com/debian-cd/12.9.0/amd64/iso-dvd/debian-12.9.0-amd64-DVD-1.iso
下载链接2(兰州大学开源社区镜像站):https://mirror.lzu.edu.cn/debian-cd/12.9.0/amd64/iso-dvd/debian-12.9.0-amd64-DVD-1.iso
虚拟机安装Debian12
创建新的虚拟机,选择典型配置
选择下载的镜像,没有对应的版本也没有关系,不影响安装过程
这里直接下一步就好了
开启虚拟机,回车进入图形界面安装
这些都是无关紧要的步骤,按照图片下一步就好
这里先不配置软件包管理器,如果配置需要等待网络下载,非常的慢
只选择SSH server
就够用了
安装GRUB引导器到驱动器上,否则不能启动系统
配置静态IP
首先要在虚拟机确定网关(gateway),子网掩码(netmask),打开虚拟机的虚拟网络编辑器
选中第三项并点击NAT设置
这个时候我们就获取到了子网IP,子网掩码,网关IP
子网ip:192.168.63.0 #如果最后一位是0的话是不能用的,要改成别的如100,最后一位不能是0、2、255其中一个
子网掩码:255.255.255.0
网关:192.168.63.2
回到Debian12系统中,以root身份登录后,输入命令查看网卡名称
ip a
可以看到一个叫做ens33的网卡的ip为192.168.63.132
到这一步,我们已经可以使用SSH工具和密码连接远程连接到Debian系统了,但是只能使用普通用户,也就是刚才创建的hello用户,不过这里操作还是使用了root用户
编辑网卡配置文件
vi /etc/network/interfaces
默认情况下的配置如图所示
按键盘上的a
键进入编辑模式,修改其中的内容,编辑完成后后按Esc
推出编辑,输入:wq
保存并退出
注意一下:IP地址最后一位如果是0的话我建议是把它改成别的,如果你要用0当最后一位的话,可能会出现上不了网的情况,这里我选择100
auto ens33
iface ens33 inet static
address 192.168.63.100
netmask 255.255.255.0
gateway 192.168.63.2
编辑后的网卡配置文件内容如下
最后重启网络服务
systemctl restart networking.service
这个时候你在输入命令ip a
就会发现ip已经变成了上面的192.168.63.100
开启root账户的密码登录
输入命令
vi /etc/ssh/sshd_config
修改下面的两行
#PermitRootLogin prohibit-password ----> PermitRootLogin yes
#PasswordAuthentication yes ----> PasswordAuthentication yes
重启ssh服务
service sshd restart
设置DNS
Debian12安装后默认没有/etc/resolv.conf 文件,使用下列命令创建
vi /etc/resolv.conf
添加以下内容
nameserver 114.114.114.114
nameserver 119.29.29.29
nameserver 8.8.8.8
nameserver 8.8.8.4
添加APT源
配置过程可参考清华大学开源软件镜像站
使用如下命令
vi /etc/apt/sources.list
在文件末尾添加如下内容(阿里云源)
deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware
deb-src 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-src https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free non-free-firmware
如果遇到无法拉取 https 源的情况,请先使用 http 源并安装:
apt install apt-transport-https ca-certificates
更新软件包
apt update
apt upgrade