W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
網(wǎng)絡(luò)配置工具
ip命令 用來顯示或操縱Linux主機(jī)的路由、網(wǎng)絡(luò)設(shè)備、策略路由和隧道,是Linux下較新的功能強(qiáng)大的網(wǎng)絡(luò)配置工具。
ip(選項(xiàng))(參數(shù))
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
netns | l2tp | macsec | tcp_metrics | token }
-V:顯示指令版本信息;
-s:輸出更詳細(xì)的信息;
-f:強(qiáng)制使用指定的協(xié)議族;
-4:指定使用的網(wǎng)絡(luò)層協(xié)議是IPv4協(xié)議;
-6:指定使用的網(wǎng)絡(luò)層協(xié)議是IPv6協(xié)議;
-0:輸出信息每條記錄輸出一行,即使內(nèi)容較多也不換行顯示;
-r:顯示主機(jī)時(shí),不使用IP地址,而使用主機(jī)的域名。
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
-h[uman-readable] | -iec |
-f[amily] { inet | inet6 | ipx | dnet | bridge | link } |
-4 | -6 | -I | -D | -B | -0 |
-l[oops] { maximum-addr-flush-attempts } |
-o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
-rc[vbuf] [size] | -n[etns] name | -a[ll] }
網(wǎng)絡(luò)對象:指定要管理的網(wǎng)絡(luò)對象;
具體操作:對指定的網(wǎng)絡(luò)對象完成具體操作;
help:顯示網(wǎng)絡(luò)對象支持的操作命令的幫助信息。
ip link show # 顯示網(wǎng)絡(luò)接口信息
ip link set eth0 up # 開啟網(wǎng)卡
ip link set eth0 down # 關(guān)閉網(wǎng)卡
ip link set eth0 promisc on # 開啟網(wǎng)卡的混合模式
ip link set eth0 promisc offi # 關(guān)閉網(wǎng)卡的混個(gè)模式
ip link set eth0 txqueuelen 1200 # 設(shè)置網(wǎng)卡隊(duì)列長度
ip link set eth0 mtu 1400 # 設(shè)置網(wǎng)卡最大傳輸單元
ip addr show # 顯示網(wǎng)卡IP信息
ip addr add 192.168.0.1/24 dev eth0 # 設(shè)置eth0網(wǎng)卡IP地址192.168.0.1
ip addr del 192.168.0.1/24 dev eth0 # 刪除eth0網(wǎng)卡IP地址
ip route show # 顯示系統(tǒng)路由
ip route add default via 192.168.1.254 # 設(shè)置系統(tǒng)默認(rèn)路由
ip route list # 查看路由信息
ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # 設(shè)置192.168.4.0網(wǎng)段的網(wǎng)關(guān)為192.168.0.254,數(shù)據(jù)走eth0接口
ip route add default via 192.168.0.254 dev eth0 # 設(shè)置默認(rèn)網(wǎng)關(guān)為192.168.0.254
ip route del 192.168.4.0/24 # 刪除192.168.4.0網(wǎng)段的網(wǎng)關(guān)
ip route del default # 刪除默認(rèn)路由
ip route delete 192.168.1.0/24 dev eth0 # 刪除路由
用ip命令顯示網(wǎng)絡(luò)設(shè)備的運(yùn)行狀態(tài)
[root@localhost ~]# ip link list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:16:3e:00:1e:51 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:16:3e:00:1e:52 brd ff:ff:ff:ff:ff:ff
顯示更加詳細(xì)的設(shè)備信息
[root@localhost ~]# ip -s link list
1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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
獲取主機(jī)所有網(wǎng)絡(luò)接口
ip link | grep -E '^[0-9]' | awk -F: '{print $2}'
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: