LinuxReviws.org --get your your Linux knowledge
> Linux Reviews > Manual Pages (man) >

ip

Linux IPv4 protocol implementation


  1. ip.7.man
  2. ip.8.man


1. ip.7.man

Manpage of IP

IP

Section: Linux Programmer's Manual (7)
Updated: 2010-10-24
Index Return to Main Contents
 

NAME

ip - Linux IPv4 protocol implementation  

SYNOPSIS

#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h> /* superset of previous */

tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
raw_socket = socket(AF_INET, SOCK_RAW, protocol);  

DESCRIPTION

Linux implements the Internet Protocol, version 4, described in RFC 791 and RFC 1122. ip contains a level 2 multicasting implementation conforming to RFC 1112. It also contains an IP router including a packet filter.

The programming interface is BSD-sockets compatible. For more information on sockets, see socket(7).

An IP socket is created by calling the socket(2) function as socket(AF_INET, socket_type, protocol). Valid socket types are SOCK_STREAM to open a tcp(7) socket, SOCK_DGRAM to open a udp(7) socket, or SOCK_RAW to open a raw(7) socket to access the IP protocol directly. protocol is the IP protocol in the IP header to be received or sent. The only valid values for protocol are 0 and IPPROTO_TCP for TCP sockets, and 0 and IPPROTO_UDP for UDP sockets. For SOCK_RAW you may specify a valid IANA IP protocol defined in RFC 1700 assigned numbers.

When a process wants to receive new incoming packets or connections, it should bind a socket to a local interface address using bind(2). Only one IP socket may be bound to any given local (address, port) pair. When INADDR_ANY is specified in the bind call, the socket will be bound to all local interfaces. When listen(2) or connect(2) are called on an unbound socket, it is automatically bound to a random free port with the local address set to INADDR_ANY.

A TCP local socket address that has been bound is unavailable for some time after closing, unless the SO_REUSEADDR flag has been set. Care should be taken when using this flag as it makes TCP less reliable.  

Address Format

An IP socket address is defined as a combination of an IP interface address and a 16-bit port number. The basic IP protocol does not supply port numbers, they are implemented by higher level protocols like udp(7) and tcp(7). On raw sockets sin_port is set to the IP protocol.

struct sockaddr_in {
    sa_family_t    sin_family; /* address family: AF_INET */
    in_port_t      sin_port;   /* port in network byte order */
    struct in_addr sin_addr;   /* internet address */
};

/* Internet address. */
struct in_addr {
    uint32_t       s_addr;     /* address in network byte order */
};

sin_family is always set to AF_INET. This is required; in Linux 2.2 most networking functions return EINVAL when this setting is missing. sin_port contains the port in network byte order. The port numbers below 1024 are called privileged ports (or sometimes: reserved ports). Only privileged processes (i.e., those having the CAP_NET_BIND_SERVICE capability) may bind(2) to these sockets. Note that the raw IPv4 protocol as such has no concept of a port, they are only implemented by higher protocols like tcp(7) and udp(7).

sin_addr is the IP host address. The s_addr member of struct in_addr contains the host interface address in network byte order. in_addr should be assigned one of the INADDR_* values (e.g., INADDR_ANY) or set using the inet_aton(3), inet_addr(3), inet_makeaddr(3) library functions or directly with the name resolver (see gethostbyname(3)).

IPv4 addresses are divided into unicast, broadcast and multicast addresses. Unicast addresses specify a single interface of a host, broadcast addresses specify all hosts on a network and multicast addresses address all hosts in a multicast group. Datagrams to broadcast addresses can be only sent or received when the SO_BROADCAST socket flag is set. In the current implementation, connection-oriented sockets are only allowed to use unicast addresses.

Note that the address and the port are always stored in network byte order. In particular, this means that you need to call htons(3) on the number that is assigned to a port. All address/port manipulation functions in the standard library work in network byte order.

There are several special addresses: INADDR_LOOPBACK (127.0.0.1) always refers to the local host via the loopback device; INADDR_ANY (0.0.0.0) means any address for binding; INADDR_BROADCAST (255.255.255.255) means any host and has the same effect on bind as INADDR_ANY for historical reasons.  

Socket Options

IP supports some protocol-specific socket options that can be set with setsockopt(2) and read with getsockopt(2). The socket option level for IP is IPPROTO_IP. A boolean integer flag is zero when it is false, otherwise true.
IP_ADD_MEMBERSHIP (since Linux 1.2)
Join a multicast group. Argument is an ip_mreqn structure.

struct ip_mreqn {
    struct in_addr imr_multiaddr; /* IP multicast group
                                     address */
    struct in_addr imr_address;   /* IP address of local
                                     interface */
    int            imr_ifindex;   /* interface index */
};

imr_multiaddr contains the address of the multicast group the application wants to join or leave. It must be a valid multicast address (or setsockopt(2) fails with the error EINVAL). imr_address is the address of the local interface with which the system should join the multicast group; if it is equal to INADDR_ANY an appropriate interface is chosen by the system. imr_ifindex is the interface index of the interface that should join/leave the imr_multiaddr group, or 0 to indicate any interface.

The ip_mreqn structure is available only since Linux 2.2. For compatibility, the old ip_mreq structure (present since Linux 1.2) is still supported; it differs from ip_mreqn only by not including the imr_ifindex field. Only valid as a setsockopt(2).
IP_DROP_MEMBERSHIP (since Linux 1.2)
Leave a multicast group. Argument is an ip_mreqn or ip_mreq structure similar to IP_ADD_MEMBERSHIP.
IP_FREEBIND (since Linux 2.4)
If enabled, this boolean option allows binding to an IP address that is nonlocal or does not (yet) exist. This permits listening on a socket, without requiring the underlying network interface or the specified dynamic IP address to be up at the time that the application is trying to bind to it. This option is the per-socket equivalent of the ip_nonlocal_bind /proc interface described below.
IP_HDRINCL (since Linux 2.0)
If enabled, the user supplies an IP header in front of the user data. Only valid for SOCK_RAW sockets. See raw(7) for more information. When this flag is enabled the values set by IP_OPTIONS, IP_TTL and IP_TOS are ignored.
IP_MTU (since Linux 2.2)
Retrieve the current known path MTU of the current socket. Only valid when the socket has been connected. Returns an integer. Only valid as a getsockopt(2).
IP_MTU_DISCOVER (since Linux 2.2)
Set or receive the Path MTU Discovery setting for a socket. When enabled, Linux will perform Path MTU Discovery as defined in RFC 1191 on this socket. The don't-fragment flag is set on all outgoing datagrams. The system-wide default is controlled by the /proc/sys/net/ipv4/ip_no_pmtu_disc file for SOCK_STREAM sockets, and disabled on all others. For non-SOCK_STREAM sockets, it is the user's responsibility to packetize the data in MTU sized chunks and to do the retransmits if necessary. The kernel will reject packets that are bigger than the known path MTU if this flag is set (with EMSGSIZE ).
Path MTU discovery flagsMeaning
IP_PMTUDISC_WANTUse per-route settings.
IP_PMTUDISC_DONTNever do Path MTU Discovery.
IP_PMTUDISC_DOAlways do Path MTU Discovery.
IP_PMTUDISC_PROBESet DF but ignore Path MTU.

When PMTU discovery is enabled, the kernel automatically keeps track of the path MTU per destination host. When it is connected to a specific peer with connect(2), the currently known path MTU can be retrieved conveniently using the IP_MTU socket option (e.g., after a EMSGSIZE error occurred). It may change over time. For connectionless sockets with many destinations, the new MTU for a given destination can also be accessed using the error queue (see IP_RECVERR). A new error will be queued for every incoming MTU update.

While MTU discovery is in progress, initial packets from datagram sockets may be dropped. Applications using UDP should be aware of this and not take it into account for their packet retransmit strategy.

To bootstrap the path MTU discovery process on unconnected sockets, it is possible to start with a big datagram size (up to 64K-headers bytes long) and let it shrink by updates of the path MTU.

To get an initial estimate of the path MTU, connect a datagram socket to the destination address using connect(2) and retrieve the MTU by calling getsockopt(2) with the IP_MTU option.

It is possible to implement RFC 4821 MTU probing with SOCK_DGRAM or SOCK_RAW sockets by setting a value of IP_PMTUDISC_PROBE (available since Linux 2.6.22). This is also particularly useful for diagnostic tools such as tracepath(8) that wish to deliberately send probe packets larger than the observed Path MTU.

IP_MULTICAST_IF (since Linux 1.2)
Set the local device for a multicast socket. Argument is an ip_mreqn or ip_mreq structure similar to IP_ADD_MEMBERSHIP.
When an invalid socket option is passed, ENOPROTOOPT is returned.
IP_MULTICAST_LOOP (since Linux 1.2)
Set or read a boolean integer argument that determines whether sent multicast packets should be looped back to the local sockets.
IP_MULTICAST_TTL (since Linux 1.2)
Set or read the time-to-live value of outgoing multicast packets for this socket. It is very important for multicast packets to set the smallest TTL possible. The default is 1 which means that multicast packets don't leave the local network unless the user program explicitly requests it. Argument is an integer.
IP_NODEFRAG (since Linux 2.6.36)
If enabled (argument is nonzero), the reassembly of outgoing packets is disabled in the netfilter layer. This option is only valid for SOCK_RAW sockets. The argument is an integer.
IP_OPTIONS (since Linux 2.0)
Set or get the IP options to be sent with every packet from this socket. The arguments are a pointer to a memory buffer containing the options and the option length. The setsockopt(2) call sets the IP options associated with a socket. The maximum option size for IPv4 is 40 bytes. See RFC 791 for the allowed options. When the initial connection request packet for a SOCK_STREAM socket contains IP options, the IP options will be set automatically to the options from the initial packet with routing headers reversed. Incoming packets are not allowed to change options after the connection is established. The processing of all incoming source routing options is disabled by default and can be enabled by using the accept_source_route /proc interface. Other options like timestamps are still handled. For datagram sockets, IP options can be only set by the local user. Calling getsockopt(2) with IP_OPTIONS puts the current IP options used for sending into the supplied buffer.
IP_PKTINFO (since Linux 2.2)
Pass an IP_PKTINFO ancillary message that contains a pktinfo structure that supplies some information about the incoming packet. This only works for datagram oriented sockets. The argument is a flag that tells the socket whether the IP_PKTINFO message should be passed or not. The message itself can only be sent/retrieved as control message with a packet using recvmsg(2) or sendmsg(2).
struct in_pktinfo {
    unsigned int   ipi_ifindex;  /* Interface index */
    struct in_addr ipi_spec_dst; /* Local address */
    struct in_addr ipi_addr;     /* Header Destination
                                    address */
};
ipi_ifindex is the unique index of the interface the packet was received on. ipi_spec_dst is the local address of the packet and ipi_addr is the destination address in the packet header. If IP_PKTINFO is passed to sendmsg(2) and ipi_spec_dst is not zero, then it is used as the local source address for the routing table lookup and for setting up IP source route options. When ipi_ifindex is not zero, the primary local address of the interface specified by the index overwrites ipi_spec_dst for the routing table lookup.
IP_RECVERR (since Linux 2.2)
Enable extended reliable error message passing. When enabled on a datagram socket, all generated errors will be queued in a per-socket error queue. When the user receives an error from a socket operation, the errors can be received by calling recvmsg(2) with the MSG_ERRQUEUE flag set. The sock_extended_err structure describing the error will be passed in an ancillary message with the type IP_RECVERR and the level IPPROTO_IP. This is useful for reliable error handling on unconnected sockets. The received data portion of the error queue contains the error packet.
The IP_RECVERR control message contains a sock_extended_err structure:
#define SO_EE_ORIGIN_NONE    0
#define SO_EE_ORIGIN_LOCAL   1
#define SO_EE_ORIGIN_ICMP    2
#define SO_EE_ORIGIN_ICMP6   3

struct sock_extended_err {
    uint32_t ee_errno;   /* error number */
    uint8_t  ee_origin;  /* where the error originated */
    uint8_t  ee_type;    /* type */
    uint8_t  ee_code;    /* code */
    uint8_t  ee_pad;
    uint32_t ee_info;    /* additional information */
    uint32_t ee_data;    /* other data */
    /* More data may follow */
};

struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);
ee_errno contains the errno number of the queued error. ee_origin is the origin code of where the error originated. The other fields are protocol-specific. The macro SO_EE_OFFENDER returns a pointer to the address of the network object where the error originated from given a pointer to the ancillary message. If this address is not known, the sa_family member of the sockaddr contains AF_UNSPEC and the other fields of the sockaddr are undefined.
IP uses the sock_extended_err structure as follows: ee_origin is set to SO_EE_ORIGIN_ICMP for errors received as an ICMP packet, or SO_EE_ORIGIN_LOCAL for locally generated errors. Unknown values should be ignored. ee_type and ee_code are set from the type and code fields of the ICMP header. ee_info contains the discovered MTU for EMSGSIZE errors. The message also contains the sockaddr_in of the node caused the error, which can be accessed with the SO_EE_OFFENDER macro. The sin_family field of the SO_EE_OFFENDER address is AF_UNSPEC when the source was unknown. When the error originated from the network, all IP options (IP_OPTIONS, IP_TTL, etc.) enabled on the socket and contained in the error packet are passed as control messages. The payload of the packet causing the error is returned as normal payload. Note that TCP has no error queue; MSG_ERRQUEUE is not permitted on SOCK_STREAM sockets. IP_RECVERR is valid for TCP, but all errors are returned by socket function return or SO_ERROR only.
For raw sockets, IP_RECVERR enables passing of all received ICMP errors to the application, otherwise errors are only reported on connected sockets
It sets or retrieves an integer boolean flag. IP_RECVERR defaults to off.
IP_RECVOPTS (since Linux 2.2)
Pass all incoming IP options to the user in a IP_OPTIONS control message. The routing header and other options are already filled in for the local host. Not supported for SOCK_STREAM sockets.
IP_RECVORIGDSTADDR (since Linux 2.6.29)
This boolean option enables the IP_ORIGDSTADDR ancillary message in recvmsg(2), in which the kernel returns the original destination address of the datagram being received. The ancillary message contains a struct sockaddr_in.
IP_RECVTOS (since Linux 2.2)
If enabled the IP_TOS ancillary message is passed with incoming packets. It contains a byte which specifies the Type of Service/Precedence field of the packet header. Expects a boolean integer flag.
IP_RECVTTL (since Linux 2.2)
When this flag is set, pass a IP_TTL control message with the time to live field of the received packet as a byte. Not supported for SOCK_STREAM sockets.
IP_RETOPTS (since Linux 2.2)
Identical to IP_RECVOPTS, but returns raw unprocessed options with timestamp and route record options not filled in for this hop.
IP_ROUTER_ALERT (since Linux 2.2)
Pass all to-be forwarded packets with the IP Router Alert option set to this socket. Only valid for raw sockets. This is useful, for instance, for user-space RSVP daemons. The tapped packets are not forwarded by the kernel; it is the user's responsibility to send them out again. Socket binding is ignored, such packets are only filtered by protocol. Expects an integer flag.
IP_TOS (since Linux 1.0)
Set or receive the Type-Of-Service (TOS) field that is sent with every IP packet originating from this socket. It is used to prioritize packets on the network. TOS is a byte. There are some standard TOS flags defined: IPTOS_LOWDELAY to minimize delays for interactive traffic, IPTOS_THROUGHPUT to optimize throughput, IPTOS_RELIABILITY to optimize for reliability, IPTOS_MINCOST should be used for "filler data" where slow transmission doesn't matter. At most one of these TOS values can be specified. Other bits are invalid and shall be cleared. Linux sends IPTOS_LOWDELAY datagrams first by default, but the exact behavior depends on the configured queueing discipline. Some high priority levels may require superuser privileges (the CAP_NET_ADMIN capability). The priority can also be set in a protocol independent way by the (SOL_SOCKET, SO_PRIORITY) socket option (see socket(7)).
IP_TRANSPARENT (since Linux 2.6.24)
Setting this boolean option enables transparent proxying on this socket. This socket option allows the calling application to bind to a nonlocal IP address and operate both as a client and a server with the foreign address as the local endpoint. NOTE: this requires that routing be set up in a way that packets going to the foreign address are routed through the TProxy box. Enabling this socket option requires superuser privileges (the CAP_NET_ADMIN capability).
TProxy redirection with the iptables TPROXY target also requires that this option be set on the redirected socket.
IP_TTL (since Linux 1.0)
Set or retrieve the current time-to-live field that is used in every packet sent from this socket.
 

/proc interfaces

The IP protocol supports a set of /proc interfaces to configure some global parameters. The parameters can be accessed by reading or writing files in the directory /proc/sys/net/ipv4/. Interfaces described as Boolean take an integer value, with a nonzero value ("true") meaning that the corresponding option is enabled, and a zero value ("false") meaning that the option is disabled.
ip_always_defrag (Boolean; since Linux 2.2.13)
[New with kernel 2.2.13; in earlier kernel versions this feature was controlled at compile time by the CONFIG_IP_ALWAYS_DEFRAG option; this option is not present in 2.4.x and later]

When this boolean flag is enabled (not equal 0), incoming fragments (parts of IP packets that arose when some host between origin and destination decided that the packets were too large and cut them into pieces) will be reassembled (defragmented) before being processed, even if they are about to be forwarded.

Only enable if running either a firewall that is the sole link to your network or a transparent proxy; never ever use it for a normal router or host. Otherwise fragmented communication can be disturbed if the fragments travel over different links. Defragmentation also has a large memory and CPU time cost.

This is automagically turned on when masquerading or transparent proxying are configured.

ip_autoconfig (since Linux 2.2 to 2.6.17)
Not documented.
ip_default_ttl (integer; default: 64; since Linux 2.2)
Set the default time-to-live value of outgoing packets. This can be changed per socket with the IP_TTL option.
ip_dynaddr (Boolean; default: disabled; since Linux 2.0.31)
Enable dynamic socket address and masquerading entry rewriting on interface address change. This is useful for dialup interface with changing IP addresses. 0 means no rewriting, 1 turns it on and 2 enables verbose mode.
ip_forward (Boolean; default: disabled; since Linux 1.2)
Enable IP forwarding with a boolean flag. IP forwarding can be also set on a per-interface basis.
ip_local_port_range (since Linux 2.2)
Contains two integers that define the default local port range allocated to sockets. Allocation starts with the first number and ends with the second number. Note that these should not conflict with the ports used by masquerading (although the case is handled). Also arbitrary choices may cause problems with some firewall packet filters that make assumptions about the local ports in use. First number should be at least greater than 1024, or better, greater than 4096, to avoid clashes with well known ports and to minimize firewall problems.
ip_no_pmtu_disc (Boolean; default: disabled; since Linux 2.2)
If enabled, don't do Path MTU Discovery for TCP sockets by default. Path MTU discovery may fail if misconfigured firewalls (that drop all ICMP packets) or misconfigured interfaces (e.g., a point-to-point link where the both ends don't agree on the MTU) are on the path. It is better to fix the broken routers on the path than to turn off Path MTU Discovery globally, because not doing it incurs a high cost to the network.
ip_nonlocal_bind (Boolean; default: disabled; since Linux 2.4)
If set, allows processes to bind(2) to nonlocal IP addresses, which can be quite useful, but may break some applications.
ip6frag_time (integer; default: 30)
Time in seconds to keep an IPv6 fragment in memory.
ip6frag_secret_interval (integer; default: 600)
Regeneration interval (in seconds) of the hash secret (or lifetime for the hash secret) for IPv6 fragments.
ipfrag_high_thresh (integer), ipfrag_low_thresh (integer)
If the amount of queued IP fragments reaches ipfrag_high_thresh, the queue is pruned down to ipfrag_low_thresh. Contains an integer with the number of bytes.
neigh/*
See arp(7).
 

Ioctls

All ioctls described in socket(7) apply to ip.

Ioctls to configure generic device parameters are described in netdevice(7).  

ERRORS

EACCES
The user tried to execute an operation without the necessary permissions. These include: sending a packet to a broadcast address without having the SO_BROADCAST flag set; sending a packet via a prohibit route; modifying firewall settings without superuser privileges (the CAP_NET_ADMIN capability); binding to a privileged port without superuser privileges (the CAP_NET_BIND_SERVICE capability).
EADDRINUSE
Tried to bind to an address already in use.
EADDRNOTAVAIL
A nonexistent interface was requested or the requested source address was not local.
EAGAIN
Operation on a nonblocking socket would block.
EALREADY
An connection operation on a nonblocking socket is already in progress.
ECONNABORTED
A connection was closed during an accept(2).
EHOSTUNREACH
No valid routing table entry matches the destination address. This error can be caused by a ICMP message from a remote router or for the local routing table.
EINVAL
Invalid argument passed. For send operations this can be caused by sending to a blackhole route.
EISCONN
connect(2) was called on an already connected socket.
EMSGSIZE
Datagram is bigger than an MTU on the path and it cannot be fragmented.
ENOBUFS, ENOMEM
Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory, but this is not 100% consistent.
ENOENT
SIOCGSTAMP was called on a socket where no packet arrived.
ENOPKG
A kernel subsystem was not configured.
ENOPROTOOPT and EOPNOTSUPP
Invalid socket option passed.
ENOTCONN
The operation is only defined on a connected socket, but the socket wasn't connected.
EPERM
User doesn't have permission to set high priority, change configuration, or send signals to the requested process or group.
EPIPE
The connection was unexpectedly closed or shut down by the other end.
ESOCKTNOSUPPORT
The socket is not configured or an unknown socket type was requested.

Other errors may be generated by the overlaying protocols; see tcp(7), raw(7), udp(7) and socket(7).  

NOTES

IP_FREEBIND, IP_MTU, IP_MTU_DISCOVER, IP_RECVORIGDSTADDR, IP_PKTINFO, IP_RECVERR, IP_ROUTER_ALERT, and IP_TRANSPARENT are Linux-specific.

Be very careful with the SO_BROADCAST option - it is not privileged in Linux. It is easy to overload the network with careless broadcasts. For new application protocols it is better to use a multicast group instead of broadcasting. Broadcasting is discouraged.

Some other BSD sockets implementations provide IP_RCVDSTADDR and IP_RECVIF socket options to get the destination address and the interface of received datagrams. Linux has the more general IP_PKTINFO for the same task.

Some BSD sockets implementations also provide an IP_RECVTTL option, but an ancillary message with type IP_RECVTTL is passed with the incoming packet. This is different from the IP_TTL option used in Linux.

Using SOL_IP socket options level isn't portable, BSD-based stacks use IPPROTO_IP level.  

Compatibility

For compatibility with Linux 2.0, the obsolete socket(AF_INET, SOCK_PACKET, protocol) syntax is still supported to open a packet(7) socket. This is deprecated and should be replaced by socket(AF_PACKET, SOCK_RAW, protocol) instead. The main difference is the new sockaddr_ll address structure for generic link layer information instead of the old sockaddr_pkt.  

BUGS

There are too many inconsistent error values.

The ioctls to configure IP-specific interface options and ARP tables are not described.

Some versions of glibc forget to declare in_pktinfo. Workaround currently is to copy it into your program from this man page.

Receiving the original destination address with MSG_ERRQUEUE in msg_name by recvmsg(2) does not work in some 2.2 kernels.  

SEE ALSO

recvmsg(2), sendmsg(2), byteorder(3), ipfw(4), capabilities(7), netlink(7), raw(7), socket(7), tcp(7), udp(7)

RFC 791 for the original IP specification.
RFC 1122 for the IPv4 host requirements.
RFC 1812 for the IPv4 router requirements.  

COLOPHON

This page is part of release 3.32 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/.


 

Index

NAME
SYNOPSIS
DESCRIPTION
Address Format
Socket Options
/proc interfaces
Ioctls
ERRORS
NOTES
Compatibility
BUGS
SEE ALSO
COLOPHON

This document was created by man2html using the manual pages.
Time: 17:31:16 GMT, October 23, 2013

2. ip.8.man

Manpage of IP

IP

Section: Linux (8)
Updated: 17 January 2002
Index Return to Main Contents
 

NAME

ip - show / manipulate routing, devices, policy routing and tunnels  

SYNOPSIS


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] }


ip link add link DEVICE [ name ] NAME
[ txqueuelen PACKETS ]
[ address LLADDR ] [ broadcast LLADDR ]
[ mtu MTU ]
type TYPE [ ARGS ]


TYPE := [ vlan | maclan | can ]


ip link delete DEVICE type TYPE [ ARGS ]


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 ]


ip link show [ DEVICE ]


ip addr { add | del } IFADDR dev STRING


ip addr { show | flush } [ dev STRING ] [ scope SCOPE-ID ] [ to PREFIX ] [ FLAG-LIST ] [ label PATTERN ]


IFADDR := PREFIX | ADDR peer PREFIX [ broadcast ADDR ] [ anycast ADDR ] [ label STRING ] [ scope SCOPE-ID ]


SCOPE-ID := [ host | link | global | NUMBER ]


FLAG-LIST := [ FLAG-LIST ] FLAG


FLAG := [ permanent | dynamic | secondary | primary | tentative | deprecated | dadfailed | temporary ]


ip addrlabel { add | del } prefix PREFIX [ dev DEV ] [ label NUMBER ]


ip addrlabel { list | flush }


ip route { list | flush } SELECTOR


ip route save SELECTOR


ip route restore


ip route get ADDRESS [ from ADDRESS iif STRING ] [ oif STRING ] [ tos TOS ]


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


SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table TABLE_ID ] [ proto RTPROTO ] [ type TYPE ] [ scope SCOPE ]


ROUTE := NODE_SPEC [ INFO_SPEC ]


NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ] [ table TABLE_ID ] [ proto RTPROTO ] [ scope SCOPE ] [ metric METRIC ]


INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ] ...


NH := [ via ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS


OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ rtt TIME ] [ rttvar TIME ] [ window NUMBER ] [ cwnd NUMBER ] [ ssthresh REALM ] [ realms REALM ] [ rto_min TIME ] [ initcwnd NUMBER ] [ initrwnd NUMBER ]


TYPE := [ unicast | local | broadcast | multicast | throw | unreachable | prohibit | blackhole | nat ]


TABLE_ID := [ local| main | default | all | NUMBER ]


SCOPE := [ host | link | global | NUMBER ]


NHFLAGS := [ onlink | pervasive ]


RTPROTO := [ kernel | boot | static | NUMBER ]


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


SELECTOR := [ from PREFIX ] [ to PREFIX ] [ tos TOS ] [ fwmark FWMARK[/MASK] ] [ iif STRING ] [ oif STRING ] [ pref NUMBER ]


ACTION := [ table TABLE_ID ] [ nat ADDRESS ] [ prohibit | reject | unreachable ] [ realms [SRCREALM/]DSTREALM ]


TABLE_ID := [ local | main | default | NUMBER ]


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


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


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 ]


MODE := { ipip | gre | sit | isatap | ip6ip6 | ipip6 | any }


ADDR := { IP_ADDRESS | any }


TOS := { NUMBER | inherit }


ELIM := { none | 0..255 }



TTL := { 1..255 | inherit }


KEY := { DOTTED_QUAD | NUMBER }


TIME := NUMBER[s|ms]


ip maddr [ add | del ] MULTIADDR dev STRING


ip maddr show [ dev STRING ]


ip mroute show [ PREFIX ] [ from PREFIX ] [ iif DEVICE ]


ip monitor [ all | LISTofOBJECTS ]


ip xfrm XFRM_OBJECT { COMMAND }


XFRM_OBJECT := { state | policy | monitor }


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 { delete | get } ID


ip xfrm state { deleteall | list } [ ID ] [ mode MODE ]
[ reqid REQID ] [ flag FLAG_LIST ]


ip xfrm state flush [ proto XFRM_PROTO ]


ip xfrm state count


ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM_PROTO ] [ spi SPI ]


XFRM_PROTO := [ esp | ah | comp | route2 | hao ]


MODE := [ transport | tunnel | ro | beet ] (default=transport)


FLAG-LIST := [ FLAG-LIST ] FLAG


FLAG := [ noecn | decap-dscp | wildrecv ]


ENCAP := ENCAP-TYPE SPORT DPORT OADDR


ENCAP-TYPE := espinudp | espinudp-nonike


ALGO-LIST := [ ALGO-LIST ] | [ ALGO ]


ALGO := ALGO_TYPE ALGO_NAME ALGO_KEY


ALGO_TYPE := [ enc | auth | comp ]


SELECTOR := src ADDR[/PLEN] dst ADDR[/PLEN] [ UPSPEC ] [ dev DEV ]


UPSPEC := proto PROTO [[ sport PORT ] [ dport PORT ] |
[ type NUMBER ] [ code NUMBER ] |
[ key KEY ]]


LIMIT-LIST := [ LIMIT-LIST ] | [ limit LIMIT ]


LIMIT := [ [time-soft|time-hard|time-use-soft|time-use-hard] SECONDS ] | [ [byte-soft|byte-hard] SIZE ] |
[ [packet-soft|packet-hard] COUNT ]


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 count


PTYPE := [ main | sub ] (default=main)


DIR := [ in | out | fwd ]


SELECTOR := src ADDR[/PLEN] dst ADDR[/PLEN] [ UPSPEC ] [ dev DEV ]


UPSPEC := proto PROTO [ [ sport PORT ] [ dport PORT ] |
[ type NUMBER ] [ code NUMBER ] |
[ key KEY ] ]


ACTION := [ allow | block ] (default=allow)


LIMIT-LIST := [ LIMIT-LIST ] | [ limit LIMIT ]


LIMIT := [ [time-soft|time-hard|time-use-soft|time-use-hard] SECONDS ] | [ [byte-soft|byte-hard] SIZE ] |
[packet-soft|packet-hard] NUMBER ]


TMPL-LIST := [ TMPL-LIST ] | [ tmpl TMPL ]


TMPL := ID [ mode MODE ] [ reqid REQID ] [ level LEVEL ]


ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM_PROTO ] [ spi SPI ]


XFRM_PROTO := [ esp | ah | comp | route2 | hao ]


MODE := [ transport | tunnel | beet ] (default=transport)


LEVEL := [ required | use ] (default=required)


ip xfrm monitor [ all | LISTofOBJECTS ]

 

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 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.

-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.

 

IP - COMMAND SYNTAX

 

OBJECT

link
- network device.

address
- protocol (IP or IPv6) address on a device.

addrlabel
- label configuration for protocol address selection.

neighbour
- ARP or NDISC cache entry.

route
- routing table entry.

rule
- rule in routing policy database.

maddress
- multicast address.

mroute
- multicast routing cache entry.

tunnel
- tunnel over IP.

xfrm
- framework for IPsec protocol.

The names of all objects may be written in full or abbreviated form, f.e. 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 add - add virtual link

link DEVICE
specifies the physical device to act operate on.

NAME specifies the name of the new virtual device.

TYPE specifies the type of the new device.

Link types:

vlan - 802.1q tagged virrtual LAN interface

macvlan - virtual interface base on link layer address (MAC)

can - Controller Area Network interface

 

ip link delete - delete virtual link

DEVICE specifies the virtual device to act operate on. TYPE specifies the type of the device.

dev DEVICE
specifies the physical device to act operate on.

 

ip link set - change device attributes

dev DEVICE
DEVICE specifies network device to operate on. When configuring SR-IOV Virtual Fuction (VF) devices, this keyword should specify the associated Physical Function (PF) device.

up and down
change the state of the device to UP or DOWN.

arp on or arp off
change the NOARP flag on the device.

multicast on or multicast off
change the MULTICAST flag on the device.

dynamic on or 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 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.

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 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 - display device attributes

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 several different addresses attached to one device. These addresses are not discriminated, so that the term alias is not quite appropriate for them and we do not use it in this document.

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

 

ip address add - add new protocol address.

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 halfwords 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. In order 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 - delete protocol address

Arguments: coincide with the arguments of ip addr add. The device name is a required argument. The rest are optional. If no arguments are given, the first address is deleted.

 

ip address show - look at protocol addresses

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 and 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 have not yet passed duplicate address detection.

deprecated
(IPv6 only) only list deprecated addresses.

dadfailed
(IPv6 only) only list addresses which have failed duplicate address detection.

temporary
(IPv6 only) only list temporary addresses.

primary and secondary
only list primary (or secondary) addresses.

 

ip address flush - flush protocol addresses

This command flushes the protocol addresses selected by some criteria.

This command has the same arguments as show. 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 - add an address label

the command adds an address label entry to the kernel.
prefix PREFIX
dev DEV
the outgoing interface.
label NUMBER
the label for the prefix. 0xffffffff is reserved.
 

ip addrlabel del - delete an address label

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 - list address labels

the command show contents of address labels.  

ip addrlabel flush - flush address labels

the command flushes the contents of address labels and it 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 - add a new neighbour entry

 

ip neighbour change - change an existing entry

 

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

These commands create new neighbour records or update existing ones.

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.

lladdr LLADDRESS
the link layer address of the neighbour. LLADDRESS can also be null.

nud NUD_STATE
the state of the neighbour entry. 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 neigh does not change the neighbour state if it was valid and the address is not changed by this command.

 

ip neighbour delete - delete a neighbour entry

This command invalidates a neighbour entry.

The arguments are the same as with ip neigh 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 neighbour show - list neighbour entries

This commands 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 which 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 - flush 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 neigh flush also dumps all the deleted neighbours.

 

ip route - routing table management

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 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 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 Warning: Route NAT is no longer supported in Linux 2.6.

via.

anycast - not 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 2^31 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. Values (0, 253, 254, and 255) are reserved for built-in use.

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 enter the game when policy routing is used.

 

ip route add - add new route

 

ip route change - change route

 

ip route replace - change or add new one

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 Type Of Service (TOS) 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 32bit 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 is a direct route installed in BSD 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 bit in IPv4 case or fragmented to MTU for IPv6.

window NUMBER
the maximal window for TCP 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 if a suffix of s, sec or secs is used to specify seconds and ms, msec or msecs to specify milliseconds.

rttvar TIME (2.3.15+ only)
the initial RTT variance estimate. Values are specified as with rtt above.

rto_min TIME (2.6.23+ only)
the minimum TCP Retransmission TimeOut to use when communicating with this destination. Values are specified as with rtt above.

ssthresh NUMBER (2.3.15+ only)
an estimate for the initial slow start threshold.

cwnd NUMBER (2.3.15+ only)
the clamp for congestion window. It is ignored if the lock flag is not used.

initcwnd NUMBER (2.5.70+ only)
the initial congestion window size for connections to this destination. Actual window size is this value multiplied by the MSS (``Maximal Segment Size'') for same connection. The default is zero, meaning to use the values specified in RFC2414.

initrwnd NUMBER (2.6.33+ only)
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 (2.3.15+ only)
the MSS ('Maximal Segment Size') to advertise to these destinations when establishing TCP connections. If it is 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 (2.3.15+ only)
Maximal reordering on the path to this destination. If it is 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.

 

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. F.e. root 0/0 selects the entire routing table. match PREFIX selects routes with prefixes not longer than PREFIX. F.e. 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, relookup 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 route save - save routing table information to stdout

this command behaves like ip route show except that the output is raw data suitable for passing to ip route restore.

 

ip route restore - restore routing table information from stdin

this command expects to read a data stream as returned from ip route save. It will attempt to restore the routing table information exactly as it was at the time of the save, so any translation of information in the stream (such as device indexes) must be done first. Any existing routes are left unchanged. Any routes specified in the data stream that already exist in the table will be ignored.

 

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.

At startup time the kernel configures the default RPDB consisting of three rules:

1.
Priority: 0, Selector: match anything, Action: lookup routing table local (ID 255). The local table is a special routing table containing high priority control routes for local and broadcast addresses.

Rule 0 is special. It cannot be deleted or overridden.

2.
Priority: 32766, Selector: match anything, Action: lookup routing table main (ID 254). The main table is the normal routing table containing all non-policy routes. This rule may be deleted and/or overridden with other ones by the administrator.

3.
Priority: 32767, Selector: match anything, Action: lookup routing table default (ID 253). The default table is empty. It is reserved for some post-processing if no previous default rules selected the packet. This rule may also be deleted.

Each RPDB entry has additional attributes. F.e. each rule has a pointer to some routing table. NAT and masquerading rules have an attribute to select new IP address to translate/masquerade. Besides that, rules have some optional attributes, which routes have, namely realms. These values do not override those contained in the routing tables. They are only used if the route did not select any attributes.

The RPDB may contain rules of the following types:

unicast - the rule prescribes to return the route found in the routing table referenced by the rule.

blackhole - the rule prescribes to silently drop the packet.

unreachable - the rule prescribes to generate a 'Network is unreachable' error.

prohibit - the rule prescribes to generate 'Communication is administratively prohibited' error.

nat - the rule prescribes to translate the source address of the IP packet into some other value.

 

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.

oif NAME
select the outgoing device to match. The outgoing interface is only available for packets originating from local sockets that are bound to a device.

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 - list multicast addresses

dev NAME (default)
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 (f.e. 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. This limitation will be removed in the future.

 

ip mroute show - list mroute cache entries

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 - 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 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. It isn't work. Don't use it.

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 | LISTofOBJECTS ]

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. F.e. 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 - add new state into xfrm

 

ip xfrm state update - update existing xfrm state

 

ip xfrm state allocspi - allocate SPI 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. Valid algorithms are: enc, auth or comp.

 

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

It can be flush all policies or only those specified with ptype.

dir DIR
directory could be one of these: inp, out or fwd.

SELECTOR
selects for which addresses will be set up the policy. The selector is defined by source and destination address.

UPSPEC
is defined by source port sport, destination port dport, type as number, code also number and key as dotted-quad or number.

dev DEV
specify network device.

index INDEX
the number of indexed policy.

ptype PTYPE
type is set as default on main, could be switch on sub.

action ACTION
is set as default on allow. It could be switch on block.

priority PRIORITY
priority is a number. Default priority is set on 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 on transport, but it could be set on tunnel or beet.

LEVEL
is set as default on required and the other choice is use.

UPSPEC
is specified by sport and dport (for UDP/TCP), type and code (for ICMP; as number) or key (for GRE; as dotted-quad or number).

 

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

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

 

HISTORY

ip was written by Alexey N. Kuznetsov and added in Linux 2.2.  

SEE ALSO

tc(8)
IP Command reference ip-cref.ps
IP tunnels ip-cref.ps
User documentation at http://lartc.org/, but please direct bugreports and patches to: <netdev@vger.kernel.org>

 

AUTHOR

Original Manpage by Michail Litvak <mci@owl.openwall.com>


 

Index

NAME
SYNOPSIS
OPTIONS
IP - COMMAND SYNTAX
OBJECT
COMMAND
ip link - network device configuration
ip link add - add virtual link
ip link delete - delete virtual link
ip link set - change device attributes
ip link show - display device attributes
ip address - protocol address management.
ip address add - add new protocol address.
ip address delete - delete protocol address
ip address show - look at protocol addresses
ip address flush - flush protocol addresses
ip addrlabel - protocol address label management.
ip addrlabel add - add an address label
ip addrlabel del - delete an address label
ip addrlabel list - list address labels
ip addrlabel flush - flush address labels
ip neighbour - neighbour/arp tables management.
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
ip neighbour delete - delete a neighbour entry
ip neighbour show - list neighbour entries
ip neighbour flush - flush neighbour entries
ip route - routing table management
ip route add - add new route
ip route change - change route
ip route replace - change or add new one
ip route delete - delete route
ip route show - list routes
ip route flush - flush routing tables
ip route get - get a single route
ip route save - save routing table information to stdout
ip route restore - restore routing table information from stdin
ip rule - routing policy database management
ip rule add - insert a new rule
ip rule delete - delete a rule
ip rule flush - also dumps all the deleted rules.
ip rule show - list rules
ip maddress - multicast addresses management
ip maddress show - list multicast addresses
ip maddress add - add a multicast address
ip maddress delete - delete a multicast address
ip mroute - multicast routing cache management
ip mroute show - list mroute cache entries
ip tunnel - tunnel configuration
ip tunnel add - add a new tunnel
ip tunnel change - change an existing tunnel
ip tunnel delete - destroy a tunnel
ip tunnel prl - potential router list (ISATAP only)
ip tunnel show - list tunnels
ip monitor and rtmon - state monitoring
ip xfrm - setting xfrm
ip xfrm state add - add new state into xfrm
ip xfrm state update - update existing xfrm state
ip xfrm state allocspi - allocate SPI value
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 monitor - is used for listing all objects or defined group of them.
HISTORY
SEE ALSO
AUTHOR

This document was created by man2html using the manual pages.
Time: 17:31:16 GMT, October 23, 2013

ENGLISH - ENGLISH - ja - pl - ENGLISH

Meet new people