Configure static ip address in Linux

When we use Xshell in windows to connect to the VMware virtual machine, often because the ip address always changes dynamically, we need to re-enter the ip add command in centos to obtain the ip address when we restart the computer, and then use Xshell to create a session and The virtual machine is connected, which will add unnecessary cumbersome operations to us.

Therefore, we should find a way to stop the ip address and prevent it from changing dynamically. At this time, we need to configure a static ip address. The specific operation is as follows:

1 Use the ip add command to view your ip address

2 Use the ip route command to view the default gateway address

3 Enter the configuration directory of the network card file

Use the cd /etc/sysconfig/network-scripts command to enter the configuration directory of the network card file

cd /etc/sysconfig/network-scripts

Then use vim ifcfg-ens33 to enter the file and edit it. The file name is the abbreviation of interface (if) and configuration config (cfg)

vim ifcfg-ens33

After entering, the following configurations can be performed

BOOTPROTO="none"      #none/static 表示静态配置ip地址  dhcp  表示动态获得ip地址
NAME="ens33"         #网络连接的名字
DEVICE="ens33"       #设备名字
ONBOOT="yes"         #开机激活网卡  yes激活  no 禁用
IPADDR=192.168.*.*    #具体的ip地址
PREFIX=24             #子网掩码
NETMASK=255.255.255.0  #子网掩码
GATEWAY=192.168.*.*    #默认网关
DNS1=114.114.114.114   #首选DNS服务器
DNS2=192.168.1.1     #备用DNS服务器

4 Refresh network services

service network restart

5 Test whether you can access the Internet

After performing the above operations, the static ip address can be successfully configured

6 Benefits of a Static IP Address

1. Stability: The static IP address is fixed and will not change with changes in the network environment, which makes the network connection more stable and reliable.

2. Security: Static IP addresses can better control network access, such as restricting access to specific IP addresses.

3. Ease of management: Static IP addresses can be managed more easily because administrators can easily identify and track network devices.

4. Compatibility: Static IP address ensures compatibility with other network devices, such as routers, switches, etc.

Guess you like

Origin blog.csdn.net/m0_53891399/article/details/129624191