All Products
Search
Document Center

Elastic Compute Service:How do I view the internal gateway IP address of an ECS instance?

Last Updated:Mar 12, 2025

To test the connectivity and performance of the network between an Elastic Compute Service (ECS) instance and its gateway, you must obtain the gateway IP address in the internal network. This topic describes how to obtain the IP address of the internal gateway connected to an ECS instance.

Background information

An Alibaba Cloud virtual private cloud (VPC) is a logically isolated network that is segmented into subnets by vSwitches. By default, subnets in the same VPC can communicate with each other, which allows the internal gateway to forward traffic between the subnets in the VPC. When you create an ECS instance, you must select a VPC and a vSwitch for it. The instance can communicate with other subnets in the VPC via the designated internal gateway IP address.

Prerequisites

Before you perform the following operations on an ECS instance, make sure that the instance meets the following requirements:

  • It is in the Running state.

  • It resides in a VPC.

Procedure

Warning
  • The internal gateway IP address is automatically designated based on the vSwitch CIDR block. To prevent issues such as network disconnections and routing abnormalities, do not change the internal gateway IP address or any related routing configurations.

  • In this example, an ECS instance that has two elastic network interfaces (ENIs) is used. If your instance has special network configurations, such as IPv6 dual-stack, the gateway information may exist in a different route table. To view the full network topology, log on to the VPC console.

Linux instance

Run the ip command

Run the following command to view the route table information:

sudo ip route show
Note
  • If the instance resides in a dual-stack IPv6 environment and needs the IPv6 route table displayed, run the ip -6 route show command.

  • If the instance runs openSUSE, we recommend that you run the ip command to view the route table information instead of the route or netstat command.

The following command output is returned:

default via 172.16.0.253 dev eth0 proto dhcp src 172.16.0.71 metric 100 
172.16.0.0/24 dev eth0 proto kernel scope link src 172.16.0.71 metric 100 

In the command output, the default via parameter indicates the default route. In this example, 172.16.0.253 is the internal gateway IP address for the eth0 ENI.

Run the route command

Run the following command to view the route table information in the kernel:

sudo route -n

The following command output is returned:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.0.253    0.0.0.0         UG    100    0        0 eth0
172.16.0.0      0.0.0.0         255.255.255.0   U     100    0        0 eth0

In the command output, find the row where Destination is 0.0.0.0 (default route), and then obtain the corresponding Gateway value, which is the internal gateway IP address for the eth0 ENI.

Run the netstat command

Run the following command to view the route table information:

sudo netstat -r -n

The following command output is returned:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         172.16.0.253    0.0.0.0         UG        0 0          0 eth0
172.16.0.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0

In the command output, find the row where Destination is 0.0.0.0 (default route), and then obtain the corresponding Gateway value, which is the internal gateway IP address for the eth0 ENI.

Windows instance

Run the ipconfig command

  1. Connect to the Windows instance. For more information, see Use Workbench to connect to a Windows instance over RDP.

  2. Click the Start icon, enter PowerShell, and then press Enter to open Windows PowerShell.

    Run the following command to view the network configuration:

    ipconfig

    The following command output is returned, from which you can obtain the gateway IP address for the relevant ENI.

    image

Run the route command

  1. Connect to the Windows instance. For more information, see Use Workbench to connect to a Windows instance over RDP.

  2. Click the Start icon, enter PowerShell, and then press Enter to open Windows PowerShell.

    Run the following command to view the network configuration:

    route print
    Note

    If the instance resides in an IPv6 dual-stack environment and needs the IPv6 route table displayed, run the route print -6 command.

    The following figure shows the command output.

    image

    In the command output, find the row where Network Destination is 0.0.0.0, and then obtain the corresponding Gateway value, which is the default gateway IP address for the current ENI.

Note

If you want to test the network connectivity after you obtain the internal gateway IP address for the ECS instance, run the ping or traceroute command to diagnose and analyze network connectivity.

FAQs

What do I do if the "ip: command not found" error message appears when I run the ip command?

  • Problem description: When you run the ip command, the "ip: command not found" error message appears.

  • Cause: The net-tools package is not installed.

  • Solution: Install the net-tools package.

    Alibaba Cloud Linux, CentOS, and Fedora

    sudo yum install -y net-tools

    Debian and Ubuntu

    sudo apt install -y net-tools

    openSUSE

    sudo zypper install -y net-tools

What do I do if the "netstat: command not found" error message appears when I run the netstat command on an openSUSE instance?

  • Problem description: When you run the netstat command on an openSUSE instance on which the net-tools package is installed, the "netstat: command not found" error message appears.

  • Cause: In the openSUSE operating system, the netstat command is replaced with the ss command.

  • Solution: Run the ss command instead of the netstat command.

References