搜尋
首頁系統教程Linuxiproute 安裝套件中 12個 ip 常用指令

iproute 安裝套件中 12個 ip 常用指令

Apr 03, 2024 pm 01:52 PM
linuxlinux教程紅帽linux系統linux指令linux認證紅帽linuxlinux視頻子網

Year after year, we have been using the ifconfig command to perform network-related tasks, such as checking and configuring network card information. But ifconfig is no longer maintained and has been deprecated in recent versions of Linux! The ifconfig command has been replaced by the ip command.

The

ip command is somewhat similar to the ifconfig command, but it is much more powerful and has many new functions. The ip command completes many tasks that the ifconfig command cannot.

iproute 安装包中 12个  ip 常用命令

This tutorial will discuss the 12 most common uses of the ip command, let’s get started.

Case 1: Check network card information

Check the network information such as IP address, subnet and other network card, use ip addr show command:

[linuxtechi@localhost]$ ip addr show

或

[linuxtechi@localhost]$ ip a s

This will display the relevant network information of all available network cards in the system, but if you want to view the information of a certain network card, the command is:

[linuxtechi@localhost]$ ip addr show enp0s3

Here enp0s3 is the name of the network card.

iproute 安装包中 12个  ip 常用命令

IP-addr-show-commant-output

Case 2: Enable/disable network card

Use the ip command to enable a disabled network card:

[linuxtechi@localhost]$ sudo ip link set enp0s3 up

To disable the network card, use the down trigger:

[linuxtechi@localhost]$ sudo ip link set enp0s3 down
Case 3: Assign IP address and other network information to the network card

To assign an IP address to the network card, we use the following command:

[linuxtechi@localhost]$ sudo ip addr add 192.168.0.50/255.255.255.0 dev enp0s3

You can also use the ip command to set the broadcast address. By default, the broadcast address is not set. The command to set the broadcast address is:

[linuxtechi@localhost]$ sudo  ip addr add broadcast 192.168.0.255 dev enp0s3

We can also use the following command to set the standard broadcast address based on the IP address:

[linuxtechi@localhost]$  sudo ip addr add 192.168.0.10/24 brd + dev enp0s3

As shown in the above example, we can use brd instead of broadcast to set the broadcast address.

Case 4: Delete the IP address configured in the network card

If you want to delete an IP from the network card, use the following ip command:

[linuxtechi@localhost]$ sudo ip addr del 192.168.0.10/24 dev enp0s3
Case 5: Add an alias for the network card (assuming the network card is named enp0s3)

添加别名,即为网卡添加不止一个 IP,执行下面命令:
iproute 安装包中 12个  ip 常用命令

[linuxtechi@localhost]$  sudo ip addr add 192.168.0.20/24 dev enp0s3 label enp0s3:1

ip-command-add-alias-linux

案例 6:检查路由/默认网关的信息

查看路由信息会给我们显示数据包到达目的地的路由路径。要查看网络路由信息,执行下面命令:

[linuxtechi@localhost]$  ip route show

iproute 安装包中 12个  ip 常用命令

ip-route-command-output

在上面输出结果中,我们能够看到所有网卡上数据包的路由信息。我们也可以获取特定 IP 的路由信息,方法是:

[linuxtechi@localhost]$ sudo ip route get 192.168.0.1
案例 7:添加静态路由

我们也可以使用 IP 来修改数据包的默认路由。方法是使用 ip route 命令:

[linuxtechi@localhost]$ sudo ip route add default via 192.168.0.150/24

这样所有的网络数据包通过 192.168.0.150 来转发,而不是以前的默认路由了。若要修改某个网卡的默认路由,执行:

[linuxtechi@localhost]$ sudo ip route add 172.16.32.32 via 192.168.0.150/24 dev enp0s3
案例 8:删除默认路由

要删除之前设置的默认路由,打开终端然后运行:

[linuxtechi@localhost]$  sudo ip route del 192.168.0.150/24

注意: 用上面方法修改的默认路由只是临时有效的,在系统重启后所有的改动都会丢失。要永久修改路由,需要修改或创建 route-enp0s3 文件。将下面这行加入其中:

[linuxtechi@localhost]$  sudo vi /etc/sysconfig/network-scripts/route-enp0s3

172.16.32.32 via 192.168.0.150/24 dev enp0s3

保存并退出该文件。

若你使用的是基于 Ubuntu 或 debian 的操作系统,则该要修改的文件为 /etc/network/interfaces,然后添加 ip route add 172.16.32.32 via 192.168.0.150/24 dev enp0s3 这行到文件末尾。

案例 9:检查所有的 ARP 记录

ARP,是地址解析协议Address Resolution Protocol的缩写,用于将 IP 地址转换为物理地址(也就是 MAC 地址)。所有的 IP 和其对应的 MAC 明细都存储在一张表中,这张表叫做 ARP 缓存。

要查看 ARP 缓存中的记录,即连接到局域网中设备的 MAC 地址,则使用如下 ip 命令:

[linuxtechi@localhost]$  ip neigh

iproute 安装包中 12个  ip 常用命令

ip-neigh-command-linux

案例 10:修改 ARP 记录

删除 ARP 记录的命令为:

[linuxtechi@localhost]$ sudo ip neigh del 192.168.0.106 dev enp0s3

若想往 ARP 缓存中添加新记录,则命令为:

[linuxtechi@localhost]$ sudo ip neigh add 192.168.0.150 lladdr 33:1g:75:37:r3:84 dev enp0s3 nud perm

这里 nud 的意思是 “neghbour state”(网络邻居状态),它的值可以是:

  • perm - 永久有效并且只能被管理员删除
  • noarp - 记录有效,但在生命周期过期后就允许被删除了
  • stale - 记录有效,但可能已经过期
  • reachable - 记录有效,但超时后就失效了
案例 11:查看网络统计信息

通过 ip 命令还能查看网络的统计信息,比如所有网卡上传输的字节数和报文数,错误或丢弃的报文数等。使用 ip -s link 命令来查看:

[linuxtechi@localhost]$ ip -s link

iproute 安装包中 12个  ip 常用命令

ip-s-command-linux

案例 12:获取帮助

若你想查看某个上面例子中没有的选项,那么你可以查看帮助。事实上对任何命令你都可以寻求帮助。要列出 ip 命令的所有可选项,执行:

[linuxtechi@localhost]$ ip help

以上是iproute 安裝套件中 12個 ip 常用指令的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:Linux就该这么学。如有侵權,請聯絡admin@php.cn刪除
互聯網在Linux上運行嗎?互聯網在Linux上運行嗎?Apr 14, 2025 am 12:03 AM

互聯網運行不依賴單一操作系統,但Linux在其中扮演重要角色。 Linux廣泛應用於服務器和網絡設備,因其穩定性、安全性和可擴展性受歡迎。

Linux操作是什麼?Linux操作是什麼?Apr 13, 2025 am 12:20 AM

Linux操作系統的核心是其命令行界面,通過命令行可以執行各種操作。 1.文件和目錄操作使用ls、cd、mkdir、rm等命令管理文件和目錄。 2.用戶和權限管理通過useradd、passwd、chmod等命令確保系統安全和資源分配。 3.進程管理使用ps、kill等命令監控和控制系統進程。 4.網絡操作包括ping、ifconfig、ssh等命令配置和管理網絡連接。 5.系統監控和維護通過top、df、du等命令了解系統運行狀態和資源使用情況。

使用Linux別名提高自定義命令快捷方式的生產率使用Linux別名提高自定義命令快捷方式的生產率Apr 12, 2025 am 11:43 AM

介紹 Linux是一個強大的操作系統,由於其靈活性和效率,開發人員,系統管理員和電源用戶都喜歡。但是,經常使用長而復雜的命令可能是乏味的

Linux實際上有什麼好處?Linux實際上有什麼好處?Apr 12, 2025 am 12:20 AM

Linux適用於服務器、開發環境和嵌入式系統。 1.作為服務器操作系統,Linux穩定高效,常用於部署高並發應用。 2.作為開發環境,Linux提供高效的命令行工具和包管理系統,提升開發效率。 3.在嵌入式系統中,Linux輕量且可定制,適合資源有限的環境。

在Linux上掌握道德黑客的基本工具和框架在Linux上掌握道德黑客的基本工具和框架Apr 11, 2025 am 09:11 AM

簡介:通過基於Linux的道德黑客攻擊數字邊界 在我們越來越相互聯繫的世界中,網絡安全至關重要。 道德黑客入侵和滲透測試對於主動識別和減輕脆弱性至關重要

如何學習Linux基礎知識?如何學習Linux基礎知識?Apr 10, 2025 am 09:32 AM

Linux基礎學習從零開始的方法包括:1.了解文件系統和命令行界面,2.掌握基本命令如ls、cd、mkdir,3.學習文件操作,如創建和編輯文件,4.探索高級用法如管道和grep命令,5.掌握調試技巧和性能優化,6.通過實踐和探索不斷提陞技能。

Linux最有用的是什麼?Linux最有用的是什麼?Apr 09, 2025 am 12:02 AM

Linux在服務器、嵌入式系統和桌面環境中的應用廣泛。 1)在服務器領域,Linux因其穩定性和安全性成為託管網站、數據庫和應用的理想選擇。 2)在嵌入式系統中,Linux因其高度定制性和高效性而受歡迎。 3)在桌面環境中,Linux提供了多種桌面環境,滿足不同用戶需求。

Linux的缺點是什麼?Linux的缺點是什麼?Apr 08, 2025 am 12:01 AM

Linux的缺點包括用戶體驗、軟件兼容性、硬件支持和學習曲線。 1.用戶體驗不如Windows或macOS友好,依賴命令行界面。 2.軟件兼容性不如其他系統,缺乏許多商業軟件的原生版本。 3.硬件支持不如Windows全面,可能需要手動編譯驅動程序。 4.學習曲線較陡峭,掌握命令行操作需要時間和耐心。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
4 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
4 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。