[root@localhost ~]# rpm -qf /sbin/ip
iproute-2.6.32-31.el6.x86_64
ip 是个命令, ip 命令的功能很多!基本上它整合了 ifconfig 与 route 这两个命令
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] | -r[esolve] | -f[amily] { inet
               | inet6 | ipx | dnet | link } | -o[neline] }
[root@ipt ~]# ip addr help

[root@ipt ~]# ip link help
[root@localhost ~]# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:75:34:a5 brd ff:ff:ff:ff:ff:ff
ip link  
ip link 可以设定与设备 (device) 有关的相关设定,包括 MTU 以及该网络设备的 MAC 等等,当然也可以启动 (up) 或关闭 (down) 某个网络设备。
ip link set [device] [动作与参数]  device 指的是 eth0, eth1 等等设备代号
   up|down :启动 (up) 或关闭 (down) 某个设备,其他参数使用预设的以太网参数;
   address :如果这个设备可以更改 MAC ,用这个参数修改;
   name     :给予这个设备一个特殊的名字;
   mtu      :设置最大传输单元。
[root@linux ~]# ip link set eth0 up
# 启动eth0这个设备;
[root@linux ~]# ip link set eth0 down
# 关闭eth0这个设备;
[root@linux ~]# ip link set eth0 mtu 1000
# 更改 MTU为1000 bytes,单位就是 bytes 。
ip link set eth0 address aa:aa:aa:aa:aa:aa
[root@localhost ~]# ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    RX: bytes  packets  errors  dropped overrun mcast
    108016     473      0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    108016     473      0       0       0       0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:75:34:a5 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    23016263   27785    0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    2402975    17084    0       0       0       0

[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:75:34:a5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.128/24 brd 192.168.2.255 scope global eth0
    inet6 fe80::20c:29ff:fe75:34a5/64 scope link
       valid_lft forever preferred_lft forever

ip addr
如果说 ip link 是与 OSI 七层模型的第二层数据链路层有关的话,那么 ip address (ip addr) 就是与第三层网络层有关的了。主要是在设定与 IP 有关的各项参数,包括 netmask, broadcast 等等。
ip address [add|del] [IP参数] [dev 设备名] [相关参数]
IP 参数 :主要就是网域的设定,例如 192.168.100.100/24 之类的设定
相关参数如下所示:
        broadcast:设定广播位址,如果设定值是 + 表示让系统自动计算;
        label    :该设备的别名,例如eth0:0;
        scope    :这个设备的领域,通常是以下几个大类:
                   global :允许来自所有来源的连接;
                   site   :仅支持IPv6 ,仅允许本主机的连接;
                   link   :仅允许本设备自我连接;
                   host   :仅允许本主机内部的连接;
                   所以当然是使用 global 了。预设也是 global !
ip addr add 192.168.50.50/24 dev eth1
ip addr del 192.168.50.50/24 dev eth1

[root@localhost ~]# ip addrlabel
prefix ::1/128 label 0
prefix ::/96 label 3
prefix ::ffff:0.0.0.0/96 label 4
prefix 2001::/32 label 6
prefix 2001:10::/28 label 7
prefix 2002::/16 label 2
prefix fc00::/7 label 5
prefix ::/0 label 1

[root@localhost ~]# ip rule
0:      from all lookup local
32766:  from all lookup main
32767:  from all lookup default

使用ip命令的neigh或者neighbour选项,你可以查看接入你所在的局域网的设备的MAC地址。
[root@localhost ~]# ip neigh
192.168.2.190 dev eth0 lladdr 6c:fd:b9:3b:57:ff REACHABLE
192.168.2.2 dev eth0 lladdr 50:46:5d:b9:cd:68 REACHABLE

[root@localhost ~]# ip -s neigh
192.168.2.190 dev eth0 lladdr 6c:fd:b9:3b:57:ff ref 3 used 58/0/2 REACHABLE
192.168.2.2 dev eth0 lladdr 50:46:5d:b9:cd:68 ref 120 used 102/102/82 STALE

[root@localhost ~]# ip route
192.168.50.0/24 dev eth1  proto kernel  scope link  src 192.168.50.50
192.168.2.0/24 dev eth1  proto kernel  scope link  src 192.168.2.131  metric 1
default via 192.168.2.2 dev eth1  proto static
ip route
proto:此路由的路由协定,主要有 redirect, kernel, boot, static, ra 等, 其中 kernel 指的是直接由核心判断自动设定。
scope:路由的范围,主要是 link ,是与本设备有关的直接连接。
ip route add 192.168.5.0/24 dev eth0 直连网段
ip route add 192.168.10.0/24 via 192.168.5.100 dev eth0 非直连网段

linux包之iproute之ip命令的更多相关文章

  1. linux包之iproute之ss命令

    概述 [root@localhost ~]# rpm -qa|grep iprouteiproute-2.6.32-31.el6.x86_64 当服务器的socket连接数量变得非常大时,无论是使用n ...

  2. linux(Ubuntu/Centos) iproute 路由IP地址等命令集合,查看端口链接

    原 linux(Ubuntu/Centos) iproute 路由IP地址等命令集合,查看端口链接 2017年03月20日 16:55:57 风来了- 阅读数:2291 标签: centoslinux ...

  3. Linux 基础教程 27-ss和ip命令

    什么是netstat     在Linux系统中输入 man netstat,显示的结果如下所示: netstat - Print network connections, routing table ...

  4. linux包之procps之sysctl命令

    概述 [root@localhost ~]# rpm -qf /sbin/sysctlprocps-3.2.8-25.el6.x86_64 我们常常在 Linux 的 /proc/sys 目录下,手动 ...

  5. #linux包之tcpdump之tcpdump命令

    概述 man tcpdump 已阅 yum install tcpdump Downloading Packages:(1/2): libpcap-1.4.0-1.20130826git2dbcaa1 ...

  6. #linux包之lsof之lsof命令

    2015/3/18查漏补缺,反复练习命令,有不明白或疑问的地方直接看man手册页,英文解释的比较清楚 man lsof 已阅 概述 [root@localhost ~]# rpm -qa|grep l ...

  7. Linux下的设置静态IP命令详解

    网络配置的配置文件在/etc/sysconfig/network-scripts/下,文件名前缀为ifcfg-后面跟的就是网卡的名称,可以通过双TAB键查看然后编辑,也可以使用ifconfig查看,也 ...

  8. linux包之nc之nc命令

    nc-1.84-22.el6.x86_64不用系统上提供的nc版本会有所不同,其提供的参数使用方法也略有差异 nc -v -w 1 192.168.2.10 -z 1-65535|grep succe ...

  9. linux包之gdb之gdb命令与core文件产生

    gdb-7.2-64.el6_5.2.x86_64/usr/bin/gcore/usr/bin/gdb/usr/bin/gdb-add-index/usr/bin/gdbtui/usr/bin/gst ...

随机推荐

  1. shell脚本入门教程(转)

    http://bbs.chinaunix.net/thread-391751-1-1.html http://www.cnblogs.com/suyang/archive/2008/05/18/120 ...

  2. 实现:编辑短信,按power键锁屏后,再点亮屏幕,进入的还是编辑短信界面,按返回键才会进入解锁界面。

    描述:在编辑短信界面按电源键锁屏后,重新按电源键点亮屏幕,并没有进入到锁屏界面而是在编辑短信界面,此时短信界面悬浮与锁屏界面之上,这时按返回键关闭编辑短信界面,回到锁屏界面,是如何实现的呢,只需要在需 ...

  3. 对dataTable去重

    using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.T ...

  4. cmd命令进行RSA 密钥加密操作

    --参考 http://msdn.microsoft.com/zh-cn/library/2w117ede http://msdn.microsoft.com/zh-cn/library/yxw286 ...

  5. apache2将http自动指向https

    <VirtualHost *:80> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_H ...

  6. JVM监控命令详解(转)

    JVM监控命令基本就是 jps.jstack.jmap.jhat.jstat 几个命令的使用就可以了 JDK本身提供了很多方便的JVM性能调优监控工具,除了集成式的VisualVM和jConsole外 ...

  7. c 函数及指针学习 6

    不完整声明 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 /* 方法一   */ struct tag_a{ ...

  8. leetcode 142. Linked List Cycle II ----- java

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note ...

  9. leetcode 105 Construct Binary Tree from Preorder and Inorder Traversal ----- java

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  10. 《Java程序设计》第4周学习总结

    学号20145220 <Java程序设计>第4周学习总结 6.1.1 继承共同行为 •定义:继承基本上就是避免多个类间重复定义共同行为. •优点:1.提高了代码的复用性.2.让类与类之间产 ...