
Security News
/Research
node-ipc npm Package Compromised in Supply Chain Attack
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
tuntap-bridge
Advanced tools
A native TUN/TAP interface module for Node.js that works on both macOS and Linux, with enhanced error handling, signal management, and thread safety.
This module provides a Node.js interface to TUN/TAP virtual network devices, allowing you to create and manage network tunnels from JavaScript/TypeScript. It's useful for VPNs, network tunneling, and other network-related applications.
npm install tuntap-bridge
On macOS, the module uses the built-in utun interfaces. No additional setup is required, but you'll need administrator privileges to create and configure the interfaces.
On Linux, the module requires:
TUN/TAP Kernel Module: The TUN/TAP kernel module must be loaded.
# Check if the module is loaded
lsmod | grep tun
# If not loaded, load it
sudo modprobe tun
# To load it automatically at boot
echo "tun" | sudo tee -a /etc/modules
Permissions: The user running the application needs access to /dev/net/tun.
# Option 1: Run your application with sudo
sudo node your-app.js
# Option 2: Add your user to the 'tun' group (if it exists)
sudo usermod -a -G tun your-username
# Option 3: Create a udev rule to set permissions
echo 'KERNEL=="tun", GROUP="your-username", MODE="0660"' | sudo tee /etc/udev/rules.d/99-tuntap.rules
sudo udevadm control --reload-rules
sudo udevadm trigger
iproute2 Package: The ip command is required for configuring interfaces.
# Debian/Ubuntu
sudo apt install iproute2
# CentOS/RHEL
sudo yum install iproute
# Arch Linux
sudo pacman -S iproute2
Development Headers: If you're building from source, you'll need the Linux kernel headers.
# Debian/Ubuntu
sudo apt install linux-headers-$(uname -r)
# CentOS/RHEL
sudo yum install kernel-devel
# Arch Linux
sudo pacman -S linux-headers
import { TunTap } from 'tuntap-bridge';
// Create a TUN device
const tun = new TunTap();
// Open the device
if (tun.open()) {
console.log(`Opened TUN device: ${tun.name}`);
// Configure the device with an IPv6 address and MTU
await tun.configure('fd00::1', 1500);
// Add a route
await tun.addRoute('fd00::/64');
// Read from the device
const data = tun.read(4096);
if (data.length > 0) {
console.log(`Read ${data.length} bytes`);
}
// Write to the device
const buffer = Buffer.from([/* your packet data */]);
const bytesWritten = tun.write(buffer);
console.log(`Wrote ${bytesWritten} bytes`);
// Get interface statistics
const stats = await tun.getStats();
console.log('RX bytes:', stats.rxBytes);
console.log('TX bytes:', stats.txBytes);
// Close the device when done
tun.close();
}
import { TunTap, TunTapError, TunTapPermissionError, TunTapDeviceError } from 'tuntap-bridge';
try {
const tun = new TunTap();
tun.open();
await tun.configure('fe80::1', 1500);
// ... use the device ...
tun.close();
} catch (err) {
if (err instanceof TunTapPermissionError) {
console.error('Permission denied. Please run with sudo.');
} else if (err instanceof TunTapDeviceError) {
console.error('Device error:', err.message);
} else if (err instanceof TunTapError) {
console.error('TUN/TAP error:', err.message);
} else {
console.error('Unexpected error:', err);
}
}
import { connectToTunnelLockdown } from 'tuntap-bridge';
import { Socket } from 'net';
// Create a socket connection to your tunnel endpoint
const socket = new Socket();
socket.connect(port, host, async () => {
try {
// Establish tunnel connection
const tunnel = await connectToTunnelLockdown(socket);
console.log('Tunnel established:', tunnel.Address);
// Add packet consumer
tunnel.addPacketConsumer({
onPacket: (packet) => {
console.log(`${packet.protocol} packet: ${packet.src}:${packet.sourcePort} → ${packet.dst}:${packet.destPort}`);
}
});
// Or use async iteration
for await (const packet of tunnel.getPacketStream()) {
console.log('Received packet:', packet);
}
// Close tunnel when done
await tunnel.closer();
} catch (err) {
console.error('Tunnel error:', err);
}
});
new TunTap(name?: string) - Create a new TUN/TAP device instanceopen(): boolean - Open the TUN deviceclose(): boolean - Close the TUN deviceread(maxSize?: number): Buffer - Read data from the device (default: 4096 bytes)write(data: Buffer): number - Write data to the deviceconfigure(address: string, mtu?: number): Promise<void> - Configure IPv6 address and MTUaddRoute(destination: string): Promise<void> - Add a route to the deviceremoveRoute(destination: string): Promise<void> - Remove a route from the devicegetStats(): Promise<Stats> - Get interface statisticsname: string - The device name (e.g., 'utun0', 'tun0')fd: number - The file descriptor of the deviceTunTapError - Base error class for all TUN/TAP errorsTunTapPermissionError - Thrown when there are permission issuesTunTapDeviceError - Thrown when the device is not available or cannot be openedThe module automatically handles SIGINT and SIGTERM signals for graceful shutdown. All open devices will be closed and network interfaces cleaned up when the process exits.
"TUN/TAP device not available": The TUN/TAP kernel module is not loaded.
sudo modprobe tun"Permission denied" when opening /dev/net/tun: The user doesn't have sufficient permissions.
"Permission denied" when configuring the interface: The user doesn't have sudo privileges.
"Command not found" when configuring the interface: The ip command is not available.
"Failed to create control socket": The application doesn't have sufficient permissions.
"Could not find an available utun device": All utun devices are in use.
Enable debug logging by running your application with the --debug flag:
node your-app.js --debug
MIT
FAQs
Native TUN/TAP interface module for Node.js
The npm package tuntap-bridge receives a total of 31 weekly downloads. As such, tuntap-bridge popularity was classified as not popular.
We found that tuntap-bridge demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.