Linux IP 命令略解

2022-09-21 06:48:10 字數 2850 閱讀 3389

help 為該命令的幫助資訊。

例項ip link show # 顯示網路介面資訊

ip link set eth0 up # 開啟網絡卡

ip link set eth0 down # 關閉網絡卡

ip link set eth0 promisc on # 開啟網絡卡的混合模式

ip link set eth0 promisc offi # 關閉網絡卡的混個模式

ip link set eth0 txqueuelen 1200 # 設定網絡卡佇列長度

ip link set eth0 mtu 1400 # 設定網絡卡最大傳輸單元

ip addr show # 顯示網絡卡ip資訊

ip addr add 192.168.0.1/24 dev eth0 # 設定eth0網絡卡ip位址192.168.0.1

ip addr del 192.168.0.1/24 dev eth0 # 刪除eth0網絡卡ip位址

ip route show # 顯示系統路由

ip route add default via 192.168.1.254 # 設定系統預設路由

ip route list # 檢視路由資訊

ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # 設定192.168.4.0網段的閘道器為192.168.0.254,資料走eth0介面

ip route add default via 192.168.0.254 dev eth0 # 設定預設閘道器為192.168.0.254

ip route del 192.168.4.0/24 # 刪除192.168.4.0網段的閘道器

ip route del default # 刪除預設路由

ip route delete 192.168.1.0/24 dev eth0 # 刪除路由

用 ip 命令顯示網路裝置的執行狀態:

[root@localhost ~]# ip link list

1: lo: mtu 16436 qdisc noqueue

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000

link/ether 00:16:3e:00:1e:51 brd ff:ff:ff:ff:ff:ff

3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000

link/ether 00:16:3e:00:1e:52 brd ff:ff:ff:ff:ff:ff

顯示更加詳細的裝置資訊:

[root@localhost ~]# ip -s link list

1: lo: mtu 16436 qdisc noqueue

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

rx: bytes packets errors dropped overrun mcast

5082831 56145 0 0 0 0

tx: bytes packets errors dropped carrier collsns

5082831 56145 0 0 0 0

2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000

link/ether 00:16:3e:00:1e:51 brd ff:ff:ff:ff:ff:ff

rx: bytes packets errors dropped overrun mcast

3641655380 62027099 0 0 0 0

tx: bytes packets errors dropped carrier collsns

6155236 89160 0 0 0 0

3: eth1: mtu 1500 qdisc pfifo_fast qlen 1000

link/ether 00:16:3e:00:1e:52 brd ff:ff:ff:ff:ff:ff

rx: bytes packets errors dropped overrun mcast

2562136822 488237847 0 0 0 0

tx: bytes packets errors dropped carrier collsns

3486617396 9691081 0 0 0 0

顯示核心路由表:

[root@localhost ~]# ip route list

112.124.12.0/22 dev eth1 proto kernel scope link src 112.124.15.130

10.160.0.0/20 dev eth0 proto kernel scope link src 10.160.7.81

192.168.0.0/16 via 10.160.15.247 dev eth0

172.16.0.0/12 via 10.160.15.247 dev eth0

10.0.0.0/8 via 10.160.15.247 dev eth0

default via 112.124.15.247 dev eth1

顯示鄰居表:

[root@localhost ~]# ip neigh list

112.124.15.247 dev eth1 lladdr 00:00:0c:9f:f3:88 reachable

10.160.15.247 dev eth0 lladdr 00:00:0c:9f:f2:c0 stale

獲取主機所有網路介面:

ip link | grep -e '^[0-9]' | awk -f: ''

linux ip命令簡介

ip是iproute2軟體包裡面的乙個強大的網路配置工具,用來顯示或操作路由 網路裝置 策略路由和隧道,它能夠替代一些傳統的網路管理工具,例如ifconfig route等。用ip配置的裝置資訊,大部分會在裝置重啟後還原,如果想永久保留配置,請盡量進入配置檔案修改。linux的ip命令和ifconf...

RPAD函式略解

在寫本篇部落格之前,有一點小東西要寫在前面,漢字佔多少個位元組得看你用的是什麼編碼集,如果是gbk和gb2312的話,確實是兩個位元組,在windows平台上會是你預期的兩個位元組。但是在linux平台使用的是utf8字符集,那麼就不一定了,不過,我現在做plsql等東西一般是在win平台上做的,l...

KMP演算法略解

前言 本文是我對kmp演算法的臨時理解,用於使我不懷疑kmp演算法的正確性,用著放心。如圖 1 長串與短串進行匹配暴力對齊匹配時,在紅叉號處失配,長串的子串藍串和短串的字首黃串相等。如圖 2 試圖利用已有資訊 黃串等於藍串 來快速尋找短串串頭下一次應該對齊長串的哪個位置,這個位置被描述為 下乙個可能...