All Products
Search
Document Center

Elastic Compute Service:Konfigurasikan rute untuk ENI

Last Updated:Aug 21, 2026

Konfigurasikan tabel rute dan aturan routing untuk ENI guna mengontrol cara Instance ECS mengirim dan menerima lalu lintas melalui beberapa antarmuka jaringan.

Konfigurasikan policy-based routes untuk ENI

Policy-based routing meneruskan lalu lintas melalui antarmuka jaringan tertentu berdasarkan aturan yang telah ditentukan, alih-alih hanya mengandalkan rute default. Hal ini memungkinkan kontrol lalu lintas detail halus di berbagai ENI.

Kasus penggunaan

  • Komunikasi di lingkungan multi-ENI: Saat ENI sekunder digunakan bersama EIP atau gerbang NAT, lalu lintas balasan mungkin keluar melalui ENI primer karena rute default-nya memiliki prioritas lebih tinggi. Rute berbasis kebijakan menegakkan prinsip source in-source out sehingga lalu lintas masuk dan keluar melalui ENI yang sama.

  • Traffic load balancing: Distribusikan lalu lintas arah keluar ke beberapa ENI dengan menentukan aturan routing, ketika rute default tidak memenuhi kebutuhan Anda.

  • Access control: Batasi lalu lintas ke antarmuka atau jalur tertentu berdasarkan alamat sumber, alamat tujuan, atau parameter lainnya untuk isolasi jaringan.

Prasyarat

Prosedur

Contoh berikut menggunakan ENI sekunder bernama eth1. Ganti identifikasi ENI dan alamat IP dengan nilai aktual Anda.

Instance Linux
  1. Buat tabel rute untuk ENI dan tambahkan aturan rute:

    ip -4 route add default via <Gateway of eth1> dev eth1 table 1001
    ip -4 rule add from <IP address of eth1> lookup 1001

    Sebagai contoh, buat tabel rute bernama 1001 untuk eth1 dan tambahkan aturan agar paket dari 172.16.20.193 dirutekan melalui eth1:

    ip -4 route add default via 172.16.20.253 dev eth1 table 1001
    ip -4 rule add from 172.16.20.193 lookup 1001
  2. Pertahankan konfigurasi rute setelah restart.

    Tambahkan perintah rute ke konfigurasi startup instans agar tetap berlaku. Jika tidak, rute akan hilang setelah restart. Lewati langkah ini jika Anda hanya melakukan pengujian.

    1. Buka /etc/rc.local:

      vim /etc/rc.local
    2. Tekan i untuk memasuki mode Insert, tambahkan perintah dari langkah sebelumnya, lalu tekan Esc. Masukkan :wq dan tekan Enter untuk menyimpan serta menutup file.

      Catatan

      Ganti identifikasi antarmuka jaringan dan alamat gateway dengan nilai aktual Anda.

    3. Berikan izin eksekusi pada /etc/rc.local:

      sudo chmod +x /etc/rc.local
  3. Verifikasi bahwa tabel rute dan aturan telah dibuat:

    ip route list table 1001 && \
    ip rule list

    Output berikut mengonfirmasi bahwa tabel rute dan aturan telah dikonfigurasi:

    root@xxx:/etc/netplan# ip route list table 1001 && ip rule list
    default via 172.16.20.253 dev eth1
    0:	from all lookup local
    32765:	from 172.16.20.193 lookup 1001
    32766:	from all lookup main
    32767:	from all lookup default

Instans Windows

  1. Buat policy-based route untuk ENI:

    route add -p <Destination network> mask <Subnet mask> <Gateway> if <Interface index> metric <Route priority>

    Dalam contoh ini, digunakan ENI bernama Ethernet 2. Perintah berikut merutekan paket semua dari 172.16.12.76 melalui gateway di 172.16.12.253:

    route add -p 0.0.0.0 mask 0.0.0.0 172.16.12.253 if 6 metric 1

    Parameter:

    • -p: membuat rute permanen. Tanpa -p, rute bersifat sementara dan hilang setelah restart.

    • Destination network: 0.0.0.0 menunjukkan rute default, digunakan saat tidak ada rute spesifik yang sesuai.

    • Subnet mask dan gateway: Jalankan ipconfig untuk melihat nilai-nilai ini.

      C:\Users\Administrator>ipconfig
      
      Windows IP Configuration
      
      Ethernet adapter Ethernet:
      
         Connection-specific DNS Suffix  . : cn-hangzhou.ecs.internal
         Link-local IPv6 Address . . . . . : fe80::6926:88f5:e002:7443%3
         IPv4 Address. . . . . . . . . . . : 172.16.20.241
         Subnet Mask . . . . . . . . . . . : 255.255.255.0
         Default Gateway . . . . . . . . . : 172.16.20.253
      
      Ethernet adapter Ethernet 2:
      
         Connection-specific DNS Suffix  . : cn-hangzhou.ecs.internal
         Link-local IPv6 Address . . . . . : fe80::46bd:a7fb:362e:f79f%6
         IPv4 Address. . . . . . . . . . . : 172.16.12.76
         Subnet Mask . . . . . . . . . . . : 255.255.255.0
         Default Gateway . . . . . . . . . : 172.16.12.253
    • Interface index: Jalankan netsh interface ipv4 show interfaces untuk melihat indeks tersebut.

      Dalam contoh ini, indeks antarmuka (Idx) untuk Ethernet 2 adalah 6.

      C:\Users\Administrator>netsh interface ipv4 show interfaces
      
      Idx     Met         MTU          State                Name
      ---  ----------  ----------  ------------  ---------------------------
        1          75  4294967295  connected     Loopback Pseudo-Interface 1
        3          15        1500  connected     Ethernet
        6          15        1500  connected     Ethernet 2
    • Route priority: ditentukan dalam format metric <n>. Nilai yang lebih kecil menunjukkan prioritas lebih tinggi.

  2. Jalankan route print untuk memverifikasi bahwa rute muncul dalam daftar rute.

    C:\Users\Administrator>route print
    
    ===========================================================================
    Interface List
    3...00 16 3e 0a d5 39 ......Red Hat VirtIO Ethernet Adapter
    6...00 16 3e 4c 88 9c ......Red Hat VirtIO Ethernet Adapter #2
    1...........................Software Loopback Interface 1
    
    IPv4 Route Table
    
    Active Routes:
    Network Destination        Netmask          Gateway       Interface  Metric
    0.0.0.0          0.0.0.0    172.16.12.253   172.16.12.76     15
    0.0.0.0          0.0.0.0    172.16.12.253   172.16.20.241     15
    127.0.0.0        255.0.0.0         On-link       127.0.0.1    331
    127.0.0.1  255.255.255.255         On-link       127.0.0.1    331
    127.255.255.255  255.255.255.255         On-link       127.0.0.1    331
    172.16.12.0    255.255.255.0         On-link    172.16.12.76    271
    172.16.12.76  255.255.255.255         On-link    172.16.12.76    271
    172.16.12.255  255.255.255.255         On-link    172.16.12.76    271
    172.16.20.0    255.255.255.0         On-link   172.16.20.241    271
    172.16.20.241  255.255.255.255         On-link   172.16.20.241    271
    172.16.20.255  255.255.255.255         On-link   172.16.20.255    271
    224.0.0.0        240.0.0.0         On-link       127.0.0.1    331
    224.0.0.0        240.0.0.0         On-link   172.16.20.241    271
    224.0.0.0        240.0.0.0         On-link    172.16.12.76    271
    255.255.255.255  255.255.255.255         On-link       127.0.0.1    331
    255.255.255.255  255.255.255.255         On-link   172.16.20.241    271
    255.255.255.255  255.255.255.255         On-link    172.16.12.76    271
    
    Persistent Routes:
    Network Address          Netmask  Gateway Address  Metric
    0.0.0.0          0.0.0.0    172.16.12.253       1
    ===========================================================================

Contoh

Contoh ini menunjukkan cara mengonfigurasi policy-based routes agar Instance ECS yang menjalankan Alibaba Cloud Linux 3.2 menerima paket melalui ENI sekunder (eth1) dan mengirim paket balasan melalui eth1 alih-alih ENI primer (eth0). Jika kebijakan keamanan Anda mencakup daftar putih IP sumber untuk ENI tertentu, jalur lalu lintas yang tidak sesuai akan menyebabkan permintaan sah ditolak. Policy-based routes mengatasi masalah ini.

  1. Persiapkan lingkungan.

    1. Buat Instance ECS.

      Lihat Create an instance on the Custom Launch tab.

    2. Bind ENI sekunder ke Instance ECS.

      Lihat Mengikat ENI sekunder.

    3. Ajukan Elastic IP Address (EIP) dan asosiasikan dengan ENI sekunder eth1 dalam Mode NAT.

      Lihat Associate an EIP with a secondary ENI.

      Setelah binding selesai, pada halaman detail Instance ECS, klik tab Elastic Network Interface. Status ENI sekunder berubah menjadi Bound, dan kolom Alamat IP menampilkan Alamat IP publik (EIP) dan Alamat IP pribadi utama yang dialokasikan.

    4. Persiapkan client uji.

      Gunakan Instance ECS lain yang memiliki akses Internet atau komputer lokal sebagai client uji.

    5. Tambahkan aturan inbound ke grup keamanan Instance ECS untuk mengizinkan akses dari alamat IP publik client uji. Lalu jalankan ping <EIP> pada client uji untuk memverifikasi konektivitas ke EIP yang diasosiasikan pada Langkah c.

      Lihat bagian Case 4: Allow only traffic of specific protocols to access ECS instances pada topik "Guidelines for using security groups and use cases".

  2. Kirim paket dari client uji ke Instance ECS:

    ping 47.xx.xx.109

    Ganti alamat IP dengan EIP yang diasosiasikan dengan eth1.

  3. Monitor paket ICMP pada kedua eth0 dan eth1 Instance ECS.

    • Tangkap paket ICMP pada eth0:

      tcpdump -i eth0 icmp
    • Buka jendela baru dan tangkap paket ICMP pada eth1:

      tcpdump -i eth1 icmp
  4. Lihat hasilnya.

    Policy-based route belum dikonfigurasi

    Paket masuk melalui eth1 tetapi paket balasan keluar melalui eth0. Instans menerima pada eth1 dan merespons pada eth0.

    Tangkap paket pada eth0. Anda dapat melihat ICMP echo reply:

    [root@xxx ~]# tcpdump -i eth0 icmp
    dropped privs to tcpdump
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
    14:01:55.129356 IP iZxxx > 12.xxx: ICMP echo reply, id 2048, seq 142, length 40
    14:01:56.141993 IP iZxxx > 12.xxx: ICMP echo reply, id 2048, seq 143, length 40
    14:01:57.145388 IP iZxxx > 12.xxx: ICMP echo reply, id 2048, seq 144, length 40
    14:01:58.163042 IP iZxxx > 12.xxx: ICMP echo reply, id 2048, seq 145, length 40

    Tangkap paket pada eth1. Anda dapat melihat ICMP echo request:

    [root@xxx ~]# tcpdump -i eth1 icmp
    dropped privs to tcpdump
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes
    14:01:55.129339 IP 12.xxx > iZxxx: ICMP echo request, id 2048, seq 142, length 40
    14:01:56.141980 IP 12.xxx > iZxxx: ICMP echo request, id 2048, seq 143, length 40
    14:01:57.145376 IP 12.xxx > iZxxx: ICMP echo request, id 2048, seq 144, length 40
    14:01:58.163030 IP 12.xxx > iZxxx: ICMP echo request, id 2048, seq 145, length 40

    Rute default eth0 memiliki prioritas 100, lebih tinggi daripada eth1, sehingga paket dikirim dari eth0.

    [root@i xxx          ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         172.16.20.253   0.0.0.0         UG    100    0        0 eth0
    0.0.0.0         172.16.20.253   0.0.0.0         UG    101    0        0 eth1
    172.16.20.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0
    172.16.20.0     0.0.0.0         255.255.255.0   U     101    0        0 eth1
    Policy-based route telah dikonfigurasi
    1. Konfigurasikan policy-based routes. Lihat bagian Configure policy-based routes for ENIs pada topik ini.

      ip -4 route add default via 172.16.20.253 dev eth1 table 1001
      ip -4 rule add from 172.16.20.177 lookup 1001
    2. Jalankan ping <EIP> pada client uji.

    3. Monitor paket ICMP pada ENI.

      Paket kini masuk dan keluar melalui eth1. Instans mengirim dan menerima melalui ENI yang sama berdasarkan prinsip source in-source out.

      [root@xxx ~]# tcpdump -i eth0 icmp
      dropped privs to tcpdump
      tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
      listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
      
      [root@xxx ~]# tcpdump -i eth1 icmp
      dropped privs to tcpdump
      tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
      listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes
      14:15:13.249277 IP 123.xxx.xxx.4 > iZbp1gt1xxx          Z: ICMP echo request, id 2050, seq 150, length 40
      14:15:13.249293 IP iZbxxx    lh49gbqovzZ :         4: ICMP echo reply, id 2050, seq 150, length 40
      14:15:14.263769 IP 123.xxx.xxx.4 > iZbp1gt1xxx          Z: ICMP echo request, id 2050, seq 151, length 40
      14:15:14.263783 IP iZbxxx    lh49gbqovzZ :         4: ICMP echo reply, id 2050, seq 151, length 40
      14:15:15.267143 IP 123.xxx.xxx.4 > iZbp1gt1xxx          Z: ICMP echo request, id 2050, seq 152, length 40
      14:15:15.267155 IP iZbxxx    lh49gbqovzZ :         4: ICMP echo reply, id 2050, seq 152, length 40
      14:15:16.275436 IP 123.xxx.xxx.4 > iZbp1gt1xxx          Z: ICMP echo request, id 2050, seq 153, length 40
      14:15:16.275449 IP iZbxxx    lh49gbqovzZ :         4: ICMP echo reply, id 2050, seq 153, length 40

Konfigurasikan default routes untuk ENI

Rute default dikonfigurasi secara otomatis saat Anda meng-bind ENI ke Instance ECS. Namun, pada beberapa versi OS sebelum Ubuntu 18, seperti Ubuntu 16, rute default mungkin tidak dikonfigurasi untuk ENI sekunder, yang menyebabkan masalah konektivitas jaringan. Ikuti langkah-langkah berikut untuk mengonfigurasi rute default secara manual.

Dalam contoh ini, digunakan Ubuntu 16 dan ENI sekunder eth1.

  1. Lihat informasi ENI:

    ip a
    root@xxx:/etc/network# ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host
           valid_lft forever preferred_lft forever
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
        link/ether 00:16:3e:15:74:ee brd ff:ff:ff:ff:ff:ff
        inet 172.16.20.231/24 brd 172.16.20.255 scope global eth0
           valid_lft forever preferred_lft forever
        inet6 fe80::216:3eff:fe15:74ee/64 scope link
           valid_lft forever preferred_lft forever
    3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
        link/ether 00:16:3e:46:31:f4 brd ff:ff:ff:ff:ff:ff
        inet 172.16.20.199/24 brd 172.16.20.255 scope global eth1
           valid_lft forever preferred_lft forever
        inet6 fe80::216:3eff:fe46:31f4/64 scope link
           valid_lft forever preferred_lft forever

    Output menunjukkan bahwa eth1 berlaku di sistem operasi.

  2. Lihat informasi rute:

    route -n

    Output menunjukkan bahwa eth1 hanya memiliki rute internal dan tidak memiliki rute arah keluar.

    root@xxx:/etc/network# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         172.16.20.253   0.0.0.0         UG    0      0        0 eth0
    172.16.20.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
    172.16.20.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1

    Contoh pengecualian

    Tanpa rute arah keluar, komunikasi melalui eth1 gagal. Sebagai contoh, mengasosiasikan EIP dengan eth1 untuk akses Internet menyebabkan kehilangan konektivitas.

    root@xxx               /etc/network# ping -I eth1 www.xxx.com
    PING www.xxx.com (1xxx12) from 172.16.20.199 eth1: 56(84) bytes of data.
    From 172.16.20.199 icmp_seq=1 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=2 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=3 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=4 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=5 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=6 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=7 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=8 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=9 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=10 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=11 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=12 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=13 Destination Host Unreachable
    From 172.16.20.199 icmp_seq=14 Destination Host Unreachable
  3. Konfigurasikan rute default untuk eth1:

    ip -4 route add default via 172.16.20.253 dev eth1 metric 200
    • -4: berlaku hanya untuk alamat IPv4.

    • 172.16.20.253: alamat gateway eth1.

    • metric 200: prioritas rute. Nilai yang lebih kecil menunjukkan prioritas lebih tinggi. Saat terdapat beberapa rute ke tujuan yang sama, rute dengan metrik terkecil yang digunakan.

  4. Pertahankan konfigurasi rute setelah restart.

    Tambahkan perintah rute ke konfigurasi startup instans agar tetap berlaku. Jika tidak, rute akan hilang setelah restart. Lewati langkah ini jika Anda hanya melakukan pengujian.

    1. Buka /etc/rc.local:

      vim /etc/rc.local
    2. Tekan i untuk memasuki mode Insert, tambahkan perintah dari langkah sebelumnya, lalu tekan Esc. Masukkan :wq dan tekan Enter untuk menyimpan serta menutup file.

      Catatan

      Ganti identifikasi antarmuka jaringan dan alamat gateway dengan nilai aktual Anda.

    3. Berikan izin eksekusi pada /etc/rc.local:

      sudo chmod +x /etc/rc.local
  5. Lihat rute yang ditambahkan untuk eth1:

    route -n
    root@ixxxxxxxxxx:/etc/network# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         172.16.20.253   0.0.0.0         UG    0      0        0 eth0
    0.0.0.0         172.16.20.253   0.0.0.0         UG    200    0        0 eth1
    172.16.20.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
    172.16.20.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1

    Verifikasi bahwa pengecualian telah terselesaikan

    Setelah mengonfigurasi rute default, eth1 berkomunikasi sebagaimana mestinya.

    root@xxx:~/etc/network# ping  -I eth1 www.xxx.com
    PING www.xxx.com (xxx) from 172.16.20.199 eth1: 56(84) bytes of data.
    64 bytes from xxx: icmp_seq=1 ttl=51 time=11.6 ms
    64 bytes from xxx: icmp_seq=2 ttl=51 time=11.6 ms
    64 bytes from xxx: icmp_seq=3 ttl=51 time=11.6 ms
    64 bytes from xxx: icmp_seq=4 ttl=51 time=11.6 ms
    ^C