How to set a fixed IP for SSH connection in Debain11

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

  1. edit ssh file
nano /etc/ssh/sshd_config
  1. found #PermitRootLogin, change the line toPermitRootLogin yes
    insert image description here

  2. Press ctrl+x, enter Yand press 回车to save

  3. 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.

  1. edit filenano /etc/network/interfaces

  2. 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

insert image description here

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.
  1. Press ctrl+x, enter Yand press 回车to save

  2. Restart the network:systemctl restart networking

Guess you like

Origin blog.csdn.net/the_liang/article/details/129777905