ip 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

ip 命令安装:


-bash/zsh: ip: command not found

# Windows (WSL2)
sudo apt-get update sudo apt-get install iproute2

# Debian
apt-get install iproute2

# Ubuntu
apt-get install iproute2

# Alpine
apk add iproute2

# Arch Linux
pacman -S iproute2

# Kali Linux
apt-get install iproute2

# CentOS
yum install iproute2

# Fedora
dnf install iproute2

# OS X
brew install iproute2

# Raspbian
apt-get install iproute2

# Dockerfile
dockerfile.run/ip

# Docker
docker run cmd.cat/ip ip

ip 命令补充说明:



ip

ip 命令整合了 ifconfig 与 route 这两个指令。除此之外,ip 命令可以达成更多的功能!可请自行 vi /sbin/ifup就知道整个 ifup 就是利用 ip 这个指令来达成的

ip 命令语法:


ip [ OPTIONS ] OBJECT { COMMAND | help }

ip [ -force ] -batch filename

OBJECT := { link | address | addrlabel | route | rule | neigh |
       ntable | tunnel | tuntap | maddress | mroute | mrule |
       monitor | xfrm | netns | l2tp | tcp_metrics | token |
       macsec | vrf | mptcp | ioam | stats }

OPTIONS := { -V[ersion] | -h[uman-readable] | -s[tatistics] |
       -d[etails] | -r[esolve] | -iec | -f[amily] { inet | inet6
       | link } | -4 | -6 | -B | -0 | -l[oops] { maximum-addr-
       flush-attempts } | -o[neline] | -rc[vbuf] [size] |
       -t[imestamp] | -ts[hort] | -n[etns] name | -N[umeric] |
       -a[ll] | -c[olor] | -br[ief] | -j[son] | -p[retty] }

ip 命令选项:


========================================================================
	OPTIONS
========================================================================
       -V, -Version
              Print the version of the ip utility and exit.

       -h, -human, -human-readable
              output statistics with human readable values followed by
              suffix.

       -b, -batch <FILENAME>
              Read commands from provided file or standard input and
              invoke them.  First failure will cause termination of ip.

       -force Don't terminate ip on errors in batch mode.  If there were
              any errors during execution of the commands, the
              application return code will be non zero.

       -s, -stats, -statistics
              Output more information. If the option appears twice or
              more, the amount of information increases.  As a rule, the
              information is statistics or some time values.

       -d, -details
              Output more detailed information.

       -l, -loops <COUNT>
              Specify maximum number of loops the 'ip address flush'
              logic will attempt before giving up. The default is 10.
              Zero (0) means loop until all addresses are removed.

       -f, -family <FAMILY>
              Specifies the protocol family to use. The protocol family
              identifier can be one of inet, inet6, bridge, mpls or
              link.  If this option is not present, the protocol family
              is guessed from other arguments. If the rest of the
              command line does not give enough information to guess the
              family, ip falls back to the default one, usually inet or
              any.  link is a special family identifier meaning that no
              networking protocol is involved.

       -4     shortcut for -family inet.

       -6     shortcut for -family inet6.

       -B     shortcut for -family bridge.

       -M     shortcut for -family mpls.

       -0     shortcut for -family link.

       -o, -oneline
              output each record on a single line, replacing line feeds
              with the '\' character. This is convenient when you want
              to count records with wc(1) or to grep(1) the output.

       -r, -resolve
              use the system's name resolver to print DNS names instead
              of host addresses.

       -n, -netns <NETNS>
              switches ip to the specified network namespace NETNS.
              Actually it just simplifies executing of:

              ip netns exec NETNS ip [ OPTIONS ] OBJECT { COMMAND | help
              }

              to

              ip -n[etns] NETNS [ OPTIONS ] OBJECT { COMMAND | help }

       -N, -Numeric
              Print the number of protocol, scope, dsfield, etc directly
              instead of converting it to human readable name.

       -a, -all
              executes specified command over all objects, it depends if
              command supports this option.

       -c[color][={always|auto|never}
              Configure color output. If parameter is omitted or always,
              color output is enabled regardless of stdout state. If
              parameter is auto, stdout is checked to be a terminal
              before enabling color output. If parameter is never, color
              output is disabled. If specified multiple times, the last
              one takes precedence. This flag is ignored if -json is
              also given.

              Used color palette can be influenced by COLORFGBG
              environment variable (see ENVIRONMENT).

       -t, -timestamp
              display current time when using monitor option.

       -ts, -tshort
              Like -timestamp, but use shorter format.

       -rc, -rcvbuf<SIZE>
              Set the netlink socket receive buffer size, defaults to
              1MB.

       -iec   print human readable rates in IEC units (e.g. 1Ki = 1024).

       -br, -brief
              Print only basic information in a tabular format for
              better readability. This option is currently only
              supported by ip addr show , ip link show & ip neigh show
              commands.

       -j, -json
              Output results in JavaScript Object Notation (JSON).

       -p, -pretty
              The default JSON format is compact and more efficient to
              parse but hard for most users to read.  This flag adds
              indentation for readability.

       -echo  Request the kernel to send the applied configuration back.


========================================================================
	IP - COMMAND SYNTAX      
========================================================================   
   OBJECT
       address
              - protocol (IP or IPv6) address on a device.

       addrlabel
              - label configuration for protocol address selection.

       ioam   - manage IOAM namespaces and IOAM schemas.

       l2tp   - tunnel ethernet over IP (L2TPv3).

       link   - network device.

       maddress
              - multicast address.

       monitor
              - watch for netlink messages.

       mptcp  - manage MPTCP path manager.

       mroute - multicast routing cache entry.

       mrule  - rule in multicast routing policy database.

       neighbour
              - manage ARP or NDISC cache entries.

       netns  - manage network namespaces.

       ntable - manage the neighbor cache's operation.

       route  - routing table entry.

       rule   - rule in routing policy database.

       stats  - manage and show interface statistics.

       tcp_metrics/tcpmetrics
              - manage TCP Metrics

       token  - manage tokenized interface identifiers.

       tunnel - tunnel over IP.

       tuntap - manage TUN/TAP devices.

       vrf    - manage virtual routing and forwarding devices.

       xfrm   - manage IPSec policies.

       The names of all objects may be written in full or abbreviated
       form, for example address can be abbreviated as addr or just a.

   COMMAND
       Specifies the action to perform on the object.  The set of
       possible actions depends on the object type.  As a rule, it is
       possible to add, delete and show (or list ) objects, but some
       objects do not allow all of these operations or have some
       additional commands. The help command is available for all
       objects. It prints out a list of available commands and argument
       syntax conventions.

       If no command is given, some default command is assumed.  Usually
       it is list or, if the objects of this class cannot be listed,
       help.

ip 命令实例:


ip 命令列出接口的详细信息:

ip address
ip a

ip 命令显示路由表:

ip route

ip 命令显示邻居(ARP 表):

ip neighbour

ip 命令使接口启用生效、下线禁用网络接口:

ip link set interface up/down

ip 命令向接口添加/删除 IP 地址:

ip addr add/del ip/mask dev interface

ip 命令添加默认路由:

ip route add default via ip dev interface

ip 命令扩展阅读:




ip 命令评论