linux 命令——52 ifconfig(轉)

來源:互聯網
上載者:User

標籤:

  許多windows非常熟悉ipconfig命令列工具,它被用來擷取網路介面配置資訊並對此進行修改。Linux系統擁有一個類似的工具,也就是ifconfig(interfaces config)。通常需要以root身份登入或使用sudo以便在Linux機器上使用ifconfig工具。依賴於ifconfig命令中使用一些選項屬性,ifconfig工具不僅可以被用來簡單地擷取網路介面配置資訊,還可以修改這些配置。

1.命令格式:

  ifconfig [網路裝置] [參數]

2.命令功能:

  ifconfig 命令用來查看和配置網路裝置。當網路環境發生改變時可通過此命令對網路進行相應的配置。

3.命令參數:

up 啟動指定網路裝置/網卡。

down 關閉指定網路裝置/網卡。該參數可以有效地阻止通過指定介面的IP資訊流,如果想永久地關閉一個介面,我們還需要從核心路由表中將該介面的路由資訊全部刪除。

arp 設定指定網卡是否支援ARP協議。

-promisc 設定是否支援網卡的promiscuous模式,如果選擇此參數,網卡將接收網路中發給它所有的資料包

-allmulti 設定是否支援多播模式,如果選擇此參數,網卡將接收網路中所有的多播資料包

-a 顯示全部介面資訊

-s 顯示摘要資訊(類似於 netstat -i)

add 給指定網卡配置IPv6地址

del 刪除指定網卡的IPv6地址

<硬體地址> 配置網卡最大的傳輸單元

mtu<位元組數> 設定網卡的傳輸單元最大值 (bytes)

netmask<子網路遮罩> 設定網卡的子網路遮罩。掩碼可以是有首碼0x的32位十六進位數,也可以是用點分開的4個十進位數。如果不打算將網路分成子網,可以不管這一選項;如果要使用子網,那麼請記住,網路中每一個系統必須有相同子網路遮罩。

tunel 建立隧道

dstaddr 設定一個遠端地址,建立點對點通訊

-broadcast<地址> 為指定網卡設定廣播協議

-pointtopoint<地址> 為網卡設定點對點通訊協議

multicast 為網卡設定組播標誌

address 為網卡設定IPv4地址

txqueuelen<長度> 為網卡設定傳輸列隊的長度

4.使用執行個體:

執行個體1:顯示網路裝置資訊(啟用狀態的)

命令:

ifconfig

輸出:

 [[email protected] ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:50:56:BF:26:20  
          inet addr:192.168.120.204  Bcast:192.168.120.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0
          TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:596390239 (568.7 MiB)  TX bytes:2886956 (2.7 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:68 errors:0 dropped:0 overruns:0 frame:0
          TX packets:68 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2856 (2.7 KiB)  TX bytes:2856 (2.7 KiB) 

 

說明:

eth0 表示第一塊網卡,

  HWaddr 表示網卡的物理地址,可以看到目前這個網卡的物理地址(MAC地址)是 00:50:56:BF:26:20

  inet addr 用來表示網卡的IP地址,此網卡的 IP地址是 192.168.120.204,廣播位址, Bcast:192.168.120.255,掩碼地址Mask:255.255.255.0 

  lo 是表示主機的回壞地址,這個一般是用來測試一個網路程式,但又不想讓區域網路或外網的使用者能夠查看,只能在此台主機上運行和查看所用的網路介面。比如把 HTTPD伺服器的指定到回壞地址,在瀏覽器輸      

入 127.0.0.1 就能看到你所架WEB網站了。但只是您能看得到,區域網路的其它主機或使用者無從知道。

第一行:連線類型:Ethernet(乙太網路)HWaddr(硬體mac地址)

第二行:網卡的IP地址、子網、掩碼

第三行:UP(代表網卡開啟狀態)RUNNING(代表網卡的網線被接上)MULTICAST(支援組播)MTU:1500(傳輸單元最大值):1500位元組

第四、五行:接收、發送資料包情況統計

第七行:接收、發送資料位元組數統計資訊。

 

執行個體2:啟動關閉指定網卡

命令:

ifconfig eth0 up

ifconfig eth0 down

輸出:

說明:

ifconfig eth0 up 為啟動網卡eth0 ;ifconfig eth0 down 為關閉網卡eth0。ssh登陸linux伺服器操作要小心,關閉了就不能開啟了,除非你有多網卡。

 

 

執行個體3:為網卡配置和刪除IPv6地址

命令:

ifconfig eth0 add 33ffe:3240:800:1005::2/64

ifconfig eth0 del 33ffe:3240:800:1005::2/64

輸出:

說明:

ifconfig eth0 add 33ffe:3240:800:1005::2/64 為網卡eth0配置IPv6地址;

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

練習的時候,ssh登陸linux伺服器操作要小心,關閉了就不能開啟了,除非你有多網卡。

 

執行個體4:用ifconfig修改MAC地址

命令:

ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE

輸出:

 [[email protected] ~]# ifconfig eth0 down //關閉網卡
[[email protected] ~]# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址
[[email protected] ~]# ifconfig eth0 up //啟動網卡
[[email protected] ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:AA:BB:CC:DD:EE  
          inet addr:192.168.120.204  Bcast:192.168.120.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0
          TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:596390239 (568.7 MiB)  TX bytes:2886956 (2.7 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:68 errors:0 dropped:0 overruns:0 frame:0
          TX packets:68 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2856 (2.7 KiB)  TX bytes:2856 (2.7 KiB)
[[email protected] ~]# ifconfig eth0 hw ether 00:50:56:BF:26:20 //關閉網卡並修改MAC地址 
[[email protected] ~]# ifconfig eth0 up //啟動網卡
[[email protected] ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:50:56:BF:26:20  
          inet addr:192.168.120.204  Bcast:192.168.120.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0
          TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:596390239 (568.7 MiB)  TX bytes:2886956 (2.7 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:68 errors:0 dropped:0 overruns:0 frame:0
          TX packets:68 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2856 (2.7 KiB)  TX bytes:2856 (2.7 KiB)  

說明:

 

執行個體5:配置IP地址

命令:

輸出:

[[email protected] ~]# ifconfig eth0 192.168.120.56 
[[email protected] ~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0 
[[email protected] ~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255

 

說明:

ifconfig eth0 192.168.120.56   ,   給eth0網卡配置IP地:192.168.120.56

ifconfig eth0 192.168.120.56 netmask 255.255.255.0 ,給eth0網卡配置IP地址:192.168.120.56 ,並加上子掩碼:255.255.255.0

ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255,  給eth0網卡配置IP地址:192.168.120.56,加上子掩碼:255.255.255.0,加上個廣播位址: 192.168.120.255

 

執行個體6:啟用和關閉ARP協議

命令:

ifconfig eth0 arp

ifconfig eth0 -arp

輸出:

[[email protected] ~]# ifconfig eth0 arp 
[[email protected] ~]# ifconfig eth0 -arp

 

說明:

ifconfig eth0 arp 開啟網卡eth0 的arp協議;

ifconfig eth0 -arp 關閉網卡eth0 的arp協議;

 

 

執行個體7:設定傳輸單元最大值

命令:

  ifconfig eth0 mtu 1500

輸出:

 [[email protected] ~]# ifconfig eth0 mtu 1480
[[email protected] ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:50:56:BF:26:1F  
          inet addr:192.168.120.203  Bcast:192.168.120.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1480  Metric:1
          RX packets:8712395 errors:0 dropped:0 overruns:0 frame:0
          TX packets:36631 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:597062089 (569.4 MiB)  TX bytes:2643973 (2.5 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:9973 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:518096 (505.9 KiB)  TX bytes:518096 (505.9 KiB)

[[email protected] ~]# ifconfig eth0 mtu 1500
[[email protected] ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:50:56:BF:26:1F  
          inet addr:192.168.120.203  Bcast:192.168.120.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8712548 errors:0 dropped:0 overruns:0 frame:0
          TX packets:36685 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:597072333 (569.4 MiB)  TX bytes:2650581 (2.5 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:9973 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:518096 (505.9 KiB)  TX bytes:518096 (505.9 KiB)

[[email protected] ~]#  

 

說明:

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

 

備忘:用ifconfig命令配置的網卡資訊,在網卡重啟後機器重啟後,配置就不存在。要想將上述的配置資訊永遠的存的電腦裡,那就要修改網卡的設定檔了。

linux 命令——52 ifconfig(轉)

聯繫我們

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