{
    "mode": "man",
    "parameter": "rtnetlink",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/rtnetlink/7/json",
    "generated": "2026-05-30T05:09:54Z",
    "synopsis": "",
    "sections": {
        "NAME": {
            "content": "rtnetlink - Linux IPv4 routing socket\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "",
            "subsections": [
                {
                    "name": "#include <asm/types.h>",
                    "content": "#include <linux/iflink.h>"
                },
                {
                    "name": "#include <linux/netlink.h>",
                    "content": ""
                },
                {
                    "name": "#include <linux/rtnetlink.h>",
                    "content": ""
                },
                {
                    "name": "#include <sys/socket.h>",
                    "content": "rtnetlinksocket = socket(AFNETLINK, int sockettype, NETLINKROUTE);\n"
                }
            ]
        },
        "DESCRIPTION": {
            "content": "Rtnetlink  allows  the kernel's routing tables to be read and altered.  It is used within the\nkernel to communicate between various subsystems, though this usage is not  documented  here,\nand  for  communication with user-space programs.  Network routes, IP addresses, link parame‐\nters, neighbor setups, queueing disciplines, traffic classes and packet classifiers  may  all\nbe controlled through NETLINKROUTE sockets.  It is based on netlink messages; see netlink(7)\nfor more information.\n",
            "subsections": [
                {
                    "name": "Routing attributes",
                    "content": "Some rtnetlink messages have optional attributes after the initial header:\n\nstruct rtattr {\nunsigned short rtalen;    /* Length of option */\nunsigned short rtatype;   /* Type of option */\n/* Data follows */\n};\n\nThese attributes should be manipulated using only the RTA* macros  or  libnetlink,  see  rt‐‐\nnetlink(3).\n"
                },
                {
                    "name": "Messages",
                    "content": "Rtnetlink consists of these message types (in addition to standard netlink messages):\n\nRTMNEWLINK, RTMDELLINK, RTMGETLINK\nCreate, remove, or get information about a specific network interface.  These messages\ncontain an ifinfomsg structure followed by a series of rtattr structures.\n\nstruct ifinfomsg {\nunsigned char  ififamily; /* AFUNSPEC */\nunsigned short ifitype;   /* Device type */\nint            ifiindex;  /* Interface index */\nunsigned int   ififlags;  /* Device flags  */\nunsigned int   ifichange; /* change mask */\n};\n\nififlags contains the device flags, see netdevice(7); ifiindex is the unique  inter‐\nface  index  (since  Linux  3.7,  it  is  possible  to  feed  a nonzero value with the\nRTMNEWLINK message, thus creating a link with the given ifindex); ifichange  is  re‐\nserved for future use and should be always set to 0xFFFFFFFF.\n\nRouting attributes\nrtatype         Value type         Description\n─────────────────────────────────────────────────────────\nIFLAUNSPEC      -                  unspecified\nIFLAADDRESS     hardware address   interface L2 address\nIFLABROADCAST   hardware address   L2 broadcast address\nIFLAIFNAME      asciiz string      Device name\nIFLAMTU         unsigned int       MTU of the device\nIFLALINK        int                Link type\n\nIFLAQDISC       asciiz string      Queueing discipline\nIFLASTATS       see below          Interface Statistics\n\nThe  value  type  for IFLASTATS is struct rtnllinkstats (struct netdevicestats in\nLinux 2.4 and earlier).\n\nRTMNEWADDR, RTMDELADDR, RTMGETADDR\nAdd, remove, or receive information about an IP address associated with an  interface.\nIn  Linux  2.2,  an interface can carry multiple IP addresses, this replaces the alias\ndevice concept in 2.0.  In Linux 2.2, these messages support IPv4 and IPv6  addresses.\nThey contain an ifaddrmsg structure, optionally followed by rtattr routing attributes.\n\nstruct ifaddrmsg {\nunsigned char ifafamily;    /* Address type */\nunsigned char ifaprefixlen; /* Prefixlength of address */\nunsigned char ifaflags;     /* Address flags */\nunsigned char ifascope;     /* Address scope */\nunsigned int  ifaindex;     /* Interface index */\n};\n\nifafamily  is  the address family type (currently AFINET or AFINET6), ifaprefixlen\nis the length of the address mask of the address if defined for the family  (like  for\nIPv4),  ifascope is the address scope, ifaindex is the interface index of the inter‐\nface the address is associated with.  ifaflags is a flag word of IFAFSECONDARY  for\nsecondary  address  (old alias interface), IFAFPERMANENT for a permanent address set\nby the user and other undocumented flags.\n\nAttributes\nrtatype        Value type             Description\n─────────────────────────────────────────────────────────────\nIFAUNSPEC      -                      unspecified\nIFAADDRESS     raw protocol address   interface address\nIFALOCAL       raw protocol address   local address\nIFALABEL       asciiz string          name of the interface\nIFABROADCAST   raw protocol address   broadcast address\nIFAANYCAST     raw protocol address   anycast address\nIFACACHEINFO   struct ifacacheinfo   Address information\n\nRTMNEWROUTE, RTMDELROUTE, RTMGETROUTE\nCreate, remove, or receive information about a network route.  These messages  contain\nan  rtmsg  structure  with  an  optional sequence of rtattr structures following.  For\nRTMGETROUTE, setting rtmdstlen and rtmsrclen to 0 means you get all  entries  for\nthe specified routing table.  For the other fields, except rtmtable and rtmprotocol,\n0 is the wildcard.\n\nstruct rtmsg {\nunsigned char rtmfamily;   /* Address family of route */\nunsigned char rtmdstlen;  /* Length of destination */\nunsigned char rtmsrclen;  /* Length of source */\nunsigned char rtmtos;      /* TOS filter */\nunsigned char rtmtable;    /* Routing table ID;\nsee RTATABLE below */\nunsigned char rtmprotocol; /* Routing protocol; see below */\nunsigned char rtmscope;    /* See below */\nunsigned char rtmtype;     /* See below */\n\nunsigned int  rtmflags;\n};\n\nrtmtype          Route type\n───────────────────────────────────────────────────────────\nRTNUNSPEC        unknown route\nRTNUNICAST       a gateway or direct route\nRTNLOCAL         a local interface route\n\n\nRTNBROADCAST     a  local  broadcast  route  (sent  as  a\nbroadcast)\nRTNANYCAST       a  local broadcast route (sent as a uni‐\ncast)\nRTNMULTICAST     a multicast route\nRTNBLACKHOLE     a packet dropping route\nRTNUNREACHABLE   an unreachable destination\nRTNPROHIBIT      a packet rejection route\nRTNTHROW         continue routing lookup in another table\nRTNNAT           a network address translation rule\nRTNXRESOLVE      refer to an external resolver  (not  im‐\nplemented)\n\nrtmprotocol      Route origin\n────────────────────────────────────────────────────\nRTPROTUNSPEC     unknown\nRTPROTREDIRECT   by  an  ICMP  redirect (currently\nunused)\nRTPROTKERNEL     by the kernel\nRTPROTBOOT       during boot\nRTPROTSTATIC     by the administrator\n\nValues larger than RTPROTSTATIC are not interpreted by the kernel, they are just  for\nuser  information.   They may be used to tag the source of a routing information or to\ndistinguish between multiple routing daemons.  See <linux/rtnetlink.h> for the routing\ndaemon identifiers which are already assigned.\n\nrtmscope is the distance to the destination:\n\nRTSCOPEUNIVERSE   global route\nRTSCOPESITE       interior  route  in the local au‐\ntonomous system\nRTSCOPELINK       route on this link\nRTSCOPEHOST       route on the local host\nRTSCOPENOWHERE    destination doesn't exist\n\nThe values between RTSCOPEUNIVERSE and RTSCOPESITE are available to the user.\n\nThe rtmflags have the following meanings:\n\nRTMFNOTIFY     if the route changes, notify the  user  via\nrtnetlink\nRTMFCLONED     route is cloned from another route\nRTMFEQUALIZE   a multipath equalizer (not yet implemented)\n\nrtmtable specifies the routing table\n\nRTTABLEUNSPEC    an unspecified routing table\nRTTABLEDEFAULT   the default table\nRTTABLEMAIN      the main table\nRTTABLELOCAL     the local table\n\nThe user may assign arbitrary values between RTTABLEUNSPEC and RTTABLEDEFAULT.\n\nAttributes\nrtatype        Value type            Description\n────────────────────────────────────────────────────────────────\nRTAUNSPEC      -                     ignored\nRTADST         protocol address      Route destination address\nRTASRC         protocol address      Route source address\nRTAIIF         int                   Input interface index\nRTAOIF         int                   Output interface index\nRTAGATEWAY     protocol address      The gateway of the route\nRTAPRIORITY    int                   Priority of route\nRTAPREFSRC     protocol address      Preferred source address\nRTAMETRICS     int                   Route metric\nRTAMULTIPATH                         Multipath nexthop data br\n(see below).\nRTAPROTOINFO                         No longer used\nRTAFLOW        int                   Route realm\nRTACACHEINFO   struct rtacacheinfo  (see linux/rtnetlink.h)\nRTASESSION                           No longer used\nRTAMPALGO                           No longer used\nRTATABLE       int                   Routing table ID; if set,\nrtmtable is ignored\nRTAMARK        int\nRTAMFCSTATS   struct rtamfcstats  (see linux/rtnetlink.h)\nRTAVIA         struct rtvia          Gateway in  different  AF\n(see below)\nRTANEWDST      protocol address      Change packet destination\naddress\nRTAPREF        char                  RFC4191 IPv6 router pref‐\nerence (see below)\nRTAENCAPTYPE  short                 Encapsulation type for\nlwtunnels (see below)\nRTAENCAP                             Defined by RTAENCAPTYPE\nRTAEXPIRES     int                   Expire   time   for  IPv6\nroutes (in seconds)\n\nRTAMULTIPATH contains several packed instances  of  struct  rtnexthop  together  with\nnested RTAs (RTAGATEWAY):\n\nstruct rtnexthop {\nunsigned short rtnhlen;     /* Length of struct + length\nof RTAs */\nunsigned char  rtnhflags;   /* Flags (see\nlinux/rtnetlink.h) */\nunsigned char  rtnhhops;    /* Nexthop priority */\nint            rtnhifindex; /* Interface index for this\nnexthop */\n}\n\nThere  exist  a  bunch  of RTNH* macros similar to RTA* and NLHDR* macros useful to\nhandle these structures.\n\nstruct rtvia {\nunsigned short rtviafamily;\nunsigned char  rtviaaddr[0];\n};\n\nrtviaaddr is the address, rtviafamily is its family type.\n\nRTAPREF may contain  values  ICMPV6ROUTERPREFLOW,  ICMPV6ROUTERPREFMEDIUM,  and\nICMPV6ROUTERPREFHIGH defined incw <linux/icmpv6.h>.\n\nRTAENCAPTYPE may contain values LWTUNNELENCAPMPLS, LWTUNNELENCAPIP, LWTUNNELEN‐‐\nCAPILA, or LWTUNNELENCAPIP6 defined in <linux/lwtunnel.h>.\n\nFill these values in!\n\nRTMNEWNEIGH, RTMDELNEIGH, RTMGETNEIGH\nAdd, remove, or receive information about a neighbor table entry (e.g., an ARP entry).\nThe message contains an ndmsg structure.\n\nstruct ndmsg {\nunsigned char ndmfamily;\nint           ndmifindex;  /* Interface index */\nu16         ndmstate;    /* State */\nu8          ndmflags;    /* Flags */\nu8          ndmtype;\n};\n\nstruct ndacacheinfo {\nu32         ndmconfirmed;\nu32         ndmused;\nu32         ndmupdated;\nu32         ndmrefcnt;\n};\n\nndmstate is a bit mask of the following states:\n\nNUDINCOMPLETE   a currently resolving cache entry\nNUDREACHABLE    a confirmed working cache entry\nNUDSTALE        an expired cache entry\nNUDDELAY        an entry waiting for a timer\nNUDPROBE        a cache entry that is currently reprobed\nNUDFAILED       an invalid cache entry\nNUDNOARP        a device with no destination cache\nNUDPERMANENT    a static entry\n\nValid ndmflags are:\n\nNTFPROXY    a proxy arp entry\nNTFROUTER   an IPv6 router\n\nThe rtattr struct has the following meanings for the rtatype field:\n\nNDAUNSPEC      unknown type\nNDADST         a neighbor cache n/w layer destination address\nNDALLADDR      a neighbor cache link layer address\n\nNDACACHEINFO   cache statistics\n\nIf the rtatype field is NDACACHEINFO, then a struct ndacacheinfo header follows.\n\nRTMNEWRULE, RTMDELRULE, RTMGETRULE\nAdd, delete, or retrieve a routing rule.  Carries a struct rtmsg\n\nRTMNEWQDISC, RTMDELQDISC, RTMGETQDISC\nAdd,  remove,  or  get a queueing discipline.  The message contains a struct tcmsg and\nmay be followed by a series of attributes.\n\nstruct tcmsg {\nunsigned char    tcmfamily;\nint              tcmifindex;   /* interface index */\nu32            tcmhandle;    /* Qdisc handle */\nu32            tcmparent;    /* Parent qdisc */\nu32            tcminfo;\n};\n\nAttributes\nrtatype     Value type           Description\n────────────────────────────────────────────────────────────────\nTCAUNSPEC   -                    unspecified\nTCAKIND     asciiz string        Name of queueing discipline\nTCAOPTIONS  byte sequence        Qdisc-specific options follow\nTCASTATS    struct tcstats      Qdisc statistics\nTCAXSTATS   qdisc-specific       Module-specific statistics\nTCARATE     struct tcestimator  Rate limit\n\nIn addition, various other qdisc-module-specific attributes are allowed.  For more in‐\nformation see the appropriate include files.\n\nRTMNEWTCLASS, RTMDELTCLASS, RTMGETTCLASS\nAdd,  remove,  or  get  a traffic class.  These messages contain a struct tcmsg as de‐\nscribed above.\n\nRTMNEWTFILTER, RTMDELTFILTER, RTMGETTFILTER\nAdd, remove, or receive information about a traffic filter.  These messages contain  a\nstruct tcmsg as described above.\n"
                }
            ]
        },
        "VERSIONS": {
            "content": "rtnetlink is a new feature of Linux 2.2.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "This manual page is incomplete.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "cmsg(3), rtnetlink(3), ip(7), netlink(7)\n",
            "subsections": []
        },
        "COLOPHON": {
            "content": "This  page  is  part  of  release  5.10 of the Linux man-pages project.  A description of the\nproject, information about reporting bugs, and the latest version of this page, can be  found\nat https://www.kernel.org/doc/man-pages/.\n\n\n\nLinux                                        2020-06-09                                 RTNETLINK(7)",
            "subsections": []
        }
    },
    "summary": "rtnetlink - Linux IPv4 routing socket",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "cmsg",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/cmsg/3/json"
        },
        {
            "name": "ip",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ip/7/json"
        },
        {
            "name": "netlink",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/netlink/7/json"
        }
    ]
}