zfsjlll

zfsjlll

趁着年轻,好好犯病

Configure Static IP in Linux

back

System: Debian11 bullseye


Debian has three methods for configuring networks by default:

MethodDescription
/etc/network/interfaces configuration fileBasic or simple configuration
NetworkManagerDefault configuration for laptops (initiated by Red Hat in 2004 with the goal of making it easier for Linux users to handle modern networking needs, especially wireless networks.)
systemd-networkdDaemon for handling network interface configuration

In this article, we will use systemd-networkd for configuration.

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. If there is already a network running using /etc/network, rename the interface file so that it is not used after activating systemd-networkd.
    Use the mv command here
sudo mv /etc/network/interfaces /etc/network/interfaces.save
  1. Define the interface (network card) file under /etc/systemd/network with the extension .network. The default interface name for VMware Debian11 is ens33, so create a new ens33.network file and configure it as follows:
sudo nano /etc/systemd/network/en*.network
[Match]
Name=en*(your interface name)

[Network]
Address=192.168.0.15/24
Gateway=192.168.0.1
  1. Save the file with Ctrl+o and exit with Ctrl+x.
  2. Start the systemd-networkd service to apply the configuration and set it to start on boot:
sudo systemctl restart systemd-networkd
sudo systemctl enable systemd-networkd

References:
Network Configuration
Interface Names
SystemdNetworkd

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.