Linux ifconfig命令詳解 Linux ifconfig命令怎麼用

來源:互聯網
上載者:User

ifconfig可設定網路裝置的狀態,或是顯示目前的設定。

文法

ifconfig [網路裝置][down up -allmulti -arp -promisc][add<地址>][del<地址>]

[<hw<網路裝置類型><硬體地址>][io_addr<I/O地址>][irq<IRQ地址>][media<網路媒介類型>]

[mem_start<記憶體位址>][metric<數目>][mtu<位元組>][netmask<子網路遮罩>][tunnel<地址>]

[-broadcast<地址>][-pointopoint<地址>][IP地址]

參數說明:

  • add<地址> 設定網路裝置IPv6的IP地址。
  • del<地址> 刪除網路裝置IPv6的IP地址。
  • down 關閉指定的網路裝置。
  • <hw<網路裝置類型><硬體地址> 設定網路裝置的類型與硬體地址。
  • io_addr<I/O地址> 設定網路裝置的I/O地址。
  • irq<IRQ地址> 設定網路裝置的IRQ。
  • media<網路媒介類型> 設定網路裝置的媒介類型。
  • mem_start<記憶體位址> 設定網路裝置在主記憶體所佔用的起始地址。
  • metric<數目> 指定在計算資料包的轉送次數時,所要加上的數目。
  • mtu<位元組> 設定網路裝置的MTU。
  • netmask<子網路遮罩> 設定網路裝置的子網路遮罩。
  • tunnel<地址> 建立IPv4與IPv6之間的隧道通訊地址。
  • up 啟動指定的網路裝置。
  • -broadcast<地址> 將要送往指定地址的資料包當成廣播資料包來處理。
  • -pointopoint<地址> 與指定地址的網路裝置建立直接連線,此模式具有保密功能。
  • -promisc 關閉或啟動指定網路裝置的promiscuous模式。
  • [IP地址] 指定網路裝置的IP地址。
  • [網路裝置] 指定網路裝置的名稱。

執行個體

顯示網路裝置資訊

# ifconfig

eth0   Link encap:Ethernet HWaddr 00:50:56:0A:0B:0C

inet addr:192.168.0.3 Bcast:192.168.0.255 Mask:255.255.255.0

inet6 addr: fe80::250:56ff:fe0a:b0c/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

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

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

collisions:0 txqueuelen:1000

RX bytes:87101880 (83.0 MiB) TX bytes:41576123 (39.6 MiB)

Interrupt:185 Base address:0x2024

lo   Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

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

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

collisions:0 txqueuelen:0

RX bytes:2459063 (2.3 MiB) TX bytes:2459063 (2.3 MiB)

啟動關閉指定網卡

# ifconfig eth0 down

# ifconfig eth0 up

為網卡配置和刪除IPv6地址

# ifconfig eth0 add 33ffe:3240:800:1005::2/ 64 //為網卡誒之IPv6地址

# ifconfig eth0 del 33ffe:3240:800:1005::2/ 64 //為網卡刪除IPv6地址

用ifconfig修改MAC地址

# ifconfig eth0 down //關閉網卡

# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址

# ifconfig eth0 up //啟動網卡

# ifconfig eth1 hw ether 00:1D:1C:1D:1E //關閉網卡並修改MAC地址

# ifconfig eth1 up //啟動網卡

配置IP地址

# ifconfig eth0 192.168.1.56

//給eth0網卡配置IP地址

# ifconfig eth0 192.168.1.56 netmask 255.255.255.0

// 給eth0網卡配置IP地址,並加上子掩碼

# ifconfig eth0 192.168.1.56 netmask 255.255.255.0 broadcast 192.168.1.255

// 給eth0網卡配置IP地址,加上子掩碼,加上個廣播位址

啟用和關閉ARP協議

# ifconfig eth0 arp //開啟

# ifconfig eth0 -arp //關閉

設定傳輸單元最大值

# ifconfig eth0 mtu 1500

//設定能通過的最大資料包大小為 1500 bytes

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.