21
« kdy: 10. 04. 2020, 18:53:00 »
Konfigurak pro nftables s 5 interfacy, enp1s0 je brana ven, na nem se dela maskarada. Enp2-4s0 je vnitri sit, wlp5s0 je wifi v mPCIe. Pak jeste povolit v sysctl ipv4_forwarding a melo by to fungovat. Forward mezi interfacy vnitri site mam jako accept, aby stroje v siti 172.16.0.0/12 mohly mezi sebou komunikovat. Ven mam povolene 22, 80, 443 stavovym firewallem:
#!/sbin/nft -f
# vim: ft=pf
### FLUSH RULESET
flush ruleset
### SERVERs
define IPV4_LOCAL = { 172.16.0.0/12 }
table ip filter {
chain input {
type filter hook input priority 0; policy drop;
counter comment "count input accepted packets"
### DROP
### State firewall
iifname enp1s0 ct state invalid counter log prefix "DROP INVALID: " drop comment "early drop of invalid packets"
iifname enp1s0 ct state established,related counter accept comment "accept all connections related to connections made by us"
iifname enp2s0 accept comment "accept all"
iifname enp3s0 accept comment "accept all"
iifname enp4s0 accept comment "accept all"
iifname wlp5s0 accept comment "accept all"
### Loopback interface
iifname lo accept comment "accept loopback"
iifname != lo ip daddr 127.0.0.1/8 counter drop comment "drop connections to loopback not coming from loopback"
### Icmp
ip protocol icmp counter limit rate 3600/hour burst 1200 packets log prefix "ACCEPT ICMP: " accept comment "accept all ICMP types"
### Allow LOCAL
ip saddr $IPV4_LOCAL counter log prefix "ACCEPT LOCAL: " accept comment "connections comming from LOCAL servers"
### Allow INET access
tcp dport 22 ct state new counter limit rate 6/minute burst 3 packets log prefix "ACCEPT SSH to port 22: " accept comment "connections via SSH"
tcp dport 80 ct state new counter log prefix "ACCEPT HTTP to port 80: " accept comment "connections via HTTP"
tcp dport 443 ct state new counter log prefix "ACCEPT HTTPS to port 443: " accept comment "connections via HTTPS"
}
chain forward {
type filter hook forward priority 0; policy accept;
counter comment "count forward dropped packets"
}
chain output {
type filter hook output priority 0; policy accept;
counter comment "count output accepted packets"
}
}
table ip nat {
chain prerouting {
type nat hook prerouting priority 0;
}
chain postrouting {
type nat hook postrouting priority 100;
oifname "enp0s1" masquerade
}
}
a pak:
nft -f /path/konfigurak.nft