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 ...
随机推荐
- Jlink下载u-boot
由于各种原因我的fl2440无启动代码,无任何程序,这时要通过jlink来烧录相关boot程序. 准备工作: 1.Jlink使用jlink commander工具 2.初始化sdram的程序boot. ...
- 【NOIP模拟赛】书 数学+期望概率
biubiu~~~ 对于这道傻题.........我考场上退了一个多小时才推出来这个东西是排列...........然后我打的dfs效率n!logInf正好n=9是最后一个能过的数结果前三个点的n全是 ...
- 【BZOJ 4034】[HAOI2015]树上操作 差分+dfs序+树状数组
我们只要看出来这道题 数组表示的含义就是 某个点到根节点路径权值和就行 那么我们可以把最终答案 看做 k*x+b x就是其深度 ,我们发现dfs序之后,修改一个点是差分一个区间,修改一个点的子树,可以 ...
- powershell for rename server name
Rename server name if server has not yet joined AD $Hostname = "newname" $username = " ...
- Patch Windows with SSM on AWS
ec2ssmupdate https://docs.amazonaws.cn/systems-manager/latest/userguide/systems-manager-patch.htmlht ...
- 51Nod 1421
1421 最大MOD值 有一个a数组,里面有n个整数.现在要从中找到两个数字(可以是同一个) ai,aj ,使得 ai mod aj 最大并且 ai ≥ aj. Input 单组测试数据. 第一行包含 ...
- 【洛谷 P1667】 数列 (贪心)
题目链接 对于一个区间\([x,y]\),设这个区间的总和为\(S\) 那么我们在前缀和(设为\(sum[i]\))的意义上考虑到原操作其实就是\(sum[x−1]+=S\) , \(sum[x]+S ...
- keras_实现cnn_手写数字识别
# conding:utf-8 import os os.environ[' import numpy as np from keras.models import Sequential from k ...
- usaco 月赛 2005 january sumset
2013-09-18 08:23 打表找规律 w[i]:=w[i-1]; 奇 w[i]:=w[i-1]+w[i div 2]; 偶 //By BLADEVIL var w :..] of l ...
- 线程局部存储 TLS
C/C++运行库提供了TLS(线程局部存储),在多线程还未产生时,可以将数据与正在执行的线程关联.strtok()函数就是一个很好的例子.与它一起的还有strtok_s(),_tcstok_s()等等 ...