Skip to content

Instantly share code, notes, and snippets.

@routevegetable
Last active November 21, 2019 22:10
Show Gist options
  • Save routevegetable/d2394360de9817f4295483db04b9eeaa to your computer and use it in GitHub Desktop.
Save routevegetable/d2394360de9817f4295483db04b9eeaa to your computer and use it in GitHub Desktop.
Shell script to run a program with a fake DNS
#!/bin/bash
# Usage:
# fake_dns 12.23.45.67 fakedomain.com <program> [args...]
set -e
IP=$1
HOST=$2
shift 2
unshare -m
mount --make-private /etc
NEWHOSTS=$(mktemp)
cat /etc/hosts - >$NEWHOSTS <<<"$IP $HOST"
mount --bind $NEWHOSTS /etc/hosts
exec $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment