iproute2常用命令

2021-08-20 08:29:45 字數 4296 閱讀 9172

#常用命令

ip link show                             #顯示鏈路

ip addr show                             #顯示位址(或ifconfig)

ip route show                            #顯示路由(route -n)

ip neigh show                            #顯示arp表(ping 192.168.95.50,如果主機在同一區域網內,直接加到arp表)

ip neigh delete 192.168.95.50 dev eth0   #刪除arp條目,條目仍然存在狀態為stale,下次通訊需要確認

ip rule show                             #顯示預設規則

ip route del default dev eth0            #刪除介面路由

ip route show table local                #檢視本地靜態路由

ip route show table main                 #檢視直連路由

#新增靜態路由

ip route add 10.0.0.0/24 via 192.168.92.129

ip route add 10.10.10.10 via 192.168.92.129

ip route add 172.31.100.0/24 dev eno16777736

ip route add 172.32.0.2 dev eno16777736

#檢視路由表

[root@localhost ~]# ip route show table main

default via 192.168.92.2 dev eno16777736  proto static  metric 1024 

10.0.0.0/24 via 192.168.92.129 dev eno16777736 

10.10.10.10 via 192.168.92.129 dev eno16777736 

172.31.100.0/24 dev eno16777736  scope link 

172.32.0.2 dev eno16777736  scope link 

192.168.92.0/24 dev eno16777736  proto kernel  scope link  src 192.168.92.129 

#刪除ip route del 10.0.0.0/24

ip route del 10.10.10.10

ip route del 172.31.100.0/24

ip route del 172.32.0.2

#再次檢視路由表

[root@localhost ~]# ip route show table main

default via 192.168.92.2 dev eno16777736  proto static  metric 1024 

192.168.92.0/24 dev eno16777736  proto kernel  scope link  src 192.168.92.129

[root@localhost ~]# ip route show table local

broadcast 127.0.0.0 dev lo  proto kernel  scope link  src 127.0.0.1 

local 127.0.0.0/8 dev lo  proto kernel  scope host  src 127.0.0.1 

local 127.0.0.1 dev lo  proto kernel  scope host  src 127.0.0.1 

broadcast 127.255.255.255 dev lo  proto kernel  scope link  src 127.0.0.1 

broadcast 192.168.92.0 dev eno16777736  proto kernel  scope link  src 192.168.92.129 

local 192.168.92.129 dev eno16777736  proto kernel  scope host  src 192.168.92.129 

broadcast 192.168.92.255 dev eno16777736  proto kernel  scope link  src 192.168.92.129 

#新增網絡卡別名

ip addr add 192.168.0.11/24 dev eno16777736

#檢視下網絡卡,別名沒有產生,而是直接繼承

[root@localhost ~]# ip addr show eno16777736

2: eno16777736:

mtu 1500 qdisc pfifo_fast state up qlen 1000

link/ether 00:0c:29:d0:a2:03 brd ff:ff:ff:ff:ff:ff

inet 192.168.92.129/24 brd 192.168.92.255 scope global dynamic eno16777736

valid_lft 1054sec preferred_lft 1054sec

inet 192.168.0.11/24 scope global eno16777736

valid_lft forever preferred_lft forever

inet6 fe80::20c:29ff:fed0:a203/64 scope link 

valid_lft forever preferred_lft forever

#新增網絡卡別名並新增標記    label

ip addr add 192.168.1.2 label eno16777736:0 dev eno16777736

#檢視下,多了eno16777736:0

ip addr show eno16777736

2: eno16777736:

mtu 1500 qdisc pfifo_fast state up qlen 1000

link/ether 00:0c:29:d0:a2:03 brd ff:ff:ff:ff:ff:ff

inet 192.168.92.129/24 brd 192.168.92.255 scope global dynamic eno16777736

valid_lft 1672sec preferred_lft 1672sec

inet 192.168.0.11/24 scope global eno16777736

valid_lft forever preferred_lft forever

inet 192.168.1.2/32 scope global eno16777736:0

valid_lft forever preferred_lft forever

inet6 fe80::20c:29ff:fed0:a203/64 scope link 

valid_lft forever preferred_lft forever

[root@localhost ~]# ip addr add 192.168.55.191/24 label eth0:1 dev eth0

[root@localhost ~]# ip addr show

1: lo: mtu 16436 qdisc noqueue state unknown 

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

inet 127.0.0.1/8 scope host lo

inet6 ::1/128 scope host 

valid_lft forever preferred_lft forever

2: eth0:

mtu 1500 qdisc pfifo_fast state up qlen 1000

link/ether 00:0c:29:ce:58:47 brd ff:ff:ff:ff:ff:ff

inet 192.168.55.143/24 brd 192.168.55.255 scope global eth0

inet 192.168.55.191/24 scope global secondary eth0:1

inet6 fe80::20c:29ff:fece:5847/64 scope link 

valid_lft forever preferred_lft forever

**:

iproute2交叉編譯

測試zynq ramdisk平台時發現自帶的busybox無法通過ip命令配置can介面,執行can配置命令 ip link set can0 type can bitrate 100000 會出現以下報錯 ip either dev is duplicate,or type is garbage ...

iproute2源IP路由配置

ip route add 192.168.0.0 24 dev eth0 table 10 ip route add default via 192.168.0.1 dev eth0 table 10 ip rule add from 192.168.0.10 table 10 pref 100 i...

TSN之iproute2交叉編譯

iproute2是linux上有關tcp ip網路的一系列工具,現時由stephen hemminger負責維護。這一系列工具的原作是alexey kuznetsov,他亦是linux核心中有關qos實現的作者。這一系列的工具包括了以下幾個元件 這一系列工具是為了取代一些過時不更新的命令 以上參考自...