Nftables Masquerade: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Linkai.zhang (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Linkai.zhang (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Zeile 21: Zeile 21:
     chain input {
     chain input {
         type filter hook input priority 0; policy drop;
         type filter hook input priority 0; policy drop;
         ct state {established, related} counter accept comment "accept all connections related to connections made by us"
         ct state {established, related} accept  
         iif lo accept comment "accept loopback"
         iif lo accept  
         iif != lo ip daddr 127.0.0.1/8 counter drop comment "drop connections to loopback not coming from loopback"
         iif != lo ip daddr 127.0.0.1/8 drop  
         ip protocol icmp counter accept comment "accept all ICMP types"
         ip protocol icmp accept  
         tcp dport 22 counter accept comment "accept SSH"
         tcp dport 22 accept  
        counter comment "count dropped packets"
     }
     }
   
   
     chain forward {
     chain forward {
         type filter hook forward priority 0; policy drop;
         type filter hook forward priority 0; policy drop;
        counter comment "count dropped packets"
     }
     }
    
    
Zeile 37: Zeile 35:
         type filter hook output priority 0; policy accept;
         type filter hook output priority 0; policy accept;
     }
     }
  }
  }
table ip nat {
    chain prerouting {
        type nat hook prerouting priority 0; policy accept;
    }
    chain postrouting {
        type nat hook postrouting priority 100; policy accept;
        oif "enp0s3" masquerade
    }
}


= Links =
= Links =


* https://wiki.gentoo.org/wiki/Nftables/Examples
* https://wiki.gentoo.org/wiki/Nftables/Examples

Version vom 7. März 2023, 14:00 Uhr

Einfache Routing Firewall

  • Eine einfache Firewall, die Pakete aus dem LAN ins WAN weiterleitet
  • Pakete aus dem WAN von etablierten Verbindungen sollen ins LAN geleitet werden

Routing aktivieren

  • sysctl -w net.ipv4.ip_forward = 1

Einfaches NAT

  • Quell IP Adressen aus dem LAN sollen auf die WAN IP geändert werden
  • Am einfachsten ist dafür das "Masquerading"
  • Sowohl dynamische als auch statische WAN IPs können damit Zugriff auf das Internet gewähren
  • Wenn sicher eine statische IP hat, ist SNAT ein wenig schneller
  • vim /etc/nftables.conf
flush ruleset

table ip filter {
    chain input {
        type filter hook input priority 0; policy drop;
        ct state {established, related} accept 
        iif lo accept 
        iif != lo ip daddr 127.0.0.1/8 drop 
        ip protocol icmp accept 
        tcp dport 22 accept 
    }

    chain forward {
        type filter hook forward priority 0; policy drop;
    }
 
    chain output {
        type filter hook output priority 0; policy accept;
    }

}

table ip nat {
    chain prerouting {
        type nat hook prerouting priority 0; policy accept;
    }

    chain postrouting {
        type nat hook postrouting priority 100; policy accept;
        oif "enp0s3" masquerade
    }

}

Links