Skip to content

Instantly share code, notes, and snippets.

View alpominth's full-sized avatar

Hamilton P. alpominth

  • A city in Spain
  • 05:19 (UTC +02:00)
View GitHub Profile
@alpominth
alpominth / README.md
Last active June 2, 2025 18:26
Port forwarder for network namespaces: forward TCP/UDP/SCTP ports from one netns to another easily.

netns-pf

This is a simple TCP/UDP/SCTP port forwarder for network namespaces, so it will require root privileges.

Compiling:

Download all files from this gist in a folder and run:

$ go build ./netns-pf.go

@alpominth
alpominth / rt_table123.sh
Last active July 19, 2024 12:26
rt_table123.sh - Easily create a firewall mark for an additional routing table and expose the IP adress(es) of a network interface to the system
#!/bin/bash
FW_MARK="$((RANDOM%2147483646 + 1))"
if [ "$(ip -4 rule show fwmark ${FW_MARK})" ] || [ "$(ip -6 rule show fwmark ${FW_MARK})" ]; then
while [ "$(ip -4 rule show fwmark ${FW_MARK})" ] || [ "$(ip -6 rule show fwmark ${FW_MARK})" ]; do
FW_MARK="$((RANDOM%2147483646 + 1))"
done
fi
TABLE="$((RANDOM%2147483396 + 1))"
if [ ! "$(ip -4 route show table ${TABLE} 2>/dev/null || echo 1)" = "1" ] || [ ! "$(ip -6 route show table ${TABLE} 2>/dev/null || echo 1)" = "1" ]; then
@alpominth
alpominth / ip_alias123.sh
Created March 31, 2024 19:27
ip_alias123.sh - Create an IP alias (like 10.1.1.1) for any network interface and any of its local IP addresses
#!/bin/bash
FW_MARK="$((RANDOM%2147483646 + 1))"
if [ "$(ip -4 rule show fwmark ${FW_MARK})" ] || [ "$(ip -6 rule show fwmark ${FW_MARK})" ]; then
while [ "$(ip -4 rule show fwmark ${FW_MARK})" ] || [ "$(ip -6 rule show fwmark ${FW_MARK})" ]; do
FW_MARK="$((RANDOM%2147483646 + 1))"
done
fi
TABLE="$((RANDOM%2147483396 + 1))"
if [ ! "$(ip -4 route show table ${TABLE} 2>/dev/null || echo 1)" = "1" ] || [ ! "$(ip -6 route show table ${TABLE} 2>/dev/null || echo 1)" = "1" ]; then