20180906 CentOS IP配置相关命令操做

自动获取IP命令: dhclient 
[root@localhost ~]# dhclient

查看ip地址信息: ip add/address
[root@localhost ~]# ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:7c:ee:a3 brd ff:ff:ff:ff:ff:ff  # 网卡信息
    inet 192.168.77.129/24 brd 192.168.77.255 scope global eno16777736 # IP地址信息
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe7c:eea3/64 scope link 
       valid_lft forever preferred_lft forever

网络配置文件路径: /etc/sysconfig/network-scripts/ifcfg-(网卡名),能够经过vi命令对其进行编辑
vi /etc/sysconfig/network-scripts/ifcfg-eno16777736

修改内容以下:

设置完成后,按esc键在输入:wq进行保存退出。
执行命令: systemctl restart network.service 重启网络服务  
重启后测试一下网络 ping www.baidu.com 
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (119.75.213.61) 56(84) bytes of data.
64 bytes from 127.0.0.1 (119.75.213.61): icmp_seq=1 ttl=128 time=9.74 ms
64 bytes from 127.0.0.1 (119.75.213.61): icmp_seq=2 ttl=128 time=9.53 ms
64 bytes from 127.0.0.1 (119.75.213.61): icmp_seq=3 ttl=128 time=10.4 ms
64 bytes from 127.0.0.1 (119.75.213.61): icmp_seq=4 ttl=128 time=10.2 ms
网络正常。

若是DNS填写错误致使网卡不正确,能够经过命令route -n 来查看网关信息
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.77.2    0.0.0.0         UG    1024   0        0 eno16777736
192.168.77.0    0.0.0.0         255.255.255.0   U     0      0        0 eno16777736
这是正确状态。

查询网络情况时,除了使用ip add以外,还能够使用ifconfig,但若是提示找不到该命令时,能够经过yum进行安装对应的工具库。git

[root@localhost ~]# yum install -y net-tools
已加载插件:fastestmirror
http://mirrors.shu.edu.cn/centos/7.5.1804/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect 
正在尝试其它镜像。
http://mirrors.nwsuaf.edu.cn/centos/7.5.1804/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed conne
正在尝试其它镜像。
base                                                                                                         
extras                                                                                                       
updates                                                                                                      
(1/4): base/7/x86_64/group_gz                                                                                
(2/4): extras/7/x86_64/primary_db                                                                            
(3/4): updates/7/x86_64/primary_db                                                                           
(4/4): base/7/x86_64/primary_db                                                                              
Determining fastest mirrors
 * base: mirror.bit.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 net-tools.x86_64.0.2.0-0.22.20131004git.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=============================================================================================================
 Package                                     架构                                     版本                   
=============================================================================================================
正在安装:
 net-tools                                   x86_64                                   2.0-0.22.20131004git.el

事务概要
=============================================================================================================
安装  1 软件包

总下载量:305 k
安装大小:917 k
Downloading packages:
警告:/var/cache/yum/x86_64/7/base/packages/net-tools-2.0-0.22.20131004git.el7.x86_64.rpm: 头V3 RSA/SHA256 Si
net-tools-2.0-0.22.20131004git.el7.x86_64.rpm 的公钥还没有安装
net-tools-2.0-0.22.20131004git.el7.x86_64.rpm                                                                
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
 用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 软件包     : centos-release-7-0.1406.el7.centos.2.3.x86_64 (@anaconda)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : net-tools-2.0-0.22.20131004git.el7.x86_64                                              
  验证中      : net-tools-2.0-0.22.20131004git.el7.x86_64                                          
已安装:
  net-tools.x86_64 0:2.0-0.22.20131004git.el7              

完毕!

安装完毕后,就能够使用ifconfig命令了
相关文章
相关标签/搜索