System: Debian11 bullseye
Debian has three methods for configuring networks by default:
Method | Description |
---|---|
/etc/network/interfaces configuration file | Basic or simple configuration |
NetworkManager | Default 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-networkd | Daemon 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.
有道翻译:
注意:如果您是远程执行此操作,请确保您可以访问物理机器,以便在出现问题时修复问题。你不能在没有网络的机器上远程工作。
- 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
- 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
- Save the file with Ctrl+o and exit with Ctrl+x.
- 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