tcprewrite - Man Page
Rewrite the packets in a pcap file.
Synopsis
tcprewrite [OPTION]...
Description
Tcprewrite is a tool to rewrite packets stored in pcap(3) file format, such as created by tools such as tcpdump(1) and wireshark(1). Once a pcap file has had it’s packets rewritten, they can be replayed back out on the network using tcpreplay(1).
The timestamp resolution of the input is preserved: nanosecond pcap and pcapng input produce a nanosecond resolution pcap output file, everything else produces the classic microsecond format (requires libpcap >= 1.5.1).
tcprewrite currently supports reading the following DLT types:
- DLT_C_HDLC
aka Cisco HDLC
- DLT_EN10MB
aka Ethernet
- DLT_LINUX_SLL
aka Linux Cooked Socket
- DLT_LINUX_SLL2
aka Linux Cooked Socket v2
- DLT_RAW
aka RAW IP
- DLT_NULL
aka BSD Loopback
- DLT_LOOP
aka OpenBSD Loopback
- DLT_IEEE802_11
aka 802.11a/b/g
- DLT_IEEE802_11_RADIO
aka 802.11a/b/g with Radiotap headers
- DLT_JUNIPER_ETHER
aka Juniper Encapsulated Ethernet
- DLT_PPP_SERIAL
aka PPP over Serial
Please see the --dlt option for supported DLT types for writing.
The packet editing features of tcprewrite which distinguish between "client" and "server" traffic requires a tcpprep(1) cache file.
For more details, please see the Tcpreplay Manual at: http://tcpreplay.appneta.com
Options
- -r, --portmap=string
Rewrite TCP/UDP ports. May appear up to 9999 times.
Specify a list of comma delimited port mappings consisting of colon delimited port number pairs. Each colon delimited port pair consists of the port to match followed by the port number to rewrite.
Examples:
--portmap=80:8000 --portmap=8080:80 # 80->8000 and 8080->80 --portmap=8000,8080,88888:80 # 3 different ports become 80 --portmap=8000-8999:80 # ports 8000 to 8999 become 80
- -s, --seed=number
Randomize src/dst IPv4/v6 addresses w/ given seed. Cannot be combined with: --fuzz-seed.
Causes the source and destination IPv4/v6 addresses to be pseudo randomized but still maintain client/server relationships. Since the randomization is deterministic based on the seed, you can reuse the same seed value to recreate the traffic.
- -N, --pnat=string
Rewrite IPv4/v6 addresses using pseudo-NAT. May appear up to 2 times. Cannot be combined with: --srcipmap.
Takes a comma delimited series of colon delimited CIDR netblock pairs. Each netblock pair is evaluated in order against the IP addresses. If the IP address in the packet matches the first netblock, it is rewritten using the second netblock as a mask against the high order bits.
IPv4 Example:
--pnat=192.168.0.0/16:10.77.0.0/16,172.16.0.0/12:10.1.0.0/24
IPv6 Example:
--pnat=[2001:db8::/32]:[dead::/16],[2001:db8::/32]:[::ffff:0:0/96]
- -S, --srcipmap=string
Rewrite source IPv4/v6 addresses using pseudo-NAT. Cannot be combined with: --pnat.
Works just like the --pnat option, but only affects the source IP addresses in the IPv4/v6 header.
- -D, --dstipmap=string
Rewrite destination IPv4/v6 addresses using pseudo-NAT. Cannot be combined with: --pnat.
Works just like the --pnat option, but only affects the destination IP addresses in the IPv4/v6 header.
- -e, --endpoints=string
Rewrite IP addresses to be between two endpoints. Requires: --cachefile.
Takes a pair of colon delimited IPv4/v6 addresses which will be used to rewrite all traffic to appear to be between the two IP addresses.
IPv4 Example:
--endpoints=172.16.0.1:172.16.0.2
IPv6 Example:
--endpoints=[2001:db8::dead:beef]:[::ffff:0:0:ac:f:0:2]
- --tcp-sequence=number
Change TCP Sequence (and ACK) numbers /w given seed. Range: 1 to any. Default:
0.Change all TCP sequence numbers, and related sequence-acknowledgement numbers. They will be shifted by a random amount based on the provided seed.
- -b, --skipbroadcast
Skip rewriting broadcast/multicast IPv4/v6 addresses.
By default --seed, --pnat and --endpoints will rewrite broadcast and multicast IPv4/v6 and MAC addresses. Setting this flag will keep broadcast/multicast IPv4/v6 and MAC addresses from being rewritten.
- -C, --fixcsum
Force recalculation of IPv4/TCP/UDP header checksums.
Causes each IPv4/v6 packet to have their checksums recalculated and fixed. Automatically enabled for packets modified with
--seed,--pnat,--endpointsor--fixlen.- --fixhdrlen
Alter IP/TCP header len to match packet length.
By default, tcpreplay will send packets with the original packet length, However, you may want the packet length revised to minimum packet size. Using this option, tcpreplay will rewrite (fix) the packet length, and recalculate checksums when packet length changes. Caution: undesired packet changes may occur when this option is specified.
- -m, --mtu=number
Override default MTU length (1500 bytes). Range: 1 to MAX_SNAPLEN.
Override the default 1500 byte MTU size for determining the maximum padding length (--fixlen=pad) or when truncating (--mtu-trunc).
- --mtu-trunc
Truncate packets larger then specified MTU.
Similar to --fixlen, this option will truncate data in packets from Layer 3 and above to be no larger then the MTU.
- -E, --efcs
Remove Ethernet checksums (FCS) from end of frames.
Note, this option is pretty dangerous! We do not actually check to see if a FCS actually exists in the frame, we just blindly delete the last 4 bytes. Hence, you should only use this if you know know that your OS provides the FCS when reading raw packets.
- --ttl=string
Modify the IPv4/v6 TTL/Hop Limit.
Allows you to modify the TTL/Hop Limit of all the IPv4/v6 packets. Specify a number to hard-code the value or +/-value to increase or decrease by the value provided (limited to 1-255).
Examples:
--ttl=10 --ttl=+7 --ttl=-64
- --tos=number
Set the IPv4 TOS/DiffServ/ECN byte. Range: 0 to 255.
Allows you to override the TOS (also known as DiffServ/ECN) value in IPv4.
- --tclass=number
Set the IPv6 Traffic Class byte. Range: 0 to 255.
Allows you to override the IPv6 Traffic Class field.
- --flowlabel=number
Set the IPv6 Flow Label. Range: 0 to 1048575.
Allows you to override the 20bit IPv6 Flow Label field. Has no effect on IPv4 packets.
- -F, --fixlen=string
Pad or truncate packet data to match header length.
Packets may be truncated during capture if the snaplen is smaller then the packet. This option allows you to modify the packet to pad the packet back out to the size stored in the IPv4/v6 header or rewrite the IP header total length to reflect the stored packet length.
- pad
Truncated packets will be padded out so that the packet length matches the IPv4 total length
- trunc
Truncated packets will have their IPv4 total length field rewritten to match the actual packet length
- del
Delete the packet
- --fuzz-seed=number
Fuzz 1 in X packets. Edit bytes, length, or emulate packet drop. Range: 0 to any. Default:
0.This fuzzing was designed as to test layer 7 protocols such as voip protocols. It modifies randomly 1 out of X packets (where X = --fuzz-factor) in order for stateful protocols to cover more of their code. The random fuzzing actions focus on data start and end because it often is the part of the data application protocols base their decisions on.
Possible fuzzing actions list: * drop packet * reduce packet size * edit packet Bytes:
* Not all Bytes have the same probability of appearance in real life. Replace with 0x00, 0xFF, or a random byte with equal likelihood. * Not all Bytes have the same significance in a packet. Replace the start, the end, or the middle of the packet with equal likelihood.- do nothing (7 out of 8 packets)
- --fuzz-factor=number
Set the Fuzz 1 in X packet ratio (default 1 in 8 packets). Range: 1 to any. Default:
8. Requires: --fuzz-seed.Sets the ratio of for --fuzz-seed option. By default this value is 8, which means 1 in 8 packets are modified by fuzzing. Note that this ratio is based on the random number generated by the supplied fuzz seed. Therefore by default you cannot expect that exactly every eighth packet will be modified.
- --skipl2broadcast
Skip rewriting broadcast/multicast Layer 2 addresses.
By default, editing Layer 2 addresses will rewrite broadcast and multicast MAC addresses. Setting this flag will keep broadcast/multicast MAC addresses from being rewritten.
- --dlt=string
Override output DLT encapsulation.
By default, no DLT (data link type) conversion will be made. To change the DLT type of the output pcap, select one of the following values:
- enet
Ethernet aka DLT_EN10MB
- hdlc
Cisco HDLC aka DLT_C_HDLC
- jnpr_eth
Juniper Ethernet DLT_C_JNPR_ETHER
- pppserial
PPP Serial aka DLT_PPP_SERIAL
- user
User specified Layer 2 header and DLT type
- --enet-dmac=string
Override destination ethernet MAC addresses.
Takes a pair of comma deliminated ethernet MAC addresses which will replace the destination MAC address of outbound packets. The first MAC address will be used for the server to client traffic and the optional second MAC address will be used for the client to server traffic.
Example:
--enet-dmac=00:12:13:14:15:16,00:22:33:44:55:66
- --enet-smac=string
Override source ethernet MAC addresses.
Takes a pair of comma deliminated ethernet MAC addresses which will replace the source MAC address of outbound packets. The first MAC address will be used for the server to client traffic and the optional second MAC address will be used for the client to server traffic.
Example:
--enet-smac=00:12:13:14:15:16,00:22:33:44:55:66
- --enet-subsmac=string
Substitute MAC addresses. May appear up to 9999 times.
Allows you to rewrite ethernet MAC addresses of packets. It takes comma delimited pair or MACs address and rewrites all occurrences of the first MAC with the value of the second MAC. Example:
--enet-subsmac=00:12:13:14:15:16,00:22:33:44:55:66
- --enet-mac-seed=number
Randomize MAC addresses. Cannot be combined with: --enet-smac, --enet-dmac, --enet-subsmac.
Allows you to randomize ethernet MAC addresses of packets, mostly like what --seed option does for IPv4/IPv6 addresses.
- --enet-mac-seed-keep-bytes=number
Randomize MAC addresses. Range: 1 to 6. Requires: --enet-mac-seed.
Keep some bytes untouched when usinging --enet-mac-seed option.
- --enet-vlan=string
Specify ethernet 802.1q VLAN tag mode.
Allows you to rewrite ethernet frames to add a 802.1q header to standard 802.3 ethernet headers or remove the 802.1q VLAN tag information.
- add
Adds an 802.1q VLAN header to the existing 802.3 ethernet header. If a VLAN header already exists, a new VLAN header is added outside of the existing header.
Note that you will be allowed to run this option multiple times to create more than 2 VLAN headers, however those packets will be valid. At most you should have 2 X 802.1q VLAN tags, or outer an 802.1ad and an inner 802.1q VLAN tag.
- del
Rewrites the existing 802.1q VLAN header as an 802.3 ethernet header
- --enet-vlan-tag=number
Specify the new ethernet 802.1q VLAN tag value. Range: 0 to 4095. Requires: --enet-vlan.
Mandatory when --enet-vlan=add is used on packets that are not already VLAN tagged.
- --enet-vlan-cfi=number
Specify the ethernet 802.1q VLAN CFI value. Range: 0 to 1. Requires: --enet-vlan.
When omitted, the CFI bit of an existing VLAN header is preserved; a newly added tag on a previously untagged packet defaults to 0 (a one-time notice is printed).
- --enet-vlan-pri=number
Specify the ethernet 802.1q VLAN priority. Range: 0 to 7. Requires: --enet-vlan.
When omitted, the priority of an existing VLAN header is preserved; a newly added tag on a previously untagged packet defaults to 0 (a one-time notice is printed).
- --enet-vlan-proto=string
Specify VLAN tag protocol 802.1q or 802.1ad.
Allows you to specify the protocol of the added VLAN tags.
- 802.1q
Specifies that 802.1q VLAN headers are to be added. This is the default.
- 802.1ad
Specifies that 802.1ad Q-in-Q VLAN headers are to be added. To make valid packets, input packets must already have 802.1q VLAN headers.
- --hdlc-control=number
Specify HDLC control value.
The Cisco HDLC header has a 1 byte "control" field. Apparently this should always be 0, but if you can use any 1 byte value.
- --hdlc-address=number
Specify HDLC address.
The Cisco HDLC header has a 1 byte "address" field which has two valid values:
- 0x0F
Unicast
- 0xBF
Broadcast
You can however specify any single byte value.
- --user-dlt=number
Set output file DLT type.
Set the DLT value of the output pcap file.
- --user-dlink=string
Rewrite Data-Link layer with user specified data. May appear up to 2 times.
Provide a series of comma deliminated hex values which will be used to rewrite or create the Layer 2 header of the packets. The first instance of this argument will rewrite both server and client traffic, but if this argument is specified a second time, it will be used for the client traffic.
Example:
--user-dlink=01,02,03,04,05,06,00,1A,2B,3C,4D,5E,6F,08,00
- -d, --dbug=number
Enable debugging output. Range: 0 to 5. Default:
0.If configured with --enable-debug, then you can specify a verbosity level for debugging output. Higher numbers increase verbosity.
- -i, --infile=string
Input pcap file to be processed. This option is required.
- -o, --outfile=string
Output pcap file. This option is required.
- -c, --cachefile=string
Split traffic via tcpprep cache file.
Use tcpprep cache file to split traffic based upon client/server relationships.
- -v, --verbose
Print decoded packets via tcpdump to STDOUT.
- -A, --decode=string
Arguments passed to tcpdump decoder. Requires: --verbose.
When enabling verbose mode (-v) you may also specify one or more additional arguments to pass to
tcpdumpto modify the way packets are decoded. By default, -n and -l are used. Be sure to quote the arguments so that they are not interpreted by tcprewrite. Please see the tcpdump(1) man page for a complete list of options.- --fragroute=string
Parse fragroute configuration file.
Enable advanced evasion techniques using the built-in fragroute(8) engine. See the fragroute(8) man page for more details. Important: tcprewrite does not support the delay, echo or print commands.
- --fragdir=string
Which flows to apply fragroute to: c2s, s2c, both. Requires: --cachefile.
Apply the fragroute engine to packets going c2s, s2c or both when using a cache file.
- --skip-soft-errors
Skip writing packets with soft errors.
In some cases, packets can not be decoded or the requested editing is not possible. Normally these packets are written to the output file unedited so that tcpprep cache files can still be used, but if you wish, these packets can be suppressed.
One example of this is 802.11 management frames which contain no data.
- -V, --version
Print version information.
- -h, --less-help
Display less usage information and exit.
- -w, --suppress-warnings
suppress printing warning messages.
- -H, --help
Display usage information and exit.
- --more-help
Pass the extended usage information through a pager.
- --save-opts[=string]
Save the current option state to a config file.
- --load-opts=string, --no-load-opts
Load options from a config file; --no-load-opts disables this.
Option Presets
Any option that is not marked as not presettable may be preset by loading values from configuration ("RC" or ".INI") file(s). The homerc file is $$/, unless that is a directory; in that case .tcprewriterc is searched for within it.
Files
See Option Presets for configuration files.
Exit Status
One of the following exit values will be returned:
0 (EXIT_SUCCESS)
Successful program execution.
1 (EXIT_FAILURE)
The operation failed or the command syntax was not valid.
66 (EX_NOINPUT)
A specified configuration file could not be loaded.
70 (EX_SOFTWARE)
libopts had an internal operational error. Please report it to autogen-users@lists.sourceforge.net. Thank you.
Authors
Copyright 2013-2026 Fred Klassen - AppNeta by Broadcom
Copyright 2000-2012 Aaron Turner
For support please use the tcpreplay-users@lists.sourceforge.net mailing list.
The latest version of this software is always available from: http://tcpreplay.appneta.com/
Copyright
Copyright © 2000-2026 Aaron Turner and Fred Klassen, all rights reserved. This program is released under the terms of the GNU General Public License, version 3 or later.
Bugs
Please send bug reports to: tcpreplay-users@lists.sourceforge.net
Notes
This manual page was generated from the tcprewrite option definitions.