Assuming you have support for network namespaces, iproute2 and iptables, you can accomplish this. Firstly you would want to create a namespace
ip netns add NETNS
and add your custom host file to the directory /etc/netns/NETNS/
(you would need to create this directory)
You would then want to create a virtual ethernet pair to connect the newly created namespace with the main namespace, and configure the interfaces
ip link add veth0 type veth peer name veth1
ip link set veth0 up
ip addr add 172.16.1.0/31 dev veth0
ip netns exec NETNS ip link set lo up
ip netns exec NETNS ip link set veth1 up
ip netns exec NETNS ip addr add 172.16.1.1/31 dev veth1
ip netns exec NETNS ip route add default via 172.16.1.0
and enable the forwarding of IPv4 packets
sysctl net.ipv4.ip_forward=1
and configure the SNAT
iptables -t nat -A POSTROUTING -s 172.16.1.1 -j MASQUERADE
You can then run any command within the network namespace
ip netns exec NETNS COMMAND