Linux配置静态IP

系统: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命令
1sudo mv /etc/network/interfaces /etc/network/interfaces.save
  1. 在.etc/systemd/network下定义接口(网卡)文件,后缀名为*** .network*** ,VMware Debian11默认接口名为ens33,于是新建ens33.network文件,然后进行如下配置:
1sudo nano /etc/systemd/network/en*.network
1[Match]
2Name=en*(你的网卡名)
3
4[Network]
5Address=192.168.0.15/24
6Gateway=192.168.0.1
  1. Ctrl+o保存文件,Ctrl+x退出
  2. 启动 systemd-networkd 服务使配置生效,并设置为开机启动:
1sudo systemctl restart systemd-networkd
2sudo systemctl enable systemd-networkd

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

1

    评论
    0 评论
avatar

取消