Portál AbcLinuxu, 24. října 2025 03:07
#!/usr/sbin/nft -f
# vlan10: 192.168.10.0/24 - LAN
# vlan20: 192.168.20.0/24 - DMZ
# vlan30: 192.168.30.0/24 - Guest network
# vlan100: 192.168.100.0/24 - servis / management network
# tun0: 192.168.40.0/24 - OpenVPN
# wg0: 192.168.50.0/24 - Wireguard VPN
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
# accept any localhost traffic
iif lo accept
# accept trafic originated from us
ct state established,related accept
# drop invalid packets
ct state invalid counter drop
# accept http, https from anywhere
tcp dport { 80,443 } accept
# accept OpenVPN clients from anywhere
udp dport 1194 accept
# accept WireGuard clients from anywhere
udp dport 5180 accept
# accept SSH only from my servis / management IPs
tcp dport ssh ip saadr 192.168.100.11 accept
tcp dport ssh ip saadr 192.168.100.12 accept
# accept icmp from anywhere
ip protocol icmp accept
# accept icmpv6 from anywhere
ip6 nexthdr icmpv6 accept
# meta nfproto ipv6 from anywhere
icmpv6 type { nd-neighbor-advert, nd-neighbor-solicit, nd-router-advert} ip6 hoplimit 1 accept
icmpv6 type { nd-neighbor-advert, nd-neighbor-solicit, nd-router-advert} ip6 hoplimit 255 counter accept
# count and reject everithing else
counter reject with icmpx type admin-prohibited
}
chain forward {
type filter hook forward priority 0;
}
chain output {
type filter hook output priority 0;
}
}
table ip nat {
chain prerouting {
type nat hook prerouting priority 100; policy accept;
iif "ens192" tcp dport 33891 dnat to 192.168.20.11:3389
iif "ens192" tcp dport 33892 dnat to 192.168.20.12:3389
}
chain postrouting {
type nat hook postrouting priority 100; policy accept;
ip saddr 192.168.10.0/24 oif "ens192" masquerade
ip saddr 192.168.20.0/24 oif "ens192" masquerade
ip saddr 192.168.30.0/24 oif "ens192" masquerade
ip saddr 192.168.40.0/24 oif "ens192" masquerade
ip saddr 192.168.50.0/24 oif "ens192" masquerade
ip saddr 192.168.100.0/24 oif "ens192" masquerade
}
}
chain forward {
type filter hook forward priority 0; policy drop;
iifname "vlan100" oifname "ens192" ct state related,established accept # vlan100 -> WAN
iifname "ens192" oifname "vlan100" accept # WAN -> vlan100
iifname "vlan101" oifname "ens192" ct state related,established accept # vlan101 -> WAN
iifname "ens192" oifname "vlan101" accept # WAN -> vlan101
iifname "vlan102" oifname "ens192" ct state related,established accept # vlan102 -> WAN
iifname "ens192" oifname "vlan102" accept # WAN -> vlan102
iifname "vlan103" oifname "ens192" ct state related,established accept # vlan103 -> WAN
iifname "ens192" oifname "vlan103" accept # WAN -> vlan103
iifname "vlan100" oifname "vlan101" ct state related,established accept # vlan100 -> vlan101
iifname "vlan100" oifname "vlan102" ct state related,established accept # vlan100 -> vlan102
iifname "vlan100" oifname "vlan103" ct state related,established accept # vlan100 -> vlan103
}
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
# accept any localhost traffic
iif lo accept
# accept trafic originated from us
ct state established,related accept
# drop invalid packets
ct state invalid counter drop
# accept http, https from anywhere
tcp dport { 80,443 } accept
# accept OpenVPN clients from anywhere
udp dport 1194 accept comment "OpenVPN in"
# accept WireGuard clients from anywhere
udp dport 5180 accept comment "WireGuard in"
# accept SSH only from this IPs
tcp dport ssh ip saddr 10.255.255.32 accept comment "SSH in"
tcp dport ssh ip saddr 10.1.100.11 accept comment "SSH in"
tcp dport ssh ip saddr 10.1.100.12 accept comment "SSH in"
# accept icmp from anywhere
ip protocol icmp accept
# accept icmpv6 from anywhere
ip6 nexthdr icmpv6 accept
# meta nfproto ipv6 from anywhere
icmpv6 type { nd-neighbor-advert, nd-neighbor-solicit, nd-router-advert} ip6 hoplimit 1 accept
icmpv6 type { nd-neighbor-advert, nd-neighbor-solicit, nd-router-advert} ip6 hoplimit 255 counter accept
# count and reject everithing else
counter reject with icmpx type admin-prohibited
}
chain forward {
type filter hook forward priority 0; policy drop;
# povolím přístup na internet z vlan100
iifname "vlan100" oifname "ens192" accept # vlan100 to Internet
iifname "ens192" oifname "vlan100" ct state related,established accept # Internet to vlan100
# povolím přístup na internet z vlan101
iifname "vlan101" oifname "ens192" accept # vlan101 to Internet
iifname "ens192" oifname "vlan101" ct state related,established accept # Internet to vlan101
# povolím přístup z vlan100 do vlan101
# pokud se komunikace navazuje z vlan100
iifname "vlan100" oifname "vlan101" accept # vlan100 to vlan101
iifname "vlan101" oifname "vlan100" ct state related,established accept # vlan101 to vlan100
}
chain output {
type filter hook output priority 0;
}
}
table ip nat {
chain prerouting {
type nat hook prerouting priority 0; policy accept;
}
chain postrouting {
type nat hook postrouting priority 100; policy accept;
ip saddr 10.100.1.0/24 oif "ens192" snat 10.255.255.251
ip saddr 10.101.1.0/24 oif "ens192" snat 10.255.255.251
}
}
Předem děkuji.
iifname "vlan101" ip saddr 10.101.1.11 oifname "vlan100" accept
iifname "vlan100" ip daddr 10.101.1.11 oifname "vlan101" accept
Díky,
cat /etc/nftables.conf
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
# accept any localhost traffic
iif lo accept
# accept trafic originated from us
# ct state established,related accept
# drop invalid packets
ct state invalid counter drop
# accept http, https from anywhere
tcp dport { 80,443 } accept
# accept OpenVPN clients from anywhere
udp dport 1194 accept comment "OpenVPN in"
# accept WireGuard clients from anywhere
udp dport 5180 accept comment "WireGuard in"
# accept SSH only from this IPs
tcp dport ssh ip saddr 10.255.255.32 accept comment "SSH in"
tcp dport ssh ip saddr 10.100.1.11 accept comment "SSH in"
tcp dport ssh ip saddr 10.101.1.11 accept comment "SSH in"
# accept icmp from anywhere
ip protocol icmp accept
# accept icmpv6 from anywhere
ip6 nexthdr icmpv6 accept
# meta nfproto ipv6 from anywhere
icmpv6 type { nd-neighbor-advert, nd-neighbor-solicit, nd-router-advert} ip6 hoplimit 1 accept
icmpv6 type { nd-neighbor-advert, nd-neighbor-solicit, nd-router-advert} ip6 hoplimit 255 counter accept
# count and reject everithing else
counter reject with icmpx type admin-prohibited
}
chain forward {
type filter hook forward priority 0; policy drop;
# povolím přístup na internet z vlan100
iifname "vlan100" oifname "ens192" accept # vlan100 to Internet
iifname "ens192" oifname "vlan100" ct state related,established accept # Internet to vlan100
# povolím přístup na internet z vlan101
iifname "vlan101" oifname "ens192" accept # vlan101 to Internet
iifname "ens192" oifname "vlan101" ct state related,established accept # Internet to vlan101
# povolím přístup z vlan100 do vlan101
# pokud se komunikace navazuje z vlan100
iifname "vlan100" oifname "vlan101" accept # vlan100 to vlan101
iifname "vlan101" oifname "vlan100" ct state related,established accept # vlan101 to vlan100
iifname "vlan101" ip saddr 10.101.1.12 oifname "vlan100" accept
iifname "vlan100" ip daddr 10.101.1.12 oifname "vlan101" accept
}
chain output {
type filter hook output priority 0;
}
}
table ip nat {
chain prerouting {
type nat hook prerouting priority 0; policy accept;
}
chain postrouting {
type nat hook postrouting priority 100; policy accept;
ip saddr 10.100.1.0/24 oif "ens192" snat 10.255.255.251
ip saddr 10.101.1.0/24 oif "ens192" snat 10.255.255.251
}
}
Díky,
Petr
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.