溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Linux中如何使用fconfig命令

發(fā)布時間:2022-02-18 10:24:54 來源:億速云 閱讀:244 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹“Linux中如何使用fconfig命令”的相關(guān)知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“Linux中如何使用fconfig命令”文章能幫助大家解決問題。

Linux ifconfig命令用于顯示或設(shè)置網(wǎng)絡(luò)設(shè)備。ifconfig可設(shè)置網(wǎng)絡(luò)設(shè)備的狀態(tài),或是顯示目前的設(shè)置。

Linux中如何使用fconfig命令

命令實踐

1、顯示網(wǎng)卡信息
(1)顯示激活的網(wǎng)卡信息
ifconfig

如果網(wǎng)卡被關(guān)閉了則不會被顯示出來。

(2)顯示所有的網(wǎng)卡信息
ifconfig -a
(3)顯示網(wǎng)卡的簡要信息
ifconfig -s
(4)顯示指定網(wǎng)卡的信息
ifconfig [網(wǎng)卡名稱]
//例:ifconfig enp0s3
(5)網(wǎng)卡信息解釋
hrx@@@:~$ ifconfig
enp0s3    Link encap:Ethernet  HWaddr 08:00:27:bd:61:3c  
         inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
         inet6 addr: fe80::7035:2dfa:8d80:ea7e/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:4 errors:0 dropped:0 overruns:0 frame:0
         TX packets:115 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:930 (930.0 B)  TX bytes:14560 (14.5 KB)
         Interrupt:19 Base address:0xd020

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:65536  Metric:1
         RX packets:32 errors:0 dropped:0 overruns:0 frame:0
         TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:2386 (2.3 KB)  TX bytes:2386 (2.3 KB)
  • 網(wǎng)卡名稱:enp0s3、lo
  • Link encap:網(wǎng)卡接口類型,Ethernet(以太網(wǎng))、Local Loopback (本地環(huán)回)
  • HWaddr:網(wǎng)卡的硬件地址,即MAC地址
  • inet addr:IPv4地址
  • Bcast:廣播地址
  • Mask:子網(wǎng)掩碼地址
  • inet6 addr:IPv6地址
  • Scope:是用來限制 IPv6 組播的作用范圍,Host(主機本地范圍)、Link(鏈路本地范圍)、Site(站點本地范圍,已廢棄)、Global(全局范圍)
  • UP:表示網(wǎng)卡開啟狀態(tài),如果網(wǎng)卡關(guān)閉時則不顯示。
  • BROADCAST:表示網(wǎng)卡支持廣播
  • RUNNING:表示網(wǎng)卡正在運行
  • MULTICAST :表示網(wǎng)卡支持組播,如果網(wǎng)卡不支持則不顯示
  • MTU:最大傳輸單元,詳細的參考:https://developer.aliyun.com/article/222535
  • Metric:躍點數(shù),通常是指到達目的地址所需的躍點數(shù)量,一個躍點代表一個路由器。另外,躍點值越大表示優(yōu)先級越大
  • RX一行:分別表示網(wǎng)卡從啟動到現(xiàn)在所接收的 總包數(shù)、錯誤數(shù)、丟棄數(shù)、過載數(shù)、幀數(shù)
  • TX一行:分別表示網(wǎng)卡從啟動到現(xiàn)在所發(fā)送的 總包數(shù)、錯誤數(shù)、丟棄數(shù)、過載數(shù)、幀數(shù)
  • collisions:數(shù)據(jù)包發(fā)生沖突、碰撞的次數(shù),次數(shù)多了說明網(wǎng)絡(luò)不太好。
  • txqueuelen:發(fā)送隊列長度
  • RX bytes:接收到的字節(jié)數(shù)
  • TX bytes:發(fā)送出的字節(jié)數(shù)
  • Interrupt:IRQ中斷地址
  • Base address:基本地址
2、指定網(wǎng)卡的開關(guān)

這里以 enp0s3 網(wǎng)卡為例。當網(wǎng)卡被關(guān)閉后使用 ifconfig 是不會顯示出來的。

//啟動enp0s3網(wǎng)卡
sudo ifconfig enp0s3 up
//關(guān)閉enp0s3網(wǎng)卡
sudo ifconfig enp0s3 down
3、指定網(wǎng)卡的ARP協(xié)議開關(guān)

這里以 enp0s3 網(wǎng)卡為例。 ARP協(xié)議是地址解析協(xié)議(Address Resolution Protocol),每臺主機或路由器都維護著一份ARP緩存表(ARP table),這個表包含IP地址到MAC地址的映射關(guān)系,表中記錄了對,從而實現(xiàn)IP地址與MAC地址的查詢與轉(zhuǎn)換。 詳細的查看:https://blog.csdn.net/jiejiemcu/article/details/88406088

//啟動enp0s3網(wǎng)卡的ARP協(xié)議
sudo ifconfig enp0s3 arp
//關(guān)閉enp0s3網(wǎng)卡的ARP協(xié)議
sudo ifconfig enp0s3 -arp
4、設(shè)置網(wǎng)卡的IPv4地址及子網(wǎng)掩碼(臨時)

這里以 enp0s3 網(wǎng)卡為例。 子網(wǎng)掩碼換算: 24 與 255.255.255.0 是相等的,24意思是按二進制算,從左開始的24位全部取1,其余為0。 即 11111111 11111111 11111111 00000000,也就是255.255.255.0

//修改網(wǎng)卡 enp0s3 的 IPv4地址
sudo ifconfig enp0s3 10.0.2.16
//修改網(wǎng)卡 enp0s3 的 IPv4地址及子網(wǎng)掩碼,方法一
sudo ifconfig enp0s3 10.0.2.16/24
//修改網(wǎng)卡 enp0s3 的 IPv4地址及子網(wǎng)掩碼,方法二
sudo ifconfig enp0s3 10.0.2.16 netmask 255.255.255.0
5、配置網(wǎng)卡的虛擬接口(臨時)

這里以 enp0s3 網(wǎng)卡為例。 相當于給網(wǎng)卡再配置一個IP地址。

sudo ifconfig enp0s3:0 10.0.2.16/24
sudo ifconfig enp0s3:1 10.0.2.17/24
sudo ifconfig enp0s3:2 10.0.2.18/24
Linux中如何使用fconfig命令
6、設(shè)置網(wǎng)卡的MAC地址(臨時)

這里以 enp0s3 網(wǎng)卡為例。 注意:需要將網(wǎng)卡down掉后才能設(shè)置,否則會提示 “SIOCSIFHWADDR: 設(shè)備或資源忙 – you may need to down the interface”

//修改網(wǎng)卡的MAC地址
sudo ifconfig enp0s3 hw ether 08:00:27:bd:61:3d
Linux中如何使用fconfig命令
7、設(shè)置網(wǎng)卡的最大傳輸單元(臨時)

這里以 enp0s3 網(wǎng)卡為例。 單位是字節(jié)。

//設(shè)置網(wǎng)卡的最大傳輸單元
sudo ifconfig enp0s3 mtu 1480
8、增加及刪除網(wǎng)卡的IPv6地址

這里以 enp0s3 網(wǎng)卡為例。

//增加網(wǎng)卡的IPv6地址
sudo ifconfig enp0s3 add fe80::7035:2dfa:8d80:ea7d/64
//刪除網(wǎng)卡的IPv6地址
sudo ifconfig enp0s3 del fe80::7035:2dfa:8d80:ea7d/64

關(guān)于“Linux中如何使用fconfig命令”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI