How to set a fixed IP for SSH connection in Debain11
Set up SSH remote connection
Here is mainly to set up SSH connection for root account
- edit ssh file
nano /etc/ssh/sshd_config
-
found
#PermitRootLogin
, change the line toPermitRootLogin yes
-
Press
ctrl+x
, enterY
and press回车
to save -
Restart ssh: systemctl restart sshd
At this time, you can connect to it through tools such as xshell.
Fixed IP
The newly installed Debain system has a dynamic IP. If you set up a remote connection, you must set a static IP to prevent the connection from being lost due to IP changes.
-
edit file
nano /etc/network/interfaces
-
Add a few lines
auto ens32
iface ens32 inet static #这行是修改
address 192.168.114.115
gateway 192.168.114.2
netmask 255.255.255.0
Let me explain here, the above configuration is the configuration of my local machine, the specific IP and gateway are mainly based on your actual situation.
- source /etc/network/interfaces.d/* means to include all files located in the /etc/network/interfaces.d/ directory, which are usually used to define additional network interfaces.
- auto lo means enable the loopback network interface.
- iface lo inet loopback means to set the IP address of the loopback network interface to the local address 127.0.0.1.
- auto ens32 means enable network interface ens32.
- allow-hotplug ens32 indicates that the interface is automatically loaded when the network card interface is plugged into the computer.
- iface ens32 inet static means to set the configuration mode of the network interface ens32 to a static IP address.
- address 192.168.114.115 means to set the IP address of network interface ens32 to 192.168.114.115.
- gateway 192.168.114.2 means to set the gateway to 192.168.114.2.
- netmask 255.255.255.0 means to set the subnet mask to 255.255.255.0.
-
Press
ctrl+x
, enterY
and press回车
to save -
Restart the network:
systemctl restart networking