在Linux中可以使用ifconfig命令查询ip,如下图所示:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2MjI1MzYyNC05NjEwMzYxMS5wbmc=.png)
这时你会发现会提示command not found,说明安装的CentOS是简易版本的,其中一些命名没有,需要我们手动进行安装。安装步骤如下:
1、使用ip addr查询本机的网卡
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2MjczMTg5OC0yMDczNzgwOTQyLnBuZw==.png)
这时会发现有两个网卡,第一个表示本机的回环地址,即:127.0.0.1。
2、vi /etc/sysconfig/network-scripts/ifcfg-xx
其中xx表示本机的网络。
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2MzQwMjYwNy0xOTk0OTkzNDU1LnBuZw==.png)
输入命令以后直接按回车,打开文件:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2MzYxMDg0MC0yMzk3ODI0MTMucG5n.png)
修改ONBOOT的值。按住键盘的方向键可以上下左右跳到光标的顺序。将光标移动到ONBOOT,并按一次键盘上面的“i”,表示进入编辑模式:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2Mzk1NzA5OS03MTU1ODI3NjUucG5n.png)
将ONBOOT的值改为YES:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2NDEwNDkxMS0xMzY0MTkwNDU4LnBuZw==.png)
先按一次键盘上面的退出键(Esc),在输出键盘上面的冒号“:”,然后输入wq。w:write表示写。q:quit表示退出。
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2NDQxNzE4NS0xODI5ODQyMTEyLnBuZw==.png)
这是按回车键,将回到原来的界面,这是表示文件已经写好了:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2NDU0ODkzMS0xOTEwNjIwNjY4LnBuZw==.png)
因为刚才修改了文件,这时先重启网络服务,使用service network restart命令:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2NDk0MjYzNS02MDU1MDUzOTkucG5n.png)
出现下面的截图所示的界面,表示重启成功:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2NTE0NDYzMy0yMDM1MjgzMjcucG5n.png)
这时在使用if addr命令查看IP:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2NTI0MzIzMi00Njc5ODQyODkucG5n.png)
这时你会发现多了192.168.142.128这个地址。
3、安装网络工具
使用命令:yum install net-tools。安装这个命令是为了可以使用ifconfig命令:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2NTYwMjM3Ny03Mjk0OTIzNDYucG5n.png)
在安装的过程中,会要求输入yes或者no,这时输入y即可:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2NTc1MjQ4MC0xNTg5ODE5MTAzLnBuZw==.png)
出现下图所示的界面,表示安装成功:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA2NTg0OTcwMy00MDMzNjY2MjEucG5n.png)
这时在使用ifconfig命令:
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWFnZXMyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTAzMzczOC8yMDE4MDcvMTAzMzczOC0yMDE4MDcxNjA3MDE0MTI2Mi0xNjgwODM3MDcucG5n.png)
这时ifconfig命令就可以使用了。
|