Skip to content

Instantly share code, notes, and snippets.

@pianomanfrazier
Last active June 14, 2017 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pianomanfrazier/51d89c96e1e3fec847c57108b31d38cd to your computer and use it in GitHub Desktop.
Save pianomanfrazier/51d89c96e1e3fec847c57108b31d38cd to your computer and use it in GitHub Desktop.
Setup virtual box VM host only adapter networking. Works for Debian 3.16 64 bit.
#!/usr/bin/env python
"""This sets up a Debian VM for host-only network adapter"""
import argparse
from subprocess import call
parser = argparse.ArgumentParser(description="setup VM for host only networking")
parser.add_argument('--ip', '-ip', required=True, help='an ip address for host only adapter')
args = vars(parser.parse_args())
ifconfig = "ifconfig eth1 {} netmask 255.255.255.0 up".format(args['ip'])
interface = """# The host-only network interface
auto eth1
iface eth1 inet static
address {}
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255""".format(args['ip'])
host = "{}\tlocalhost".format(args['ip'])
#call(ifconfig, shell=True)
with open("/etc/network/interfaces", "a") as fout:
fout.write(interface)
with open("/etc/hosts", "a") as fout:
fout.write(host)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment