Linux作業系統Ifconfig命令詳細解析

來源:互聯網
上載者:User

   無論是Linux 自動安裝還是我們手工安裝,Linux 都會向你詢問有關網路的問題並配置相關的軟體。這個用於配置網卡的基本命令就是ifconfig。

  在執行ifconfig 命令後,系統將在核心表中設定必要的參數,這樣Linux 就知道如何與網路上的網卡通訊。ifconfig 命令有以下兩種格式:

  ※ifconfig [interface]

  ※ifconfig interface [aftype] option | address …

  ifconfig 的第一種格式(或使用不帶任何參數的ifconfig 命令)可以用來查看當前系統的網路設定情況。

  在剛剛安裝完系統之後,實際上是在沒有網卡或者網路連接的情況下使用Linux,但通過ifconfig 可以使用迴繞方式工作,使電腦認為自己工作在網路上。

  現在我們運行一下ifconfig 命令,不帶參數的ifconfig 命令可以顯示當前啟動的網路介面,其輸出結果為:

  [root@machine1 /sbin]#ifconfig

  eth0 Link encap:Ethernet Hwaddr 52:54:AB:DD:6F:61

  inet addr:210.34.6.89 Bcast:210.34.6.127 Mask:255.255.255.128

  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

  RX packets:46299 errors:0 dropped:0 overruns:0 frame:189

  TX packets:3057 errors:0 dropped:0 overruns:0 carrier:0

  collisions:0 txqueuelen:100

  Interrupt:5 Base address:0xece0

  lo Link encap:Local Loopback

  inet addr:127.0.0.1 Mask:255.0.0.0

  UP LOOPBACK RUNNING MTU:3924 Metric:1

  RX packets:44 errors:0 dropped:0 overruns:0 frame:0

  TX packets:44 errors:0 dropped:0 overruns:0 carrier:0

  collisions:0 txqueuelen:0

  其中以eth0 為首的部分是原生乙太網路卡配置參數,這裡顯示了網卡在下的裝置名稱/dev/eth0 和硬體的MAC 地址52:54:AB:DD:6F:61,MAC 位址是生產廠家定的,每個網卡擁有的唯一地址。

  不過我們可以手工改動網卡的MAC 位址,只要我們在/etc/rc.d/init.d/中的network 中加入:

  ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx

  然後重啟,此時再用ifconfig 命令查看一下,我們就會發現網卡的MAC 位址已經變成xx:xx:xx:xx:xx:xx了。

  後繼 常用網卡ip設定方法:

  直接通過setup 進行設定。

  配置多個網卡 ifconfig -a 查看網路裝置 eth0 / eth1 / lo (迴路)。

  ifconfig eth1 //裝置1

  ifconfig eth1 192.168.1.10 netmask 255.255.255.0 //設定網卡子網及ip

  man ifconfig

  ifconfig --help(T002)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.