{
    "mode": "man",
    "parameter": "tc-sample",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/tc-sample/8/json",
    "generated": "2026-06-10T16:21:58Z",
    "synopsis": "tc ... action sample rate RATE group GROUP [ trunc SIZE ] [ index INDEX ]\ntc ... action sample index INDEX",
    "sections": {
        "NAME": {
            "content": "sample - packet sampling tc action\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "tc ... action sample rate RATE group GROUP [ trunc SIZE ] [ index INDEX ]\n\ntc ... action sample index INDEX\n\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The sample action allows sampling packets matching classifier.\n\nThe  packets  are  chosen randomly according to the rate parameter, and are sampled using the\npsample generic netlink channel. The user can also specify packet truncation  to  save  user-\nkernel  traffic.  Each  sample  includes some informative metadata about the original packet,\nwhich is sent using netlink attributes, alongside the original packet data.\n\nThe user can either specify the sample action parameters  as  presented  in  the  first  form\nabove, or use an existing sample action using its index, as presented in the second form.\n\n",
            "subsections": []
        },
        "SAMPLED PACKETS METADATA FIELDS": {
            "content": "The  metadata are delivered to userspace applications using the psample generic netlink chan‐\nnel, where each sample includes the following netlink attributes:\n\nPSAMPLEATTRIIFINDEX\nThe input interface index of the packet, if there is one.\n\nPSAMPLEATTROIFINDEX\nThe output interface index of the packet. This field is not relevant on  ingress  sam‐\npling\n\nPSAMPLEATTRORIGSIZE\nThe size of the original packet (before truncation)\n\nPSAMPLEATTRSAMPLEGROUP\nThe psample group the packet was sent to\n\nPSAMPLEATTRGROUPSEQ\nA  sequence number of the sampled packet. This number is incremented with each sampled\npacket of the current psample group\n\nPSAMPLEATTRSAMPLERATE\nThe rate the packet was sampled with\n\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "rate RATE\nThe packet sample rate.  RATE is the expected ratio between observed packets and  sam‐\npled  packets.  For example, RATE of 100 will lead to an average of one sampled packet\nout of every 100 observed.\n\ntrunc SIZE\nUpon set, defines the maximum size of the sampled packets, and  causes  truncation  if\nneeded\n\ngroup GROUP\nThe  psample  group the packet will be sent to. The psample module defines the concept\nof groups, which allows the user to match specific sampled packets in the case of mul‐\ntiple sampling rules, thus identify only the packets that came from a specific rule.\n\nindex INDEX\nIs a unique ID for an action. When creating new action instance, this parameter allows\nto set the new action index. When using existing  action,  this  parameter  allows  to\nspecify the existing action index.  The index must 32bit unsigned integer greater than\nzero.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Sample one of every 100 packets flowing into interface eth0 to psample group 12:\n\ntc qdisc add dev eth0 handle ffff: ingress\ntc filter add dev eth0 parent ffff: matchall \\\naction sample rate 100 group 12 index 19\n\nUse the same action instance to sample eth1 too:\n\ntc qdisc add dev eth1 handle ffff: ingress\ntc filter add dev eth1 parent ffff: matchall \\\naction sample index 19\n\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "tc(8), tc-matchall(8) psample(1)\n\n\n\niproute2                                     31 Jan 2017               Packet sample action in tc(8)",
            "subsections": []
        }
    },
    "summary": "sample - packet sampling tc action",
    "flags": [],
    "examples": [
        "Sample one of every 100 packets flowing into interface eth0 to psample group 12:",
        "tc qdisc add dev eth0 handle ffff: ingress",
        "tc filter add dev eth0 parent ffff: matchall \\",
        "action sample rate 100 group 12 index 19",
        "Use the same action instance to sample eth1 too:",
        "tc qdisc add dev eth1 handle ffff: ingress",
        "tc filter add dev eth1 parent ffff: matchall \\",
        "action sample index 19"
    ],
    "see_also": [
        {
            "name": "tc",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/tc/8/json"
        },
        {
            "name": "tc-matchall",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/tc-matchall/8/json"
        },
        {
            "name": "psample",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/psample/1/json"
        },
        {
            "name": "tc",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/tc/8/json"
        }
    ]
}