Google Cloud VPC 网络会针对具有连接概念(例如 TCP)的 IP 协议实现 10 分钟的连接跟踪。这意味着,只要在过去 10 分钟内至少发送或收到一个连接的数据包,就允许与建立的连接关联的入站数据包。如果在 10 分钟或更长时间内未收到或发送连接的数据包,则系统会移除闲置连接的跟踪条目。移除连接的跟踪条目后, Google Cloud 在至少发送了一个新出站数据包之前不允许其他入站数据包。此连接跟踪适用于所有来源和目的地,即内部和外部 IP 地址。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-19。"],[[["\u003cp\u003eThis page provides tips for troubleshooting issues with Google Compute Engine, including general instance problems and Windows-specific errors.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egcloud\u003c/code\u003e CLI tool's log files, which are stored at \u003ccode\u003e$HOME/.config/gcloud/logs\u003c/code\u003e, can be managed by setting the \u003ccode\u003emax_log_days\u003c/code\u003e property to limit the retention period or \u003ccode\u003edisable_file_logging\u003c/code\u003e property to stop file logging entirely.\u003c/p\u003e\n"],["\u003cp\u003eInstances can achieve direct internet access with both an external IP address and a default route to the internet gateway, while indirect access can be facilitated via Cloud NAT or an instance-based proxy.\u003c/p\u003e\n"],["\u003cp\u003eTo prevent idle connection issues within Google Cloud VPC networks, it is recommended to configure operating system TCP keep-alive settings to send packets at intervals shorter than 10 minutes.\u003c/p\u003e\n"],["\u003cp\u003eTo avoid packet fragmentation when communicating with Compute Engine instances via UDP, set the maximum size of UDP datagram data 28 bytes less than the network's MTU, which is by default 1460 bytes.\u003c/p\u003e\n"]]],[],null,["# General tips for using Compute Engine\n\n*** ** * ** ***\n\nThis page describes tips that you might find helpful if you run into problems\nusing Compute Engine.\n\nFor help troubleshooting specific issues, see one of the following sections:\n\n- For steps to troubleshoot general issues with instances, such as if your instance doesn't start up, see [General troubleshooting](/compute/docs/troubleshooting/troubleshooting-instances).\n- For steps to troubleshoot issues with Windows instances, see [Troubleshooting Windows instances](/compute/docs/troubleshooting/troubleshooting-windows).\n\nViewing different response formats\n----------------------------------\n\nThe Google Cloud CLI performs most of its actions by making REST\nAPI calls. The pretty-printed results show only the most important information\nreturned by any specific command. To see the different response formats,\nuse the `--format` flag which displays the response in different output formats,\nincluding `json`, `yaml`, and `text`. For example, to see a list of instances in\nJSON, use `--format json`: \n\n gcloud compute instances list --format json\n\nViewing gcloud compute logs\n---------------------------\n\nThe gcloud CLI creates and stores logs in a log file that you\ncan query, located at `$HOME/.config/gcloud/logs`. To see the latest log file on\na Linux-based operating system, run: \n\n```\n$ less $(find ~/.config/gcloud/logs | sort | tail -n 1)\n```\n\nThe log file includes information about all requests and responses made using\nthe `gcloud CLI` tool.\n\nTo automatically purge the log files created by the gcloud CLI,\nuse the [`max_log_days`](/sdk/gcloud/reference/config#max_log_days) property,\nwhich sets the maximum number of days to retain log files before deleting.\nThe default setting is 30 days. If you set this property value to 0, it turns\noff log garbage collection and does not delete log files. \n\n```\n gcloud config set core/max_log_days DAYS_TO_RETAIN_LOGS\n```\n\n**Disable gcloud CLI file logging:**\n\nThe file `$HOME/.config/gcloud/logs` consumes space on the local filesystem.\nThe amount of logs generated might overwhelm the amount of space on the local\nfilesystem, which can cause issues like:\n\n- Space utilization reaching 100% on the instance.\n- Failure to execute gcloud CLI logging commands because there is no space left to create a new file on the local filesystem.\n\nTo change the gcloud CLI behavior and disable the file\nlogging, use the [`disable_file_logging`](/sdk/gcloud/reference/config/set#disable_file_logging)\nproperty: \n\n```\n gcloud config set core/disable_file_logging True\n```\n| **Note:** The gcloud version must be higher than 250.0.0 to be able to use the `disable_file_logging` property. To check the gcloud version, use the command `gcloud -v`.\n\nSelecting resource names\n------------------------\n\nWhen selecting names for your resources, keep in mind that these friendly-names\nmay be visible on support and operational dashboards within Compute Engine.\nFor this reason, it is recommended that resource names that do not expose any\nsensitive information.\n\nCommunicating to the internet\n-----------------------------\n\nAn instance has *direct* internet access only if both of the following\nconditions are true:\n\n- The instance has an [external IP\n address](/compute/docs/instances_and_network#externaladdresses).\n- The instance's VPC network uses a [default route whose next hop\n is the default internet gateway](/vpc/docs/routes#routingpacketsinternet).\n\nInstances can also access the internet indirectly, by connecting through\n[Cloud NAT](/nat/docs) or an instance-based proxy. For additional\nconsiderations, including firewall rule configuration, see [Internet access\nrequirements](/vpc/docs/vpc#internet_access_reqs).\n\nIdle connections\n----------------\n\nGoogle Cloud VPC networks implement 10-minute connection\ntracking for IP protocols that have a concept of a *connection* (TCP for\nexample). This means that inbound packets associated with an established\nconnection are permitted as long as at least one packet is sent or received for\nthe connection within the last 10 minutes. If no packets for the connection\nhave been sent or received for 10 minutes or longer, the idle connection's\ntracking entries are removed. After the connection's tracking entries have been\nremoved, Google Cloud does not permit additional inbound packets until at\nleast one new outbound packet has been sent. This connection tracking applies to\nall sources and destinations -- both [internal and external IP\naddresses](/vpc/docs/ip-addresses) .\n\nTo prevent idle connections, do the following:\n\n- Set operating system\n [TCP keep-alive](https://en.wikipedia.org/wiki/Keepalive)\n parameters to a time frame of *less than* 10 minutes. This ensures that at\n least one packet is sent within the time frame.\n\n- Ensure applications that open TCP connections do so with the `SO_KEEPALIVE`\n option enabled.\n\nThe following examples demonstrate how to set operating system TCP keep-alive\nparameters with an interval value of one minute. Consult your application or\nsoftware library's documentation to determine how to configure it to use\n`SO_KEEPALIVE`.\n**Note:** IPv6 doesn't have separate `ipv6` settings. The `keepalive` settings for IPv4 also apply to IPv6. \n\n#### Linux\n\n\u003cbr /\u003e\n\nRun the following command: \n\n```\n$ sudo /sbin/sysctl -w net.ipv4.tcp_keepalive_time=60 net.ipv4.tcp_keepalive_intvl=60 net.ipv4.tcp_keepalive_probes=5\n```\nTo ensure that the settings survive a reboot, add the settings to your `/etc/sysctl.conf` file.\n\n\u003cbr /\u003e\n\nSee\n[Linux TCP Keepalive HOWTO](http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO) for additional information.\n\n#### macOS\n\n\u003cbr /\u003e\n\nRun the following command: \n\n```\n$ sudo sysctl -w net.inet.tcp.always_keepalive=1 net.inet.tcp.keepidle=60000 net.inet.tcp.keepinit=60000 net.inet.tcp.keepintvl=60000\n```\n\n#### Windows\n\n\u003cbr /\u003e\n\nUnder the registry path\n`HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\`,\nadd the following settings, using the\n[DWORD](http://msdn.microsoft.com/en-us/library/cc230318.aspx)\ndata type, or edit the values if the settings already exist: \n\n```\nKeepAliveInterval: 1000\nKeepAliveTime: 60000\nTcpMaxDataRetransmissions: 10\n```\n\nAccessing Compute Engine as a different SSH user\n------------------------------------------------\n\nBy default, the `gcloud compute` command-line tool uses the `$USER` variable to\nadd users to the `/etc/passwd` file for connecting to virtual machine instances\nusing SSH. You can specify a different user using the\n`--ssh-key-file PRIVATE_KEY_FILE` flag when running the `gcloud compute ssh`\ncommand. For example: \n\n gcloud compute ssh example-instance --ssh-key-file my-private-key-file\n\nSee the\n[`gcloud` reference documentation](/sdk/gcloud/reference/compute/ssh) for\nmore information.\n\nInteracting with the serial console\n-----------------------------------\n\nYou can enable interactive access to an instance's serial console so you can\nconnect and troubleshoot instances through the serial console.\n\nTo learn more, read\n[Interacting with the Serial Console](/compute/docs/instances/interacting-with-serial-console).\n\nAvoiding packet fragmentation to instances built from custom images\n-------------------------------------------------------------------\n\nThe VPC network has a default maximum transmission unit (MTU)\nof `1460` bytes for Linux images and Windows Server images. However, the\nnetwork MTU can be changed. For details, see the\n[maximum transmission unit overview](/vpc/docs/mtu) in the VPC\ndocumentation.\n\nWhen creating client applications that communicate with Compute Engine\ninstances over UDP sockets, you can avoid fragmentation if you set the maximum\nsize of the UDP datagram's data to 28 bytes less than the network MTU. For\nexample, if the network's MTU is 1460 bytes, you can send up to 1432 bytes of\nUDP data per packet without fragmentation. If the network's MTU is 1500 bytes,\nyou can send up to 1472 bytes of UDP data without fragmentation. The 28 bytes\nare used for an IPv4 packet header (20 bytes) and a UDP datagram header\n(8 bytes). You can set the network's MTU to a maximum of 8896 bytes."]]