The methods and steps for configuring IP addresses under Linux are super detailed! ! !

有很多萌新刚开始充满好奇的开始学习Linux操作系统 第一步就会卡在ip地址的配置上 我当时也是 所以我打算出这一篇关于ip地址配置的所有步骤 其中也会写下我遇到的问题和踩过的坑。
Insert image description here

1. Network connection

First of all, you must be clear about the network connection configuration including** IP address, subnet mask, gateway **, etc.
These are the most basic requirements for configuring a host IP address.

1. Define the network connection information

  • Let’s first define some information about our network connection
  1. First, the IP address of Linux is 192.168.123.101

  2. The second gateway is 192.168.123.2

  3. DNS is 114.114.114.114

2. Configuration of network card information

那么知道了ip地址是什么 该在哪里进行配置呢?
Configuring the IP address is also called configuring the network card
. So in Centos7网卡的默认位置在/etc/sysconfig/network-scripts/ifcfg-ens33 下

  1. Let’s go into this configuration file to check
vi /etc/sysconfig/network-scripts/ifcfg-ens33 

Insert image description here

(1) This is the most basic parameter. There are two important knowledge points in this network card.

(1)BOOTPROTO=dhcp //启动网卡的方式 dhcp代表自动获取 但是我们配置ip时通常修改为static(静态)或者none
(2)ONBOOT=no //是否启动网卡 默认为no 我们要改成yes 即启动的意思

(2) 记住我们需要添加的三个内容

IPADDR=192.168.123.101 //指定网卡的ip地址
NETMASK=255.255.255.0   //指定网卡的子网掩码
GATEWAY=192.168.123.2   //指定网卡的网关
DNS1=114.114.114.114 //可选 可以不添加 但是ping外网一定要添加

(3) The picture after configuration is as followsInsert image description here

(4) After configuration, we press ESC first and then ** 同时按住shift和;(;在L的右边)**

Insert image description here

(5) Then this small message will appear:我们输入wq后按回车!
Insert image description here

(6) Then let’s try restarting the network card! ! !

systemctl restart network //这个就是重启网卡的命令

Insert image description here
Success! ! ! No error occurred! ! !
When successful, we should check the ip address. Use the following parameters to check the ip address.

ip a //查看网卡信息

Insert image description here

Doesn't it feel a bit messy?只需要看画了红圈的地方
It's okay. Can we? 看到192.168.123.101/24Yes , this is the IP address we just configured.

3. Network debugging and expansion

When we configure the IP address for the first time, we may get some. 小小的成就感Me too这也是我们的一个小小的里程碑 !

But we still need to 面临一些问题 configure the IP address so that some of the services we configure in Linux can be used on other clients in the future.

So first we need to do ** 让他们互相建立信息的连接吧** At this time we need to go to our own computer打开cmd使用ping命令来尝试建立信息的连接了

1. Ping command test

  1. back to our computer按住win和R 输入cmd

image.png

  1. After entering like this we useping命令进行测试

  2. The ping command is a tool used to test whether the network between two hosts in the network is smooth and the network quality is

ping 192.168.123.101

2. We may encounter the following two situations

(1) Display the return time of the message

image.png

首先就是像这样的 这就说明你和虚拟机已经建立了连接 如果你是这样 那么后面的内容你就可以掠过了

There is another situation

(2) TLL transmission process expires

image.png

If you are this kind of person, then just follow me.

1.首先如果遇到这个情况 那么有可能是你在VM的虚拟网络编辑器中的ip设置有问题
2.也有可能是你的网卡问日

1. It may be a problem with your virtual network editor
解决方法如下:

(1)打开vm 找到左上角的编辑按钮 

![image.png](https://img-blog.csdnimg.cn/img_convert/9b0d4bc4f813c44ce4b939c9b3c8562f.png)

(2) Click on the virtual network editor and then click on nat

image.png

(3) The modified picture is as follows

image.png

(4) After entering, we change the gateway to 192.168.123.2

image.png

(5) After clicking OK, let’s try restarting the network card.

(6)

image.png

(7) Restart the network card

systemctl restart network

(8) Enter cmd again and use the ping command to test

image.png

You can see that the connection has been established at this time

But if you still can't establish it, it may be a problem with the network connection mode.

2. Network connection mode problem

(1) Enter VM and click on the virtual machine

image.png

(2) Then find Settings at the bottom of the tab and click

image.png

#4. Summary
There are many reasons for network failures. These are just the two most common ones. Many, many strange problems will occur when we configure them.但是请大家不要灰心 积极百度 也可以私信我

This article almost ends here. Thank you all! ! !

Insert image description here

Guess you like

Origin blog.csdn.net/2201_75288693/article/details/133097221