zfsjlll

zfsjlll

趁着年轻,好好犯病

Linux配置静态IP

back

系统:Debian11 bullseye


Debian 默认有三种配置网络的方法:

方法简介
/etc/network/interfaces 的 interfaces 配置文件进行基础或简单配置
NetworkManager笔记本电脑默认配置值(2004 年由红帽公司发起,其目标是让 Linux 用户能够更容易的处理现代的网络需求,特别是无线网络。)
systemd-networkd处理网络接口配置的守护进程

本文中我们使用 systemd-networkd 来进行配置。

NOTE: If you are doing this remotely, please ensure that you can get to the physical machine in order to fix things should something go wrong. You can't work remotely on a machine whose networking isn't.
有道翻译:
注意:如果您是远程执行此操作,请确保您可以访问物理机器,以便在出现问题时修复问题。你不能在没有网络的机器上远程工作。

  1. 如果当前已有网络使用 /etc/network 运行,重命名接口文件,这样激活 systemd-netwrkd 后就不会使用它。
    这里使用 mv 命令
sudo mv /etc/network/interfaces /etc/network/interfaces.save
  1. 在.etc/systemd/network 下定义接口(网卡)文件,后缀名为 *** .network*** ,VMware Debian11 默认接口名为 ens33, 于是新建 ens33.network 文件,然后进行如下配置:
sudo nano /etc/systemd/network/en*.network
[Match]
Name=en*(你的网卡名)

[Network]
Address=192.168.0.15/24
Gateway=192.168.0.1
  1. Ctrl+o 保存文件,Ctrl+x 退出
  2. 启动 systemd-networkd 服务使配置生效,并设置为开机启动:
sudo systemctl restart systemd-networkd
sudo systemctl enable systemd-networkd

参考材料:
配置网络
网卡名称
SystemdNetworkd

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。