Linux命令之ip
ip [ OPTIONS ] OBJECT { COMMAND | help }
这一条命令几乎包含了所有使用方法,其中
对象OBJECT={ link | addr | addrlabel | route | rule | neigh | ntable | tunnel | maddr | mroute | mrule | monitor | xfrm | token }
选项OPTIONS={ -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] | -h[uman-readable] | -iec | -f[amily] { inet | inet6 | ipx | dnet | link } | -o[neline] | -t[imestamp] | -b[atch] [filename] | -rc[vbuf] [size] }
不过COMMAND比较长,请使用’ip OBJECT help’查看。
剩下的如下显示:
ip [-force] -batch filename
ip是iproute2软件包里面的一个强大的网络配置工具,用来显示或操作路由、网络设备、策略路由和隧道,它能够替代一些传统的网络管理工具,例如ifconfig、route等。用ip配置的设备信息,大部分会在设备重启后还原,如果想永久保留配置,请尽量进入配置文件修改。
(1).对象
link 网络设备
address 设备上的协议(IP或IPv6)地址
addrlabel 协议地址选择的标签配置
neighbour ARP或NDISC缓存条目
route 路由表条目
rule 路由策略数据库中的规则
maddress 组播地址
mroute 组播路由缓存条目
tunnel IP隧道
xfrm IPSec协议框架
所有对象的名称可以用完整或缩写形式书写,例如address可以缩写成addr或只是a。
(2).选项
-V,-Version 显示指令版本信息
-s,-stats,statistics 输出详细信息
-h,-human,-human-readable 输出人类可读的统计信息和后缀
-iec 以IEC标准单位打印人类可读速率(例如1K=1024)
-f,-family <FAMILY> 指定要使用的协议族。协议族标识可以是inet、inet6、ipx、dnet或link之一。如果此选项不存在,则从其他参数中推测协议族。如果命令行的其余部分没有提供足够的信息来推测该族,则ip会退回到默认值,通常是inet或any。link是一个特殊的系列标识符,表示不涉及网络协议。
-4 –family inet的快捷方式
-6 –family inet6的快捷方式
-0 –family link的快捷方式
-o,-oneline 将每条记录输出到一行,用’\’字符替换换行符。
-r,-resolve 使用系统名称解析程序来打印DNS名称而不是主机地址。
(3).实例
注意:以下介绍的ip命令都是临时配置,一但重启就会还原,如"service network restart"
查看所有IP地址
ip a/addr/address
ip a/addr/address sh/show
查看指定IP地址
ip a/addr/address sh/show dev eth1
ip a/addr/address sh/show eth1
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.78.129/24 brd 192.168.78.255 scope global eth1
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
[root@CentOS6 桌面]# ip a sh eth1
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.78.129/24 brd 192.168.78.255 scope global eth1
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
增加或删除IP地址
ip a/addr/address add 192.168.78.130/24 dev eth1
ip a/addr/address del/delete 192.168.78.130/24 dev eth1
[root@CentOS6 桌面]# ip a add 192.168.78.130/24 dev eth1
[root@CentOS6 桌面]# ip a sh eth1
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.78.129/24 brd 192.168.78.255 scope global eth1
inet 192.168.78.130/24 scope global secondary eth1
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
[root@CentOS6 桌面]# ip a del 192.168.78.130/24 dev eth1
[root@CentOS6 桌面]# ip a sh eth1
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.78.129/24 brd 192.168.78.255 scope global eth1
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
删除eth1所有IP地址
ip a flush dev eth1
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.78.129/24 brd 192.168.78.255 scope global eth1
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
[root@CentOS6 桌面]# ip a add 192.168.78.130/24 dev eth1
[root@CentOS6 桌面]# ip a add 192.168.78.131/24 dev eth1
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.78.129/24 brd 192.168.78.255 scope global eth1
inet 192.168.78.130/24 scope global secondary eth1
inet 192.168.78.131/24 scope global secondary eth1
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
[root@CentOS6 桌面]# ip a flush dev eth1
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
删除eth1的所有IPv4的IP地址
ip -4 a flush dev eth1
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.78.129/24 brd 192.168.78.255 scope global eth1
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
[root@CentOS6 桌面]# ip a add 192.168.78.130/24 dev eth1
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.78.129/24 brd 192.168.78.255 scope global eth1
inet 192.168.78.130/24 scope global secondary eth1
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
[root@CentOS6 桌面]# ip -4 a flush dev eth1
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
查看网络设备信息
ip link sh/show/l/list/ls
ip link sh/show/l/ls/lsit eth1
ip link sh/show/l/ls/list dev eth1
[root@CentOS6 桌面]# ip link l
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
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
[root@CentOS6 桌面]# ip link l eth1
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
[root@CentOS6 桌面]# ip link l dev eth1
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
停止与激活网络设备
ip link set dev eth1 down
ip link set dev eth1 up
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.78.133/24 brd 192.168.78.255 scope global eth1
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
[root@CentOS6 桌面]# ip link set dev eth1 down
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.78.133/24 brd 192.168.78.255 scope global eth1
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
[root@CentOS6 桌面]# ip link set dev eth1 up
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
[root@CentOS6 桌面]# 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:42:9f:ce brd ff:ff:ff:ff:ff:ff
inet 192.168.78.133/24 brd 192.168.78.255 scope global eth1
inet6 fe80::20c:29ff:fe42:9fce/64 scope link
valid_lft forever preferred_lft forever
查看路由表
ip r/ro/route
ip r/ro/route sh/show
ip r/ro/route sh/show dev eth1
[root@CentOS6 桌面]# ip r
192.168.78.0/24 dev eth2 proto kernel scope link src 192.168.78.132 metric 1
192.168.78.0/24 dev eth1 proto kernel scope link src 192.168.78.133 metric 1
default via 192.168.78.2 dev eth1 proto static
[root@CentOS6 桌面]# ip r sh dev eth1
192.168.78.0/24 proto kernel scope link src 192.168.78.133 metric 1
default via 192.168.78.2 proto static
添加或删除路由
ip r/ro/route add 192.168.79.0/24 dev eth1
ip r/ro/route d/del/delete 192.168.79.0/24
ip r/ro/route d/del/delete 192.168.79.0/24 dev eth1
[root@CentOS6 桌面]# ip r
192.168.78.0/24 dev eth2 proto kernel scope link src 192.168.78.132 metric 1
192.168.78.0/24 dev eth1 proto kernel scope link src 192.168.78.133 metric 1
default via 192.168.78.2 dev eth1 proto static
[root@CentOS6 桌面]# ip r add 192.168.79.0/24 dev eth1
[root@CentOS6 桌面]# ip r
192.168.79.0/24 dev eth1 scope link
192.168.78.0/24 dev eth2 proto kernel scope link src 192.168.78.132 metric 1
192.168.78.0/24 dev eth1 proto kernel scope link src 192.168.78.133 metric 1
default via 192.168.78.2 dev eth1 proto static
[root@CentOS6 桌面]# ip r d 192.168.79.0/24 dev eth1
[root@CentOS6 桌面]# ip r
192.168.78.0/24 dev eth2 proto kernel scope link src 192.168.78.132 metric 1
192.168.78.0/24 dev eth1 proto kernel scope link src 192.168.78.133 metric 1
default via 192.168.78.2 dev eth1 proto static
默认路由的删除、添加与修改
ip r/ro/route d/del/delete default
ip r/ro/route add default via 192.168.78.1
ip r/ro/route chg/change default via 192.168.78.2
[root@CentOS6 桌面]# ip r
192.168.78.0/24 dev eth1 proto kernel scope link src 192.168.78.133 metric 1
192.168.78.0/24 dev eth2 proto kernel scope link src 192.168.78.132 metric 1
default via 192.168.78.2 dev eth1 proto static
[root@CentOS6 桌面]# ip r d default
[root@CentOS6 桌面]# ip r
192.168.78.0/24 dev eth1 proto kernel scope link src 192.168.78.133 metric 1
192.168.78.0/24 dev eth2 proto kernel scope link src 192.168.78.132 metric 1
[root@CentOS6 桌面]# ip r add default via 192.168.78.1
[root@CentOS6 桌面]# ip r
192.168.78.0/24 dev eth1 proto kernel scope link src 192.168.78.133 metric 1
192.168.78.0/24 dev eth2 proto kernel scope link src 192.168.78.132 metric 1
default via 192.168.78.1 dev eth1
[root@CentOS6 桌面]# ip r chg default via 192.168.78.2
[root@CentOS6 桌面]# ip r
192.168.78.0/24 dev eth1 proto kernel scope link src 192.168.78.133 metric 1
192.168.78.0/24 dev eth2 proto kernel scope link src 192.168.78.132 metric 1
default via 192.168.78.2 dev eth1
查看ARP表
ip n/neigh/neighbuor sh/show
[root@CentOS6 桌面]# ip n
192.168.78.2 dev eth1 lladdr 00:50:56:f0:d4:05 REACHABLE
192.168.78.2 dev eth2 lladdr 00:50:56:f0:d4:05 STALE
192.168.78.254 dev eth2 lladdr 00:50:56:f5:45:c8 STALE
参考:
https://blog.csdn.net/freeking101/article/details/68939059
Linux命令之ip的更多相关文章
- Linux命令之ip命令
linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者.使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务.ifconfig是net-tools中已被废弃使用的一个命 ...
- linux命令配置IP详解
在Linux系统中,TCP/IP网络是通过若干个文本文件进行配置的,有时需要编辑这些文件来完成联网工作. vi /etc/sysconfig/network-scripts/ifcfg-eth0 :进 ...
- N天学习一个linux命令之ip
用途 show / manipulate routing, devices, policy routing and tunnels 用法 通用格式 ip [ OPTIONS ] OBJECT { CO ...
- Linux命令:ip命令
ip命令功能:配置网络属性 一.ip link 系列 ip link ip [-s] link show # 查看默认信息 ip link show eth0 ip link show ...
- Linux 命令配置IP
配置静态IP:ip addr add 192.168.18.18/24 dev eth0 启动网卡:ifup eth0/ifup ifcfg-eth0 添加默认网关路由:ip route add de ...
- linux配置网卡IP地址命令详细介绍及一些常用网络配置命令
linux配置网卡IP地址命令详细介绍及一些常用网络配置命令2010-- 个评论 收藏 我要投稿 Linux命令行下配置IP地址不像图形界面下那么方 便,完全需要我们手动配置,下面就给大家介绍几种配置 ...
- Linux命令行修改IP、网关、DNS、主机名 的方法
修改主机名:[改里面的 HOSTNAME 即可] vim /etc/sysconfig/network 网卡eth0 IP修改为 102.168.0.1 ifconfig eth0 102.16 ...
- Linux下的ip命令,除了ifconfig还有很多
linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者.使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务.ifconfig是net-tools中已被废弃使用的一个命 ...
- Linux命令行修改IP、网关、DNS的方法
Linux中在命令行中修改IP地址.网关.DNS的方法. 网卡eth0 IP修改为 102.168.0.1 复制代码代码如下: ifconfig eth0 102.168.0.1 netmask ...
随机推荐
- Seajs的用法
以前经常听到Seajs,但是没深入了解过,不清楚到底是用做哪个方面,后来调组到M站做开发,发现项目用到了Seajs,便去了解下 SeaJS是一个遵循CMD规范的JavaScript模块加载框架,可以实 ...
- 迅雷Bolt的ClipSubBindBitmap函数特别说明
因为在工作中基于迅雷Bolt开发的是IM产品,需要实现自定义用户头像的功能. 但Bolt中对图像的默认拉伸锯齿效果非常明显,所以自己实现了图像拉伸函数,代码已共享,具体可查看:<迅雷Bolt图像 ...
- 迅雷Bolt图像拉伸不清晰的解决办法
迅雷Bolt库中的图像拉伸的效果锯齿比较严重,常见的导致锯齿的情况: 1.在使用ImageObject时,drawmode为1拉伸模式下: 2.使用Bitmap类的Stretch函数拉伸图像: 虽然I ...
- vue-transition-fade
<!Doctype> <html> <head> <meta charset="utf-8"> <meta name=&quo ...
- tomcat编码配置
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" ...
- Eclipse Tomcat部署项目没有加载新加的静态资源文件
额,一直用MyEclipse,后来用Eclipse时,启动项目后去Tomcat webapps找对应文件夹,发现没有,才知道Eclipse 默认不往本地Tomcat部署. 1.eclipse不像MyE ...
- face++ API接口调用
人脸识别 首先我想描述一下,在学校的时候一直好奇人脸识别与人脸检测这个技术,之后做了很多实验,曾经使用过很多简单的算法来做人脸相似度对比,比如:夹角余弦算法.判断两个矩阵之间对应位置元素相同来做统计. ...
- Linux rar乱码
大家都知道,Linux下的中文乱码是一个很烦的事情,在这里我叫大家如何解决这个问题. rar乱码 ubunut下打开rar包,如果里面有中文就会显示乱码,其实就觉这个问题最简单了,只要把进入新立得,搜 ...
- 利用opencv自带源码,调试摄像头做人脸检测
本文为原创作品,转载请注明出处 欢迎关注我的博客:http://blog.csdn.net/hit2015spring 和 http://www.cnblogs.com/xujianqing/ 作者: ...
- 【Shell 编程基础第二部分】Shell里的流程控制、Shell里的函数及脚本调试方法!
http://blog.csdn.net/xiaominghimi/article/details/7603003 本站文章均为李华明Himi原创,转载务必在明显处注明:转载自[黑米GameDev街区 ...