ip:网络配置工具
简介ip命令是iproute软件包中的一个强大的网络配置工具,用于显示和管理Linux系统的路由、网络设备、策略路由和隧道。Centos7推荐使用ip命令代替传统的ipconfig和route[该命令我们没有进行说明,需要学习的请参考网上资料]命令。
说明
ip命令是iproute软件包中的一个强大的网络配置工具,用于显示和管理Linux系统的路由、网络设备、策略路由和隧道。Centos7推荐使用ip命令代替传统的ipconfig和route[该命令我们没有进行说明,需要学习的请参考网上资料]命令。
格式
ip [option] [object(网络对象)] [command]
网络对象
- link:网设备
- address:设备的协议地址(IP地址),这里可以简化成:addr或者a
- addrlabel:协议地址标签管理
- neighbour:arp或ndisc缓存表
- route:路由表
- rule:策略路由表
- maddress:多播地址
- mroute:多播路由缓存表
- tunnel:IP隧道
- xfrm:IPse协议框架
操作命令
不同的网络对象对应不同的操作命令
网络对象 | 操作命令 |
---|---|
link | set(修改设备属性)、show(显示设备属性) |
address | add(添加协议地址)、del(删除)、flush(清除)、show(查看) |
addrlabel | add、del、list、flush |
neighbour | add、change、replace、delete、show、flush |
route | add、change、replace、delete、show、flush、get |
rule | add、delete、show、flush |
maddress | add、delete、show |
mroute | show |
tunnel | add、change、delete、show、prl |
xfrm | state、policy、monitor |
常用参数
- -s:输出更详细的信息
- -r:显示主机时,不使用IP地址,而使用主机的域名
查看帮助
- ip help:查看ip命令的帮助
- ip [object] help:查看网络对象的帮助
示例
1、查看网卡信息
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 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
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:1e:d8:26 brd ff:ff:ff:ff:ff:ff
inet 192.168.71.108/24 brd 192.168.71.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe1e:d826/64 scope link
valid_lft forever preferred_lft forever
2、查看网络设备的属性
[root@localhost ~]# ip link show dev eno16777736
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:1e:d8:26 brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# ip -s link show dev eno16777736 #加了一个-s
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:1e:d8:26 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
387995 5068 0 0 0 0
TX: bytes packets errors dropped carrier collsns
302141 2111 0 0 0 0
[root@localhost ~]# ip -s -s link show dev eno16777736 #加了两个-s
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:1e:d8:26 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
392001 5111 0 0 0 0
RX errors: length crc frame fifo missed
0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
305997 2143 0 0 0 0
TX errors: aborted fifo window heartbeat
0 0 0 0
3、修改MAC地址
[root@localhost ~]# ip link show dev eno16777736
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:1e:d8:26 brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# ip link set eno16777736 address 00:ac:29:13:11:2a
[root@localhost ~]# ip link show dev eno16777736
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:ac:29:13:11:2a brd ff:ff:ff:ff:ff:ff
4、添加或删除IP地址
[root@localhost ~]# ip a show eno16777736
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:ac:29:13:11:2a brd ff:ff:ff:ff:ff:ff
inet 192.168.71.108/24 brd 192.168.71.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe1e:d826/64 scope link
valid_lft forever preferred_lft forever
[root@localhost ~]# ip a add 192.168.71.109/24 dev eno16777736#添加IP
[root@localhost ~]# ip a show eno16777736
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:ac:29:13:11:2a brd ff:ff:ff:ff:ff:ff
inet 192.168.71.108/24 brd 192.168.71.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet 192.168.71.109/24 scope global secondary eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe1e:d826/64 scope link
valid_lft forever preferred_lft forever
[root@localhost ~]# ip a del 192.168.71.109/24 dev eno16777736 #删除IP
[root@localhost ~]# ip a show eno16777736
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:ac:29:13:11:2a brd ff:ff:ff:ff:ff:ff
inet 192.168.71.108/24 brd 192.168.71.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe1e:d826/64 scope link
valid_lft forever preferred_lft forever
注意:
1、删除网卡的主IP地址,同时会删除该网卡下的所有IP地址
2、删除网卡的辅IP地址,不会影响该网卡的其他IP地址
ip命令的其他用例后续使用了再继续添加…