Exemple #1
0
def cleanup():
    print("Stopping processes..")
    for f in os.listdir(config.run_dir):
        if re.search(".pid$", f):
            check_pidfile(os.path.join(config.run_dir, f))

    create_dir(config.run_dir, True)
    # create_dir(env.cmd, True)

    print("Reseting NAT..")
    cmd = """
    iptables -t nat -D POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 0 > /proc/sys/net/ipv4/ip_forward
    iptables -D INPUT -i {2} -j ACCEPT
    iptables -D FORWARD -i {2} -j ACCEPT
    iptables -D OUTPUT -o {2} -j ACCEPT
    """.format(config.subnet, get_default_route()[1], config.bridge)
    runcmd(cmd)

    print("Deleting bridge %s.." % config.bridge)
    cmd = """
    ip link show {0} && ip addr del {1}/{2} dev {0}
    sleep 1
    ip link set {0} down
    sleep 1
    brctl delbr {0}
    """.format(config.bridge, config.gateway, config.net.prefixlen)
    runcmd(cmd)
Exemple #2
0
def cleanup():
    print("Stopping processes..")
    for f in os.listdir(config.run_dir):
        if re.search(".pid$", f):
            check_pidfile(os.path.join(config.run_dir, f))

    create_dir(config.run_dir, True)
    # create_dir(env.cmd, True)

    print("Reseting NAT..")
    cmd = """
    iptables -t nat -D POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 0 > /proc/sys/net/ipv4/ip_forward
    iptables -D INPUT -i {2} -j ACCEPT
    iptables -D FORWARD -i {2} -j ACCEPT
    iptables -D OUTPUT -o {2} -j ACCEPT
    """.format(config.subnet,
               get_default_route()[1], config.bridge)
    runcmd(cmd)

    print("Deleting bridge %s.." % config.bridge)
    cmd = """
    ip link show {0} && ip addr del {1}/{2} dev {0}
    sleep 1
    ip link set {0} down
    sleep 1
    brctl delbr {0}
    """.format(config.bridge, config.gateway, config.net.prefixlen)
    runcmd(cmd)
Exemple #3
0
def cleanup(args, env):
    print("Cleaning up bridge, NAT, resolv.conf...")

    for f in os.listdir(env.run):
        if re.search(".pid$", f):
            check_pidfile(os.path.join(env.run, f))

    create_dir(env.run, True)
    # create_dir(env.cmd, True)
    cmd = """
    iptables -t nat -D POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 0 > /proc/sys/net/ipv4/ip_forward
    iptables -D INPUT -i {2} -j ACCEPT
    iptables -D FORWARD -i {2} -j ACCEPT
    iptables -D OUTPUT -o {2} -j ACCEPT
    """.format(env.subnet, get_default_route()[1], env.bridge)
    os.system(cmd)

    cmd = """
    ip link show {0} && ip addr del {1}/{2} dev {0}
    sleep 1
    ip link set {0} down
    sleep 1
    brctl delbr {0}
    """.format(env.bridge, env.gateway, env.net.prefixlen)
    os.system(cmd)
Exemple #4
0
def cleanup(args, env):
    print("Cleaning up bridge, NAT, resolv.conf...")

    for f in os.listdir(env.run):
        if re.search(".pid$", f):
            check_pidfile(os.path.join(env.run, f))

    create_dir(env.run, True)
    # create_dir(env.cmd, True)
    cmd = """
    iptables -t nat -D POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 0 > /proc/sys/net/ipv4/ip_forward
    iptables -D INPUT -i {2} -j ACCEPT
    iptables -D FORWARD -i {2} -j ACCEPT
    iptables -D OUTPUT -o {2} -j ACCEPT
    """.format(env.subnet,
               get_default_route()[1], env.bridge)
    os.system(cmd)

    cmd = """
    ip link show {0} && ip addr del {1}/{2} dev {0}
    sleep 1
    ip link set {0} down
    sleep 1
    brctl delbr {0}
    """.format(env.bridge, env.gateway, env.net.prefixlen)
    os.system(cmd)
Exemple #5
0
def network(args, env):
    print("Create bridge..Add gateway IP..Activate NAT.."
          "Append NS options to resolv.conf")

    cmd = """
    ! ip link show {0} && brctl addbr {0} && ip link set {0} up
    sleep 1
    ip link set promisc on dev {0}
    ip addr add {1}/{2} dev {0}
    """.format(env.bridge, env.gateway, env.net.prefixlen)
    os.system(cmd)

    cmd = """
    iptables -t nat -A POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 1 > /proc/sys/net/ipv4/ip_forward
    iptables -I INPUT 1 -i {2} -j ACCEPT
    iptables -I FORWARD 1 -i {2} -j ACCEPT
    iptables -I OUTPUT 1 -o {2} -j ACCEPT
    """.format(env.subnet, get_default_route()[1], env.bridge)
    os.system(cmd)
Exemple #6
0
def network():
    print("Creating bridge %s.." % config.bridge)
    print("Add gateway IP %s.." % config.gateway)

    cmd = """
    ! ip link show {0} && brctl addbr {0} && ip link set {0} up
    sleep 1
    ip link set promisc on dev {0}
    ip addr add {1}/{2} dev {0}
    """.format(config.bridge, config.gateway, config.net.prefixlen)
    runcmd(cmd)

    print("Activate NAT..")
    cmd = """
    iptables -t nat -A POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 1 > /proc/sys/net/ipv4/ip_forward
    iptables -I INPUT 1 -i {2} -j ACCEPT
    iptables -I FORWARD 1 -i {2} -j ACCEPT
    iptables -I OUTPUT 1 -o {2} -j ACCEPT
    """.format(config.subnet, get_default_route()[1], config.bridge)
    runcmd(cmd)
Exemple #7
0
def network():
    print("Creating bridge %s.." % config.bridge)
    print("Add gateway IP %s.." % config.gateway)

    cmd = """
    ! ip link show {0} && brctl addbr {0} && ip link set {0} up
    sleep 1
    ip link set promisc on dev {0}
    ip addr add {1}/{2} dev {0}
    """.format(config.bridge, config.gateway, config.net.prefixlen)
    runcmd(cmd)

    print("Activate NAT..")
    cmd = """
    iptables -t nat -A POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 1 > /proc/sys/net/ipv4/ip_forward
    iptables -I INPUT 1 -i {2} -j ACCEPT
    iptables -I FORWARD 1 -i {2} -j ACCEPT
    iptables -I OUTPUT 1 -o {2} -j ACCEPT
    """.format(config.subnet,
               get_default_route()[1], config.bridge)
    runcmd(cmd)
Exemple #8
0
def network(args, env):
    print(
        "Create bridge..Add gateway IP..Activate NAT.."
        "Append NS options to resolv.conf")

    cmd = """
    ! ip link show {0} && brctl addbr {0} && ip link set {0} up
    sleep 1
    ip link set promisc on dev {0}
    ip addr add {1}/{2} dev {0}
    """.format(env.bridge, env.gateway, env.net.prefixlen)
    os.system(cmd)

    cmd = """
    iptables -t nat -A POSTROUTING -s {0} -o {1} -j MASQUERADE
    echo 1 > /proc/sys/net/ipv4/ip_forward
    iptables -I INPUT 1 -i {2} -j ACCEPT
    iptables -I FORWARD 1 -i {2} -j ACCEPT
    iptables -I OUTPUT 1 -o {2} -j ACCEPT
    """.format(env.subnet,
               get_default_route()[1], env.bridge)
    os.system(cmd)
Exemple #9
0
def _autoconf():
    return {
        "name": get_hostname(),
        "ip": get_netinfo()[0],
        "public_iface": get_default_route()[1],
        }
Exemple #10
0
def _autoconf():
    return {
        "name": get_hostname(),
        "ip": get_netinfo()[0],
        "public_iface": get_default_route()[1],
    }