Ubuntu Overlay 场景的防火墙规则配置

一、先明确 Overlay 类型与边界
二、主机层防火墙 UFW 快速配置
sudo apt updatesudo apt install ufw -ysudo ufw default deny incomingsudo ufw default allow outgoingsudo ufw enablesudo ufw allow from 10.0.0.0/24 to any port 22sudo ufw allow from 10.0.0.0/24 to any port 80 proto tcpsudo ufw status verbosesudo ufw status numberedsudo ufw delete <编号>三、主机层 nftables 精细化示例(适合 VXLAN 场景)
sudo apt install nftables -ysudo nft add table inet filtersudo nft add chain inet filter input { type filter hook input priority 0; policy drop; }sudo nft add rule inet filter input iifname "lo" acceptsudo nft add rule inet filter input ct state established,related acceptsudo nft add rule inet filter input udp dport 4789 accept# VXLANsudo nft add rule inet filter input tcp dport 22 accept # SSHsudo nft add rule inet filter input ip saddr 10.0.0.0/24 acceptsudo nft add chain inet filter forward { type filter hook forward priority 0; policy drop; }sudo nft add rule inet filter forward iifname "vxlan0" ip saddr 10.0.0.0/24 ip daddr 10.0.0.0/24 acceptsudo apt install nftables-persistent -ysudo netfilter-persistent savesudo nft list ruleset > /etc/nftables.conf# 重启后sudo nft -f /etc/nftables.conf四、容器网络内的策略控制
Docker Swarm
docker service create --name web --network my_overlay_network --publish 80:80 nginxKubernetes/Calico
apiVersion: projectcalico.org/v3kind: NetworkPolicymetadata:name: allow-default-to-svcnamespace: defaultspec:selector: app == 'myapp'ingress:- action: Allowsource:namespaceSelector: name == 'default'destination:ports:- protocol: TCPport: 80egress:- action: Allowprotocol: TCPdestination:nets:- 10.0.0.0/16kubectl get networkpolicy -Akubectl describe networkpolicy allow-default-to-svc -n default五、验证与排障清单
docker network ls/inspect my_overlay_networkdocker service ls/ps webkubectl get networkpolicy -A -o yamldocker exec -it <容器名> bashping <对端IP或服务名>