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命令了
相關文章
相關標籤/搜索