Linux ip command

Updated: 06/22/2024 by Computer Hope
ip command

On Linux operating systems, the ip command edits and displays the configuration of network interfaces, routing, and tunnels. On many Linux systems, it replaces the deprecated ifconfig command.

Syntax

ip [ OPTIONS ] OBJECT { COMMAND | help }

where OBJECT may be:

{ link | addr | addrlabel | route | rule | neigh | ntable | tunnel |
tuntap maddr | mroute | mrule | monitor | xfrm | netns | l2tp | tcp_metrics }

and OPTIONS may be:

{ -V[ersion] | -s[tatistics] | -r[esolve] | -f[amily]
{ inet | inet6 | ipx | dnet | link } | -o[neline] }

Options

-V,
-Version
Print the version of the ip utility and exit.
-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.
-l, -loops Specify maximum number of loops the 'ip addr flush' logic will attempt before giving up. The default is 10. Zero ("0") means loop until all addresses are removed.
-f, -family Followed by protocol family identifier: inet, inet6, bridge, ipx, dnet or link, enforce the protocol family to use. If the 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.
-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 or to grep the output.
-r, -resolve Use the system's name resolver to print DNS names instead of host addresses.

Object

address Protocol (IP or IPv6) address on a device.
addrlabel Label configuration for protocol address selection.
l2tp Tunnel Ethernet over IP (L2TPv3).
link Network device.
maddress Multicast address.
monitor Watch for netlink messages.
mroute Multicast routing cache entry.
mrule Rule in multicast routing policy database.
neighbour Manage ARP (Address Resolution Protocol) 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.
tcp_metrics,
tcpmetrics
Manage TCP Metrics.
tunnel Tunnel over IP.
tuntap Manage TUN/TAP devices.
xfrm Manage IPSec policies.

The names of all objects may be written in full or abbreviated form (e.g., address is 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 link: Network Device Configuration

link is a network device and the corresponding commands display and change the state of devices.

ip link set changes device attributes:

ip link set DEVICE { up | down | arp { on | off } |
            promisc { on | off } |
            allmulticast { on | off } |
            dynamic { on | off } |
            multicast { on | off } |
            txqueuelen PACKETS |
            name NEWNAME |
            address LLADDR | broadcast LLADDR |
            mtu MTU |
            netns PID |
            alias NAME |
            vf NUM [ mac LLADDR ]
            [ vlan VLANID [ qos VLAN-QOS ] ]
            [ rate TXRATE ] } 
dev NAME (Default.) NAME specifies network device to operate on. When configuring SR-IOV Virtual Function (VF) devices, this keyword should specify the associated Physical Function (PF) device.
up, down Change the state of the device to UP or DOWN.
arp on, arp off Change the NOARP flag on the device.
multicast on, multicast off Change the MULTICAST flag on the device.
dynamic on, dynamic off Change the DYNAMIC flag on the device.
name NAME Change the name of the device. This operation is not recommended if the device is running or has some addresses already configured.
txqueuelen NUMBER, txqlen NUMBER Change the transmit queue length of the device.
mtu NUMBER Change the MTU (Maximum Transmission Unit) of the device.
address LLADDRESS Change the station address of the interface.
broadcast LLADDRESS brd LLADDRESS
peer LLADDRESS Change the link layer broadcast address or the peer address when the interface is POINTOPOINT.
netns PID Move the device to the network namespace associated with the process PID (Process IDentifier).
alias NAME Give the device a symbolic name for easy reference.
vf NUM Specify a Virtual Function device to be configured. The associated PF device must be specified using the dev parameter.
mac LLADDRESS Change the station address for the specified VF. The vf parameter must be specified.
vlan VLANID Change the assigned VLAN (Virtual Local Area Network) for the specified VF. When specified, all traffic sent from the VF will be tagged with the specified VLAN ID. Incoming traffic will be filtered for the specified VLAN ID, and will have all VLAN tags stripped before being passed to the VF. Setting this parameter to 0 disables VLAN tagging and filtering. The vf parameter must be specified.
qos VLAN-QOS Assign VLAN QOS (priority) bits for the VLAN tag. When specified, all VLAN tags transmitted by the VF will include the specified priority bits in the VLAN tag. If not specified, the value is assumed to be 0. Both the vf and vlan parameters must be specified. Setting both vlan and qos as 0 disables VLAN tagging and filtering for the VF.
rate TXRATE Change the allowed transmit bandwidth, in Mbps, for the specified VF. Setting this parameter to 0 disables rate limiting. The vf parameter must be specified.

Warning: If multiple parameter changes are requested, ip aborts immediately after any of the changes have failed. This is the only case when ip can move the system to an unpredictable state. The solution is to avoid changing several parameters with one ip link set call.

ip link show displays device attributes:

ip link show [ DEVICE ]
dev NAME (Default.) NAME specifies the network device to show. If this argument is omitted all devices are listed.
up Only display running interfaces.

ip address: Protocol Address Management

The address is a protocol (IP or IPv6) address attached to a network device. Each device must have at least one address to use the corresponding protocol. It is possible to have different addresses attached to one device. These addresses are not discriminated, so the term alias is not quite appropriate for them and we do not use it in this page.

The ip addr command displays addresses and their properties, adds new addresses and deletes old ones.

ip address add adds a new protocol address:

ip address add IFADDR dev NAME
dev NAME The name of the device to add the address to.
local ADDRESS (Default.) the address of the interface. The format of the address depends on the protocol. It is a dotted quad for IP and a sequence of hexadecimal half words separated by colons for IPv6. The ADDRESS may be followed by a slash and a decimal number which encodes the network prefix length.
peer ADDRESS The address of the remote endpoint for pointopoint interfaces. Again, the ADDRESS may be followed by a slash and a decimal number, encoding the network prefix length. If a peer address is specified, the local address cannot have a prefix length. The network prefix is associated with the peer rather than with the local address.
broadcast ADDRESS

The broadcast address on the interface.

It is possible to use the special symbols '+' and '-' instead of the broadcast address. In this case, the broadcast address is derived by setting/resetting the host bits of the interface prefix.

label NAME Each address may be tagged with a label string. To preserve compatibility with Linux-2.0 net aliases, this string must coincide with the name of the device or must be prefixed with the device name followed by colon.
scope SCOPE_VALUE

The scope of the area where this address is valid. The available scopes are listed in file /etc/iproute2/rt_scopes. Predefined scope values are:

global

the address is globally valid.

site

(IPv6 only) the address is site local, i.e., it is valid inside this site.

link

the address is link local, i.e., it is valid only on this device.

host

the address is valid only inside this host.

ip address delete deletes a protocol address:

The arguments for ip address delete are the same as the arguments of ip addr add (see above). The device name is a required argument; the rest are optional. If no arguments are given, the first address is deleted.

ip address show looks at protocol addresses:

ip address { show | flush } [ dev STRING ] [ scope SCOPE-ID ] [ to PREFIX ]
           [ FLAG-LIST ] [ label PATTERN ] 
dev NAME (Default.) name of device.
scope SCOPE_VAL Only list addresses with this scope.
to PREFIX Only list addresses matching this prefix.
label PATTERN Only list addresses with labels matching the PATTERN. PATTERN is a usual shell style pattern.
dynamic, permanent (IPv6 only) only list addresses installed due to stateless address configuration or only list permanent (not dynamic) addresses.
tentative (IPv6 only) only list addresses which did not pass duplicate address detection.
deprecated (IPv6 only) only list deprecated addresses.
primary, secondary Only list primary (or secondary) addresses.

ip address flush flushes a protocol addresses:

This command flushes the protocol addresses selected by some criteria.

This command has the same arguments as show (see above). The difference is that it does not run when no arguments are given.

Warning: This command (and other flush commands described below) is pretty dangerous. If you make a mistake, it will not forgive it, but will cruelly purge all the addresses.

With the -statistics option, the command becomes verbose. It prints out the number of deleted addresses and the number of rounds made to flush the address list. If this option is given twice, ip addr flush also dumps all the deleted addresses in the format described in the previous subsection.

ip addrlabel: Protocol Address Label Management

IPv6 address label is used for address selection described in RFC 3484. Precedence is managed by userspace, and only label is stored in kernel.

ip addrlabel add adds an address label entry to the kernel:

ip addrlabel { add | del } prefix PREFIX [ dev DEV ] [ label NUMBER ]
ip addrlabel { list | flush }
prefix PREFIX The prefix to be used.
dev DEV The outgoing interface.
label NUMBER The label for the prefix. 0xffffffff is reserved.

ip addrlabel del flushes address labels:

the command deletes an address label entry in the kernel. Arguments coincide with the arguments of ip addrlabel add but label is not required.

ip addrlabel list lists address labels:

this command shows contents of address labels.

ip addrlabel flush flushes address labels:

this command flushes the contents of address labels and does not restore default settings.

ip neighbour - neighbour/arp tables management.

neighbour objects establish bindings between protocol addresses and link layer addresses for hosts sharing the same link. Neighbour entries are organized into tables. The IPv4 neighbour table is known by another name: the ARP table.

The corresponding commands display neighbour bindings and their properties, add new neighbour entries and delete old ones.

ip neighbour { add | del | change | replace } { ADDR [ lladdr LLADDR ]
             [ nud { permanent | noarp | stale | reachable } ] | proxy ADDR }
             [ dev DEV ]

ip neighbour add - add a new neighbour entry

ip neighbour change - change an existing entry

ip neighbour replace - add a new entry or change an existing one

to ADDRESS (Default.) the protocol address of the neighbour. It is either an IPv4 or IPv6 address.
dev NAME The interface to which this neighbour is attached.
illaddr LLADDRESS The link layer address of the neighbour. LLADDRESS can also be null.
nud NUD_STATE The state of the neighbour entry. The nud is an abbreviation for 'Neighbour Unreachability Detection'. The state can take one of the following values:

permanent

The neighbour entry is valid forever and can be only be removed administratively.

noarp

The neighbour entry is valid. No attempts to validate this entry will be made but it can be removed when its lifetime expires.

reachable

The neighbour entry is valid until the reachability timeout expires.

stale

The neighbour entry is valid but suspicious. This option to ip neighbour does not change the neighbour state if it was valid and the address is not changed by this command.

ip neighbour delete deletes a neighbour entry:

This command invalidates a neighbour entry.

The arguments are the same as with ip neighbor add, except that lladdr and nud are ignored.

Warning: Attempts to delete or manually change a noarp entry created by the kernel may result in unpredictable behaviour. Particularly, the kernel may try to resolve this address even on a NOARP interface or if the address is multicast or broadcast.

ip neighbor { show | flush } [ to PREFIX ] [ dev DEV ] [ nud STATE ]

ip neighbour show lists neighbour entries:

This command displays neighbour tables.

to ADDRESS (default) The prefix selecting the neighbours to list.
dev NAME Only list the neighbours attached to this device.
unused Only list neighbours that are not currently in use.
nud NUD_STATE Only list neighbour entries in this state. NUD_STATE takes values listed below or the special value all which means all states. This option may occur more than once. If this option is absent, ip lists all entries except for none and noarp.

ip neighbour flush flushes neighbour entries:

This command flushes neighbour tables, selecting entries to flush by some criteria.

This command has the same arguments as show. The differences are that it does not run when no arguments are given, and that the default neighbour states to be flushed do not include permanent and noarp.

With the -statistics option, the command becomes verbose. It prints out the number of deleted neighbours and the number of rounds made to flush the neighbour table. If the option is given twice, ip neighbor flush also dumps all the deleted neighbours.

ip route manages routing tables:

Manipulate route entries in the kernel routing tables keep information about paths to other networked nodes.

Route types:

unicast the route entry describes real paths to the destinations covered by the route prefix.
unreachable These destinations are unreachable. Packets are discarded and the ICMP (Internet Control Message Protocol) message host unreachable is generated. The local senders get an EHOSTUNREACH error.
blackhole These destinations are unreachable. Packets are discarded silently. The local senders get an EINVAL error.
prohibit These destinations are unreachable. Packets are discarded and the ICMP message communication administratively prohibited is generated. The local senders get an EACCES error.
local The destinations are assigned to this host. The packets are looped back and delivered locally.
broadcast The destinations are broadcast addresses. The packets are sent as link broadcasts.
throw A special control route used together with policy rules. If such a route is selected, lookup in this table is terminated pretending that no route was found. Without policy routing it is equivalent to the absence of the route in the routing table. The packets are dropped and the ICMP message net unreachable is generated. The local senders get an ENETUNREACH error.
nat A special NAT (Network Address Translation) route. Destinations covered by the prefix are considered to be dummy (or external) addresses which require translation to real (or internal) ones before forwarding. The addresses to translate to are selected with the attribute via.

Warning: Route NAT is no longer supported in Linux 2.6.
anycast (Not yet implemented!) the destinations are anycast addresses assigned to this host. They are mainly equivalent to local with one difference: such addresses are invalid when used as the source address of any packet.
multicast A special type used for multicast routing. It is not present in normal routing tables.

Route tables:

Linux-2.x can pack routes into several routing tables identified by a number in the range from 1 to 255 or by name from the file /etc/iproute2/rt_tables By default, all normal routes are inserted into the main table (ID 254) and the kernel only uses this table when calculating routes.

Actually, one other table always exists, which is invisible but even more important. It is the local table (ID 255). This table consists of routes for local and broadcast addresses. The kernel maintains this table automatically and the administrator usually need not modify it or even look at it.

The multiple routing tables get involved when policy routing is used.

ip route { add | del | change | append | replace | monitor } ROUTE 

ip route add - add new route

ip route change - change route

ip route replace - change route, or add new route

to TYPE PREFIX (default) The destination prefix of the route. If TYPE is omitted, ip assumes type unicast. Other values of TYPE are listed above. PREFIX is an IP or IPv6 address optionally followed by a slash and the prefix length. If the length of the prefix is missing, ip assumes a full-length host route. There is also a special PREFIX default - which is equivalent to IP 0/0 or to IPv6 ::/0.
tos TOS, dsfield TOS The TOS (Type Of Service) key. This key has no associated mask and the longest match is understood as: First, compare the TOS of the route and of the packet. If they are not equal, then the packet may still match a route with a zero TOS. TOS is either an 8 bit hexadecimal number or an identifier from /etc/iproute2/rt_dsfield.
metric NUMBER, preference NUMBER The preference value of the route. NUMBER is an arbitrary 32 bit number.
table TABLEID The table to add this route to. TABLEID may be a number or a string from the file /etc/iproute2/rt_tables. If this parameter is omitted, ip assumes the main table, with the exception of local, broadcast and nat routes, which are put into the local table by default.
dev NAME The output device name.
via ADDRESS The address of the nexthop router. Actually, the sense of this field depends on the route type. For normal unicast routes it is either the true next hop router or, if it's a direct route installed in BSD (Berkeley Software Distribution) compatibility mode, it can be a local address of the interface. For NAT routes it is the first address of the block of translated IP destinations.
src ADDRESS The source address to prefer when sending to the destinations covered by the route prefix.
realm REALMID The realm to which this route is assigned. REALMID may be a number or a string from the file /etc/iproute2/rt_realms.
mtu MTU, mtu lock MTU The MTU along the path to the destination. If the modifier lock is not used, the MTU may be updated by the kernel due to Path MTU Discovery. If the modifier lock is used, no path MTU discovery will be tried, all packets will be sent without the DF (Don't Fragment) bit in IPv4 case or fragmented to MTU for IPv6.
window NUMBER The maximal window for TCP (Transmission Control Protocol) to advertise to these destinations, measured in bytes. It limits maximal data bursts that our TCP peers are allowed to send to us.
rtt TIME

The initial RTT ('Round Trip Time') estimate. If no suffix is specified the units are raw values passed directly to the routing code to maintain compatibility with previous releases. Otherwise:

a suffix of s, sec or secs is used to specify seconds;

ms, msec or msecs to specify milliseconds;

us, usec or usecs to specify microseconds;

ns, nsec or nsecs to specify nanoseconds;

or j, hz or jiffies to specify jiffies.

The value is then converted to what the routing code expects.

rttvar TIME The initial RTT variance estimate. Values are specified as with rtt above.
rto_min TIME The minimum TCP Retransmission timeout to use when communicating with this destination. Values are specified as with rtt above.
ssthresh NUMBER An estimate for the initial slow start threshold.
cwnd NUMBER The clamp for congestion window. It is ignored if the lock flag is not used.
initcwnd NUMBER The maximum initial congestion window (cwnd) size in MSS of a TCP connection.
initrwnd NUMBER The initial receive window size for connections to this destination. Actual window size is this value multiplied by the MSS of the connection. The default value is zero, meaning to use Slow Start value.
advmss NUMBER The MSS ('Maximal Segment Size') to advertise to these destinations when establishing TCP connections. If it's not given, Linux uses a default value calculated from the first hop device MTU. If the path to these destination is asymmetric, this guess may be wrong.
reordering NUMBER Maximal reordering on the path to this destination. If it's not given, Linux uses the value selected with sysctl variable net/ipv4/tcp_reordering.
nexthop NEXTHOP

The nexthop of a multipath route. NEXTHOP is a complex value with its own syntax similar to the top level argument lists:

via ADDRESS

is the nexthop router.

dev NAME

is the output device.

weight NUMBER

is a weight for this element of a multipath route reflecting its relative bandwidth or quality.

scope SCOPE_VAL The scope of the destinations covered by the route prefix. SCOPE_VAL may be a number or a string from the file /etc/iproute2/rt_scopes. If this parameter is omitted, ip assumes scope global for all gatewayed unicast routes, scope link for direct unicast and broadcast routes and scope host for local routes.
protocol RTPROTO

The routing protocol identifier of this route. RTPROTO may be a number or a string from the file /etc/iproute2/rt_protos. If the routing protocol ID is not given, ip assumes protocol boot (i.e., it assumes the route was added by someone who doesn't understand what they are doing). Several protocol values have a fixed interpretation. Namely:

redirect - the route was installed due to an ICMP redirect.

kernel - the route was installed by the kernel during autoconfiguration.

boot - the route was installed during the bootup sequence. If a routing daemon starts, it will purge all of them.

static - the route was installed by the administrator to override dynamic routing. Routing daemon will respect them and, probably, even advertise them to its peers.

ra - the route was installed by Router Discovery protocol.

The rest of the values are not reserved and the administrator is free to assign (or not to assign) protocol tags:

onlink Pretend that the nexthop is directly attached to this link, even if it does not match any interface prefix.
equalize Allow packet by packet randomization on multipath routes. Without this modifier, the route will be frozen to one selected nexthop, so that load splitting will only occur on per-flow base. equalize only works if the kernel is patched.

ip route delete - delete route

ip route del has the same arguments as ip route add, but their semantics are a bit different.

Key values (to, tos, preference and table) select the route to delete. If optional attributes are present, ip verifies that they coincide with the attributes of the route to delete. If no route with the given key and attributes was found, ip route del fails.

ip route show - list routes

the command displays the contents of the routing tables or the route(s) selected by some criteria.

to SELECTOR (default) Only select routes from the given range of destinations. SELECTOR consists of an optional modifier (root, match or exact) and a prefix. root PREFIX selects routes with prefixes not shorter than PREFIX. For example, root 0/0 selects the entire routing table. match PREFIX selects routes with prefixes not longer than PREFIX. For example, match 10.0/16 selects 10.0/16, 10/8 and 0/0, but it does not select 10.1/16 and 10.0.0/24. And exact PREFIX (or just PREFIX) selects routes with this exact prefix. If neither of these options are present, ip assumes root 0/0 i.e., it lists the entire table.
tos TOS, dsfield TOS Only select routes with the given TOS.
table TABLEID

Show the routes from this table(s). The default setting is to show tablemain. TABLEID may either be the ID of a real table or one of the special values:

all

list all of the tables.

cache

dump the routing cache.

cloned, cached

list cloned routes i.e., routes which were dynamically forked from other routes because some route attribute (f.e. MTU) was updated. Actually, it is equivalent to table cache.

from SELECTOR The same syntax as for to, but it binds the source address range rather than destinations. Note that the from option only works with cloned routes.
protocol RTPROTO Only list routes of this protocol.
scope SCOPE_VAL Only list routes with this scope.
type TYPE Only list routes of this type.
dev NAME Only list routes going via this device.
via PREFIX Only list routes going via the nexthop routers selected by PREFIX.
src PREFIX Only list routes with preferred source addresses selected by PREFIX.
realm REALMID, realms FROMREALM/ TOREALM Only list routes with these realms.

ip route flush - flush routing tables

this command flushes routes selected by some criteria.

The arguments have the same syntax and semantics as the arguments of ip route show, but routing tables are not listed but purged. The only difference is the default action: show dumps all the IP main routing table but flush prints the helper page.

With the -statistics option, the command becomes verbose. It prints out the number of deleted routes and the number of rounds made to flush the routing table. If the option is given twice, ip route flush also dumps all the deleted routes in the format described in the previous subsection.

ip route get - get a single route

this command gets a single route to a destination and prints its contents exactly as the kernel sees it.

to ADDRESS (default) The destination address.
from ADDRESS The source address.
tos TOS, dsfield TOS The Type Of Service.
iif NAME The device from which this packet is expected to arrive.
oif NAME Force the output device on which this packet will be routed.
connected If no source address (option from) was given, re-lookup the route with the source set to the preferred address received from the first lookup. If policy routing is used, it may be a different route.

Note that this operation is not equivalent to ip route show. show shows existing routes. get resolves them and creates new clones if necessary. Essentially, get is equivalent to sending a packet along this path. If the iif argument is not given, the kernel creates a route to output packets towards the requested destination. This is equivalent to pinging the destination with a subsequent ip route ls cache, however, no packets are actually sent. With the iif argument, the kernel pretends that a packet arrived from this interface and searches for a path to forward the packet.

ip rule - routing policy database management

Rules in the routing policy database control the route selection algorithm.

Classic routing algorithms used in the Internet make routing decisions based only on the destination address of packets (and in theory, but not in practice, on the TOS field).

In some circumstances we want to route packets differently depending not only on destination addresses, but also on other packet fields: source address, IP protocol, transport protocol ports or even packet payload. This task is called 'policy routing'.

To solve this task, the conventional destination based routing table, ordered according to the longest match rule, is replaced with a 'routing policy database' (or RPDB), which selects routes by executing some set of rules.

Each policy routing rule consists of a selector and an action predicate. The RPDB is scanned in the order of increasing priority. The selector of each rule is applied to {source address, destination address, incoming interface, tos, fwmark} and, if the selector matches the packet, the action is performed. The action predicate may return with success. In this case, it will either give a route or failure indication and the RPDB lookup is terminated. Otherwise, the RPDB program continues on the next rule.

Semantically, natural action is to select the nexthop and the output device.

ip rule [ list | add | del | flush ] SELECTOR ACTION 

ip rule add - insert a new rule

ip rule delete - delete a rule

type TYPE (default) The type of this rule. The list of valid types was given in the previous subsection.
from PREFIX Select the source prefix to match.
to PREFIX Select the destination prefix to match.
iif NAME Select the incoming device to match. If the interface is loopback, the rule only matches packets originating from this host. This means that you may create separate routing tables for forwarded and local packets and, hence, completely segregate them.
tos TOS, dsfield TOS Select the TOS value to match.
fwmark MARK Select the fwmark value to match.
priority PREFERENCE The priority of this rule. Each rule should have an explicitly set unique priority value. The options preference and order are synonyms with priority.
table TABLEID The routing table identifier to lookup if the rule selector matches. It is also possible to use lookup instead of table.
realms FROM/TO Realms to select if the rule matched and the routing table lookup succeeded. Realm TO is only used if the route did not select any realm.
nat ADDRESS The base of the IP address block to translate (for source addresses). The ADDRESS may be either the start of the block of NAT addresses (selected by NAT routes) or a local host address (or even zero). In the last case the router does not translate the packets, but masquerades them to this address. Using map-to instead of nat means the same thing.

Warning: Changes to the RPDB made with these commands do not become active immediately. It is assumed that after a script finishes a batch of updates, it flushes the routing cache with ip route flush cache.

ip rule flush - also dumps all the deleted rules.

This command has no arguments.

ip rule show - list rules

This command has no arguments. The options list or lst are synonyms with show.

ip maddress - multicast addresses management

maddress objects are multicast addresses.

ip maddress show [ dev STRING ]
ip maddress [ add | del ] MULTIADDR dev STRING

ip maddress show - list multicast addresses

dev NAME the device name.

ip maddress add - add a multicast address

ip maddress delete - delete a multicast address

these commands attach/detach a static link layer multicast address to listen on the interface. Note that it is impossible to join protocol multicast groups statically. This command only manages link layer addresses.

address LLADDRESS (default) The link layer multicast address.
dev NAME The device to join/leave this multicast address.

ip mroute - multicast routing cache management

mroute objects are multicast routing cache entries created by a user level mrouting daemon (e.g., pimd or mrouted).

Due to the limitations of the current interface to the multicast routing engine, it is impossible to change mroute objects administratively, so we may only display them. According to the authors, this limitation will be removed in the future.

ip mroute show - list mroute cache entries

ip mroute show [ PREFIX ] [ from PREFIX ] [ iif DEVICE ]
to PREFIX (default) The prefix selecting the destination multicast addresses to list.
iif NAME The interface on which multicast packets are received.
from PREFIX The prefix selecting the IP source addresses of the multicast route.

ip tunnel - tunnel configuration

tunnel objects are tunnels, encapsulating packets in IP packets and then sending them over the IP infrastructure. The encapulating (or outer) address family is specified by the -f option. The default is IPv4.

ip tunnel { add | change | del | show | prl } [ NAME ] [ mode MODE ]
          [ remote ADDR ] [ local ADDR ] [ [i|o]seq ] [ [i|o]key KEY ]
          [ [i|o]csum ] ] [ encaplimit ELIM ] [ ttl TTL ] [ tos TOS ]
          [ flowlabel FLOWLABEL ] [ prl-default ADDR ] [ prl-nodefault ADDR ]
          [ prl-delete ADDR ] [ [no]pmtudisc ] [ dev PHYS_DEV ] [ dscp inherit ]

ip tunnel add - add a new tunnel

ip tunnel change - change an existing tunnel

ip tunnel delete - destroy a tunnel

name NAME (default) Select the tunnel device name.
mode MODE Set the tunnel mode. Available modes depend on the encapsulating address family.

Modes for IPv4 encapsulation available: ipip, sit, isatap, and gre.

Modes for IPv6 encapsulation available: ip6ip6, ipip6 and any.
remote ADDRESS Set the remote endpoint of the tunnel.
local ADDRESS Set the fixed local address for tunneled packets. It must be an address on another interface of this host.
ttl N Set a fixed TTL (Time To Live) N on tunneled packets. N is a number in the range 1-255. 0 is a special value meaning that packets inherit the TTL value. The default value for IPv4 tunnels is: inherit. The default value for IPv6 tunnels is: 64.
tos T, dsfield T, tclass T Set a fixed TOS (or traffic class in IPv6) T on tunneled packets. The default value is: inherit.
dev NAME Bind the tunnel to the device NAME so that tunneled packets will only be routed via this device and will not be able to escape to another device when the route to endpoint changes.
nopmtudisc Disable Path MTU Discovery on this tunnel. It is enabled by default. Note that a fixed ttl is incompatible with this option: tunnelling with a fixed ttl always makes pmtu discovery.
key K,
ikey K,
okey K
( only GRE tunnels ) use keyed GRE with key K. K is either a number or an IP address-like dotted quad. The key parameter sets the key to use in both directions. The ikey and okey parameters set different keys for input and output.
csum, icsum, ocsum ( only GRE tunnels ) generate/require checksums for tunneled packets. The ocsum flag calculates checksums for outgoing packets. The icsum flag requires that all input packets have the correct checksum. The csum flag is equivalent to the combination icsum ocsum.
seq, iseq, oseq ( only GRE tunnels ) serialize packets. The oseq flag enables sequencing of outgoing packets. The iseq flag requires that all input packets are serialized. The seq flag is equivalent to the combination iseq oseq.
dscp inherit ( only IPv6 tunnels ) Inherit DS field between inner and outer header.
encaplim ELIM ( only IPv6 tunnels ) set a fixed encapsulation limit. Default is 4.
flowlabel FLOWLABEL ( only IPv6 tunnels ) set a fixed flowlabel.

ip tunnel prl - potential router list (ISATAP only)

dev NAME Mandatory device name.
prl-default ADDR, prl-nodefault ADDR, prl-delete ADDR Add or delete ADDR as a potential router or default router.

ip tunnel show - list tunnels

This command has no arguments.

ip monitor and rtmon - state monitoring

The ip utility can monitor the state of devices, addresses, and routes continuously. This option has a slightly different format. Namely, the monitor command is the first in the command line and then the object list follows:

ip monitor [ all | OBJECT-LIST ]

OBJECT-LIST is the list of object types that we want to monitor. It may contain link, address and route. If no file argument is given, ip opens RTNETLINK, listens on it and dumps state changes in the format described in previous sections.

If a file name is given, it does not listen on RTNETLINK, but opens the file containing RTNETLINK messages saved in binary format and dumps them. Such a history file can be generated with the rtmon utility. This utility has a command line syntax similar to ip monitor. Ideally, rtmon should be started before the first network configuration command is issued. For example, if you insert:

rtmon file /var/log/rtmon.log

in a startup script, you will be able to view the full history later.

Certainly, it is possible to start rtmon at any time. It prepends the history with the state snapshot dumped at the moment of starting.

ip xfrm - setting xfrm

xfrm is an IP framework, which can transform format of the datagrams, i.e., encrypt the packets with some algorithm. xfrm policy and xfrm state are associated through templates TMPL_LIST. This framework is used as a part of IPsec protocol.

ip xfrm state { add | update } ID [ XFRM_OPT ] [ mode MODE ] [ reqid REQID ]
              [ seq SEQ ] [ replay-window SIZE ] [ flag FLAG-LIST ]
              [ encap ENCAP ] [ sel SELECTOR ] [ LIMIT-LIST ]
ip xfrm state allocspi ID [ mode MODE ] [ reqid REQID ] [ seq SEQ ]
              [ min SPI max SPI ]

ip xfrm state add - add new state into xfrm

ip xfrm state update - update existing xfrm state

ip xfrm state allocspi - allocate SPI (Stateful Packet Inspection) value

MODE Is set as default to transport, but it could be set to tunnel,ro or beet.
FLAG-LIST Contains one or more flags.
FLAG Could be set to noecn, decap-dscp or wildrecv.
ENCAP Encapsulation is set to encapsulation type ENCAP-TYPE, source port SPORT, destination port DPORT and OADDR.
ENCAP-TYPE Could be set to espinudp or espinudp-nonike.
ALGO-LIST Contains one or more algorithms ALGO which depend on the type of algorithm set by ALGO_TYPE. The algorithm can be enc, auth or comp.
ip xfrm policy { add | update } dir DIR SELECTOR [ index INDEX ]
               [ ptype PTYPE ] [ action ACTION ] [ priority PRIORITY ]
               [ LIMIT-LIST ] [ TMPL-LIST ]
ip xfrm policy { delete | get } dir DIR [ SELECTOR | index INDEX ]
               [ ptype PTYPE ]
ip xfrm policy { deleteall | list } [ dir DIR ] [ SELECTOR ]
               [ index INDEX ] [ action ACTION ] [ priority PRIORITY ]
ip xfrm policy flush [ ptype PTYPE ]

ip xfrm policy add - add a new policy

ip xfrm policy update - update an existing policy

ip xfrm policy delete - delete existing policy

ip xfrm policy get - get existing policy

ip xfrm policy deleteall - delete all existing xfrm policy

ip xfrm policy list - print out the list of xfrm policy

ip xfrm policy flush - flush policies

ip xfrm policy flush can flush all policies or only those specified with ptype.

dir DIR Directory could be one of these: inp, out or fwd.
SELECTOR Selects which addresses the policy will configure. The selector is defined by source and destination address.
UPSPEC Is defined by source port sport, destination port dport, type as number and code also number.
dev DEV Specify network device.
index INDEX The number of indexed policy.
ptype PTYPE Default type is main.
action ACTION Default is allow.
priority PRIORITY Priority is a number. Default is zero.
LIMIT-LIST Limits are set in seconds, bytes or numbers of packets.
TMPL-LIST Template list is based on ID, mode, reqid and level.
ID Is specified by source address, destination address, proto, and value of spi.
XFRM_PROTO Values: esp, ah, comp, route2 or hao.
MODE Is set as default to transport, but it could be set to tunnel or beet.
LEVEL Is set as default on required and the other choice is use.
UPSPEC Is specified by sport, dport, type and code (NUMBER).
ip xfrm monitor [ all | OBJECT-LIST ]

ip xfrm monitor - is used for listing all objects or defined group of them.

xfrm monitor can monitor the policies for all objects or defined group of them.

Examples

Tip

You must have root access to use some functions of the ip command.

ip addr show

Lists the network interfaces.

ip route show

Lists the routing table.

ip addr add 104.20.56.118 dev eth1

Assign the IP address 104.20.56.118 to Ethernet device eth1.

A note about other operating systems

If you are using another Unix-like operating system such as BSD or macOS X (whose foundations are based upon BSD), the ip command may not be available; however the same, or very closely similar, functionality can be achieved using the route command. For instance, this Linux ip command:

ip route get 74.125.226.35

...which outputs:

74.125.226.35 via 192.168.1.1 dev wlan0  src 192.168.1.2
cache

...is similar to this OS X route command:

route get 74.125.226.35
route to: lga15s43-in-f3.1e100.net
destination: default
       mask: default
    gateway: 192.168.1.1
  interface: en1
      flags: <UP,GATEWAY,DONE,STATIC,PRCLONING>
 recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
       0         0         0         0         0         0      1500         0

Note that this form of the route command is BSD-specific, and does not carry over to Linux route. Also, note that the route command performs DNS resolution, but ip does not. Therefore, on BSD, this command will work:

route get google.com

...but this Linux command:

ip route get google.com

...will not, because it needs an IP address, and cannot (by design) resolve the domain name on its own.

There are many differences between these types of kernel-level utilities on varying operating systems despite the fact they often share the same command name, and it's advisable to check your operating system's manual pages for exact usage details.

arp — Manipulate the system ARP cache.
ifconfig — View or modify the configuration of network interfaces.
netstat — Print information about network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
route — Display and manipulate the IP routing table.
tcpdump — Capture raw network traffic.