首頁 > 軟體

CentOS7最小化安裝以後沒有ifconfig這個命令的解決方案

2020-06-16 17:45:28

前幾天我最小化安裝了一下CentOS7,進入系統發現沒有ifconfig這個網路設定工作,又想急著上網,那怎麼辦呀。下面是我給出的解決方法:

1、用光碟機設定yum源,安裝net-tools這個軟體包(或者用rpm這個命令)。
    1.1、把CentOS預設的yum源除(CentOS-Media.repo)都移動到一個指定的目錄,我是在yum源組態檔存放目中建了一個叫repo的子目錄,以下是具體操作:
[root@bogon ~]# cd /etc/yum.repos.d/   
    [root@bogon yum.repos.d]# ls
    CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentO    S-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo
    [root@bogon yum.repos.d]# mkdir repo
    [root@bogon yum.repos.d]# ls
    CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
    CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  repo
    [root@bogon yum.repos.d]# mv *.repo repo/
    [root@bogon yum.repos.d]# ls
    repo
    [root@bogon yum.repos.d]# cd repo/
    [root@bogon repo]# ls
    CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentO    S-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo
    [root@bogon repo]# mv CentOS-Media.repo ../
    [root@bogon repo]# ls
    CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentO    S-Sources.repo  CentOS-Vault.repo
    [root@bogon repo]# cd ..
    [root@bogon yum.repos.d]# ls
    CentOS-Media.repo  repo


      1.2、掛載光碟機設定yum源的具體操作步驟:

[root@bogon yum.repos.d]# mount /dev/sr0 /media/   
    mount: /dev/sr0 is write-protected, mounting read-only
    #以上是掛載光碟機的命令和操作步驟
     
    [root@bogon yum.repos.d]# cat CentOS-Media.repo 
    [c7-media]
    name=CentOS-$releasever - Media
    baseurl=file:///media/
    gpgcheck=1
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 
    #以上光碟機yum源的設定文件
     
    [root@bogon yum.repos.d]# yum list | wc -l
    3776
    #用yum list檢視測試yum源是否存在問題

    1.3、用yum安裝net-tools工具包
[root@bogon yum.repos.d]# yum install net-tools -y   
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
    Resolving Dependencies
    --> Running transaction check
    ---> Package net-tools.x86_64 0:2.0-0.17.20131004git.el7 will be installed
    --> Finished Dependency Resolution
    …………
    Running transaction
      Installing : net-tools-2.0-0.17.20131004git.el7.x86_64                                                                                  1/1
      Verifying  : net-tools-2.0-0.17.20131004git.el7.x86_64                                                                                  1/1
    Installed:
      net-tools.x86_64 0:2.0-0.17.20131004git.el7                                                                                                 
    Complete!

    1.4、測試ifconfig命令 
[root@bogon yum.repos.d]# ifconfig
    eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.131  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::20c:29ff:fe2d:c130  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:2d:c1:30  txqueuelen 1000  (Ethernet)
            RX packets 53366  bytes 3890372 (3.7 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 47832  bytes 22949340 (21.8 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
     
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 0  (Local Loopback)
            RX packets 58  bytes 5088 (4.9 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 58  bytes 5088 (4.9 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

2、在linux中除了ifconfig這個命令可以設定IP地址之外還有一個命令就是ip了(本人用的是這種方法)。
[root@bogon yum.repos.d]# ip addr l eno16777736
    2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 00:0c:29:2d:c1:30 brd ff:ff:ff:ff:ff:ff
        inet 192.168.1.131/24 brd 192.168.1.255 scope global eno16777736
          valid_lft forever preferred_lft forever
        inet6 fe80::20c:29ff:fe2d:c130/64 scope link 
          valid_lft forever preferred_lft forever
    [root@bogon yum.repos.d]# ip addr add 192.168.1.131/24 dev eno16777736

ip這個命令和博大精深不是一兩句話就可以說明的,在以後網路學習的時候我會給大家進行詳細認真的講解,再給大家提一下關於網絡卡,在CentOS7以後預設的網絡卡型別識別符號為eno16777736,在以前的系統為ethN。

本文永久更新連結地址http://www.linuxidc.com/Linux/2016-03/129302.htm


IT145.com E-mail:sddin#qq.com