예제 #1
0
 def clear_rules():
     # type: () -> None
     """Clear all rules."""
     execute_commands([
         "iptables -F", "iptables -X", "iptables -t nat -F",
         "iptables -t nat -X"
     ])
예제 #2
0
 def clear_rules():
     # type: () -> None
     """Clear all rules."""
     execute_commands([
         "iptables -F", "iptables -X", "iptables -t nat -F",
         "iptables -t nat -X"
     ])
예제 #3
0
 def nat(internal_interface, external_interface):
     # type: (str, str) -> None
     """Do NAT."""
     execute_commands([
         "iptables -t nat -A POSTROUTING -o {} -j MASQUERADE".format(
             external_interface),
         "iptables -A FORWARD -i {} -o {} -j ACCEPT".format(
             internal_interface, external_interface)
     ])
예제 #4
0
 def nat(internal_interface, external_interface):
     # type: (str, str) -> None
     """Do NAT."""
     execute_commands([
         "iptables -t nat -A POSTROUTING -o {} -j MASQUERADE".format(
             external_interface),
         "iptables -A FORWARD -i {} -o {} -j ACCEPT".format(
             internal_interface, external_interface)
     ])
예제 #5
0
    def redirect_requests_localhost():
        # type: () -> None
        """Redirect HTTP, HTTPS & DNS requests to localhost.

        Redirect the following requests to localhost:
            * HTTP (Port 80)
            * HTTPS (Port 443)
            * DNS (Port 53)
        """
        execute_commands([
            "iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, PORT),
            "iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, 53),
            "iptables -t nat -A PREROUTING -p tcp --dport 53 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, 53),
            "iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, SSL_PORT)
        ])
예제 #6
0
    def redirect_requests_localhost():
        # type: () -> None
        """Redirect HTTP, HTTPS & DNS requests to localhost.

        Redirect the following requests to localhost:
            * HTTP (Port 80)
            * HTTPS (Port 443)
            * DNS (Port 53)
        """
        execute_commands([
            "iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, PORT),
            "iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, 53),
            "iptables -t nat -A PREROUTING -p tcp --dport 53 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, 53),
            "iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT "
            "--to-destination {}:{}".format(NETWORK_GW_IP, SSL_PORT)
        ])