这个
Container-optimized OS
ssh
除了配置Google Compute Engine防火墙规则以允许进入虚拟机的流量外,您还需要确保在虚拟机内运行的操作系统也允许。
这在
docs for Container-Optimized OS
默认情况下,容器优化操作系统主机防火墙仅允许
SSH服务。在上接受传入连接
容器优化操作系统实例,您必须打开服务的端口
正在收听。
例如,接受来自
在同一个计算引擎项目中,在两个
开发工作站,并在容器优化的操作系统实例上:
# On your workstation:
SUBNETWORK_URI=$(gcloud compute instances describe ${COS_INSTANCE_NAME} | grep -w 'subnetwork:' | awk '{ print $2 }')
SUBNET_PREFIX=$(gcloud compute networks subnets describe ${SUBNETWORK_URI} | grep -w 'ipCidrRange:' | awk '{ print $2 }')
# On your Container-Optimized OS instance:
sudo iptables -w -A INPUT -p tcp -s ${SUBNET_PREFIX} -j ACCEPT
sudo iptables -w -A INPUT -p udp -s ${SUBNET_PREFIX} -j ACCEPT
As another example, if you need to accept HTTP (port 80) connections from any source IP address, run the following commands on
# On your Container-Optimized OS instance:
sudo iptables -w -A INPUT -p tcp --dport 80 -j ACCEPT
通常,建议您将主机防火墙配置为
systemd
服务通过
cloud-init
.