Linux(四)---------网络命令(ip命令)

一.ip命令简介

IP命令是iproute软件包中强大得网络管理工具,包括ifconfig和route命令的作用,查看系统路由,网络设备,设置策略等功能。

1.查看ip命令的使用宝典

[root@localhost ~]# ip --help
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
       ip [ -force ] -batch filename
where  OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
                   tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
                   netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila |
                   vrf }
       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
                    -h[uman-readable] | -iec |
                    -f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |
                    -4 | -6 | -I | -D | -B | -0 |
                    -l[oops] { maximum-addr-flush-attempts } | -br[ief] |
                    -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
                    -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}

ip命令可以操作的对象

OBJECT :对象

link :网络设备

address :定义ipv4 ipv6的地址

neighbour:查看ARP缓存地址(ARP用于解析MAC地址)

route:路由表对象

maddress:多播地址

tunel:IP上的通道

二.IP命令案例学习

1.查看,显示网络设备信息

ip addr show = ip a

2.查看指定网络设备显示信息

[root@localhost ~]# ip link show dev ens33

3.显示网络设备,详细的数据包收发大小情况

[root@localhost ~]# ip -s link show dev ens33

4.关闭,激活网络设备

ip link set ens33 down/up #关闭启动网卡

5.修改网卡MAC地址信息

[root@localhost ~]# ip link set ens33 address 0:0c:29:13:10:11

6.ip命令添加,删除ip信息(一般在集群时候用)

[root@localhost ~]# ip address  add 193.168.178.150/24 dev ens
[root@localhost ~]# ip address del 192.168.178.161/24 dev ens33
#删除ip 信息

7.ip命令给网卡添加别名

[root@localhost ~]# ip address add 192.168.178.161/24 dev ens33 label ens33:1
#起ens33:1的别名
#注意添加完毕后,用ifconfig命令能看到别名网卡信息

8.通过ip命令检查路由信息

[root@localhost ~]# ip route
default via 192.168.23.2 dev ens33 proto dhcp metric 100 
192.168.23.0/24 dev ens33 proto kernel scope link src 192.168.23.141 metric 100 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 

9.ip检查arp缓存(显示网络令居的信息),检查MAC地址信息

[root@localhost ~]# ip neighbour
192.168.23.1 dev ens33 lladdr 00:50:56:c0:00:08 DELAY
192.168.23.2 dev ens33 lladdr 00:50:56:f6:59:77 STALE
192.168.23.254 dev ens33 lladdr 00:50:56:ec:89:d5 STALE
[root@localhost ~]# arp
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.23.1             ether   00:50:56:c0:00:08   C                     ens33
gateway                  ether   00:50:56:f6:59:77   C                     ens33
192.168.23.254           ether   00:50:56:ec:89:d5   C                     ens33
[root@localhost ~]# arp -n
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.23.1             ether   00:50:56:c0:00:08   C                     ens33
192.168.23.2             ether   00:50:56:f6:59:77   C                     ens33
192.168.23.254           ether   00:50:56:ec:89:d5   C                     ens33

猜你喜欢

转载自blog.csdn.net/weixin_58419099/article/details/132060180
今日推荐