Last active
November 21, 2019 22:10
-
-
Save routevegetable/d2394360de9817f4295483db04b9eeaa to your computer and use it in GitHub Desktop.
Shell script to run a program with a fake DNS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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