Skip to content
Named Pipe

Named Pipe

Published: at 12:20 PM

Table of contents

Open Table of contents

What is a Named Pipe?

Named pipes, also known as FIFOs (First In, First Out), are a powerful feature in Unix-like operating systems that allow for unidirectional or bidirectional communication between processes. They function similarly to regular pipes, but with the key difference that they exist as a file in the filesystem, making them accessible by unrelated processes. A command for creating named pipes: mkfifo.

Simple example with cat:

Using netcat as a Proxy

A practical example of using named pipes can be demonstrated with netcat

Standard netcat Proxy

One useful behavior is using netcat as a proxy to redirect both ports and hosts.

nc -lvnp 12345 | nc -v some.website 80

In this command:

When a web browser makes a request to the netcat server on port 12345, the request is forwarded to some.website:80. However, the response from the Website is not sent back to the web browser because standard pipes are unidirectional.

Working Around with Named Pipes

This limitation can be overcome using a named pipe to redirect both input and output.

mkfifo backpipe
nc -l 12345 0<backpipe | nc some.website 80 1>backpipe

In this setup:

This configuration allows bidirectional communication through the named pipe, ensuring that the response from the Website is sent back to the web browser that made the request.

Visual Representation

Normal Pipe

Named Pipe

By using named pipes, you can effectively manage bidirectional data flow between processes, making it a valuable tool for more complex networking tasks and process communication in Unix-like systems.

References