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等。

(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地址

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

[[email protected] 桌面]# 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
[[email protected] 桌面]# 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

[[email protected] 桌面]# ip a add 192.168.78.130/24 dev eth1
[[email protected] 桌面]# 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
[[email protected] 桌面]# ip a del 192.168.78.130/24 dev eth1
[[email protected] 桌面]# 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

[[email protected] 桌面]# 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
[[email protected] 桌面]# ip a add 192.168.78.130/24 dev eth1
[[email protected] 桌面]# ip a add 192.168.78.131/24 dev eth1
[[email protected] 桌面]# 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
[[email protected] 桌面]# ip a flush dev eth1
[[email protected] 桌面]# 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

[[email protected] 桌面]# 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
[[email protected] 桌面]# ip a add 192.168.78.130/24 dev eth1
[[email protected] 桌面]# 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
[[email protected] 桌面]# ip -4 a flush dev eth1
[[email protected] 桌面]# 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

[[email protected] 桌面]# 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
[[email protected] 桌面]# 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
[[email protected] 桌面]# 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

[[email protected] 桌面]# 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
[[email protected] 桌面]# ip link set dev eth1 down
[[email protected] 桌面]# 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
[[email protected] 桌面]# 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
[[email protected] 桌面]# ip link set dev eth1 up
[[email protected] 桌面]# 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
[[email protected] 桌面]# 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

[[email protected] 桌面]# 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
[[email protected] 桌面]# 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

[[email protected] 桌面]# 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
[[email protected] 桌面]# ip r add 192.168.79.0/24 dev eth1
[[email protected] 桌面]# 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
[[email protected] 桌面]# ip r d 192.168.79.0/24 dev eth1
[[email protected] 桌面]# 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

[[email protected] 桌面]# 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
[[email protected] 桌面]# ip r d default
[[email protected] 桌面]# 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
[[email protected] 桌面]# ip r add default via 192.168.78.1
[[email protected] 桌面]# 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
[[email protected] 桌面]# ip r chg default via 192.168.78.2
[[email protected] 桌面]# 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

[[email protected] 桌面]# 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

原文地址:https://www.cnblogs.com/diantong/p/9511072.html

时间: 2024-11-13 10:44:38

Linux命令之ip的相关文章

Linux命令之ip命令

linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者.使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务.ifconfig是net-tools中已被废弃使用的一个命令,许多年前就已经没有维护了.iproute2套件里提供了许多增强功能的命令,ip命令即是其中之一. 要安装ip,请点击这里下载iproute2套装工具 .不过,大多数Linux发行版已经预装了iproute2工具. 你也可以使用git命令来下载最新源代码来编译: $ git clone https

N天学习一个linux命令之ip

用途 show / manipulate routing, devices, policy routing and tunnels 用法 通用格式 ip [ OPTIONS ] OBJECT { COMMAND | help } OBJECT := { link | addr | addrlabel | route | rule | neigh | tunnel | maddr | mroute | monitor } OPTIONS := { -V[ersion] | -s[tatistics

linux 命令之 ip

ip 命令的语法 ip [OPTIONS] OBJECT {COMMAND | help} OPTIONS是修改ip行为或者改变其输出的选项. -V : 打印ip的版本并退出 -s :输出更为详细的信息.如果这个选项出现两次或者多次,输出的信息将更为详细. -f : 这个选项后接协议种类,包括 inet.inet6.link.表明强调使用的协议种类.(link代表不涉及任何网络协议). -4 :是-f inet 的简写. -6 :是-f inet6 的简写. -0 :是-f link 的简写.

Linux命令:ip命令

ip命令功能:配置网络属性 一.ip link 系列 ip link ip [-s] link show        # 查看默认信息 ip link show eth0 ip link show up ip link show up        # 查看启用的端口 ip link show lo         # 查看某一端口 ip link set 接口 [up|down] [multicast on|off]:    # 开启或关闭接口 ip link set [dev] eth0

Linux下的ip命令

linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者.使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务.ifconfig是net-tools中已被废弃使用的一个命令,许多年前就已经没有维护了.iproute2套件里提供了许多增强功能的命令,ip命令即是其中之一. Net tools vs Iproute2 要安装ip,请点击这里下载iproute2套装工具 .不过,大多数Linux发行版已经预装了iproute2工具. 你也可以使用git命令来下载最新源代码

Linux网卡高级命令、IP别名及多网卡绑定 转

http://www.cnblogs.com/xiaoluo501395377/archive/2013/05/26/3100065.html 本篇随笔将详细讲解Linux系统的网卡高级命令.IP别名以及Linux下多网卡绑定的知识 一.网卡高级命令 在之前的一篇随笔里Linux学习之CentOS(九)--Linux系统的网络环境配置,详细讲解了Linux系统下的网络环境配置等知识,我们了解了一些关于网络配置的一些基本命令.在这里将补充一些Linux系统下有关网卡的一些高级命令. ①mii-to

用Linux命令行获取本机外网IP地址

用Linux命令行获取本机外网IP地址 $ curl ifconfig.me$ curl icanhazip.com$ curl ident.me$ curl ipecho.net/plain$ curl whatismyip.akamai.com$ curl tnx.nl/ip$ curl myip.dnsomatic.com$ curl ip.appspot.com$ curl -s checkip.dyndns.org | sed 's/.*IP Address: \([0-9\.]*\)

linux命令总结之ip命令

Linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者.使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务.ifconfig是net-tools中已被废弃使用的一个命令,许多年前就已经没有维护了.iproute2套件里提供了许多增强功能的命令,ip命令即是其中之一. 要安装ip,请点击这里下载iproute2套装工具 .不过,大多数Linux发行版已经预装了iproute2工具. 你也可以使用git命令来下载最新源代码来编译: $ git clone https

Linux命令行修改IP、网关、DNS、主机名 的方法

修改主机名:[改里面的 HOSTNAME 即可] vim /etc/sysconfig/network 网卡eth0    IP修改为 102.168.0.1 ifconfig eth0 102.168.0.1 netmask 255.255.255.0 网关修改为 102.168.0.254 route add default gw 102.168.0.254 Linux命令行修改DNS echo "nameserver 202.202.202.20 ">> /etc/r