Debian 命令行配置网络并切国内源

背景

因为debian11 连网安装非常的久,我又不太清楚在安装程序中切换国内的源。于是我就断网安装。安装完了默认是没有网的,于是就要命令中配置网络了。

配置

一、对于有线网络,如果默认没有安装图形界面,进入了 multi-user.target中时,是没有使用NetworkManager管理网络的,此时需要手动配置才能上网
首先得到网卡名称:ip addr or ls /sys/class/net/,以下假设网卡名为eth0,实际中应替换为自己实际的名称。

设置文件为:/etc/network/interfaces
使用DHCP方式,在文件底部添加:

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

手动设置IP上网,在文件底部添加:

auto eth0
iface eth0 inet static
    address 192.168.0.7
    netmask 255.255.255.0
    gateway 192.168.0.254

重启网络服务sudo systemctl restart networking.service
详细的设置方法可以使用man interfaces得到
也可以参考这里:https://wiki.debian.org/NetworkConfiguration

国内源

摘自:
https://mirrors.ustc.edu.cn/help/debian.html

使用说明
警告

操作前请做好相应备份

一般情况下,将 /etc/apt/sources.list 文件中 Debian 默认的源地址 http://deb.debian.org/ 替换为 http://mirrors.ustc.edu.cn 即可。

可以使用如下命令:

sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

当然也可以直接编辑 /etc/apt/sources.list 文件(需要使用 sudo)。以下是 Debian Stable 参考配置内容:

deb http://mirrors.ustc.edu.cn/debian stable main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable main contrib non-free
deb http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free

# deb http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free

同时你也可能需要更改 Debian Security 源,请参考 Debian Security 源使用帮助

更改完 sources.list 文件后请运行 sudo apt-get update 更新索引以生效。

参考

https://www.cnblogs.com/lvchaoshun/p/10676211.html

猜你喜欢

转载自blog.csdn.net/lxyoucan/article/details/128647965