Sekilas Tentang IP Forwarding

Test Fowarding RHEL6

Beberapa hari lalu salah seorang rekan bertanya via Whatsapp. Dia punya masalah dengan Linux servernya. Katanya servernya punya 2 IP (berbeda jaringan) & ada broadcast request yang datang dari network 1 ke network 2. Padahal menurut rekan saya, kedua IP tersebut harusnya terisolasi satu sama lain. Karena kami berkomunikasi via Whatsapp, saya kurang paham betul apa sebenarnya yang jadi masalah. Rekan saya minta pendapat apa saja yang perlu dicek. Dengan informasi yang terbatas itu saya cuma bisa menduga 2 hal, isu pada IP Forwarding atau Firewall.

Karena pertanyaan itu saya jadi berpikir lagi tentang IP Forwarding. Meskipun saya tahu cara mengaktifkan IP Forwarding di mesin Linux, tapi sampai sekarang saya belum pernah berhenti sejenak untuk memikirkan konsepnya seperti apa. Konsep IP Forwarding yang saya tahu secara sederhana kira-kira seperti ini :

  • Misalkan sebuah server punya 2 NIC (network interface card), NIC#1 terhubung ke network A & NIC#2 terhubung ke B.
  • Bila ada paket IP yang datang melalui NIC#1 menuju network B. Ada 2 kemungkinan yang terjadi :
    • Tanpa IP Forwarding, server tidak akan meneruskan paket itu keluar ke network B. Meskipun dia punya akses ke network B. Ilustrasinya seperti gambar berikut ini :
      Tanpa IP Forwarding
    • Dengan IP Forwarding, server akan meneruskan paket IP melalui NIC#2 itu menuju network B. Jadi gampangnya, akan ada serah terima paket dari NIC#1ke NIC#2 karena server tahu hanya NIC#2 yang tahu caranya mengantar paket ke tujuan. Ilustrasinya seperti gambar berikut ini :
      Dengan IP Forwarding

Konsep sederhana di atas belum melibatkan kemungkinan adanya Firewall yang aktif dalam server tersebut. Mungkin saja meskipun IP Forwarding sudah aktif, paket tetap tidak bisa dikirimkan ke network B karena terbentur oleh Firewall.

Saya jadi penasaran melakukan tes untuk makin menyakinkan diri sendiri soal IP Forwarding & Firewall tadi. Saya segera buka VirtualBox & membuat 2 buah VM (virtual machine), masing-masing menggunakan RedHat Linux 6.

VirtualBox Setup

Strukturnya saya buat mengikuti diagram pada gambar pertama tadi. Berikut detailnya :

  1. VM#1 hostname-nya host01. VM ini memiliki 2 NIC :
    VM#1 Network Adapter Setup

    • Adapter 1 menggunakan IP 192.168.10.1 terhubung dengan LAN kamar saya (dengan menggunakan VirtualBox Bridged Interface).
    • Adapter 2 menggunakan IP 10.10.10.1 terhubung dengan VirtualBox Internal Network (int0).

    Tampilan konfigurasi IP dari host01 terlihat seperti berikut ini :

    [root@host01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    TYPE=Ethernet
    ONBOOT=yes
    NM_CONTROLLED=no
    BOOTPROTO=static
    IPADDR=192.168.10.1
    NETMASK=255.255.255.0
    GATEWAY=192.168.10.2
    DNS1=8.8.8.8
    [root@host01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
    DEVICE=eth1
    TYPE=Ethernet
    ONBOOT=yes
    NM_CONTROLLED=no
    BOOTPROTO=static
    IPADDR=10.10.10.1
    NETMASK=255.255.255.0
    [root@host01 ~]# 
    [root@host01 ~]# ip address show label eth[0-1]
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 08:00:27:37:32:de brd ff:ff:ff:ff:ff:ff
        inet 192.168.10.1/24 brd 192.168.10.255 scope global eth0
        inet6 fe80::a00:27ff:fe37:32de/64 scope link 
           valid_lft forever preferred_lft forever
    3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 08:00:27:c9:23:ae brd ff:ff:ff:ff:ff:ff
        inet 10.10.10.1/24 brd 10.10.10.255 scope global eth1
        inet6 fe80::a00:27ff:fec9:23ae/64 scope link 
           valid_lft forever preferred_lft forever
    [root@host01 ~]# 
    [root@host01 ~]# netstat -rn
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
    10.10.10.0      0.0.0.0         255.255.255.0   U         0 0          0 eth1
    192.168.10.0    0.0.0.0         255.255.255.0   U         0 0          0 eth0
    169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
    169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth1
    0.0.0.0         192.168.10.2    0.0.0.0         UG        0 0          0 eth0
    [root@host01 ~]# 
    
  2. VM#2 hostname-nya host02. VM ini cuma memiliki 1 NIC & terhubung hanya ke VirtualBox Internal Network (int0):
    VM#1 Network Adapter Setup

    • Adapter 1 menggunakan IP 10.10.10.100 (dengan default gateway 10.10.10.1) terhubung dengan VirtualBox Internal Network (int0).

    Tampilan konfigurasi IP host02 seperti berikut ini :

    [root@host02 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
    DEVICE=eth0
    TYPE=Ethernet
    ONBOOT=yes
    NM_CONTROLLED=no
    BOOTPROTO=static
    IPADDR=10.10.10.100
    NETMASK=255.255.255.0
    GATEWAY=10.10.10.1
    DNS1=8.8.8.8
    [root@host02 ~]# 
    [root@host02 ~]# ip address show eth0
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 08:00:27:37:32:de brd ff:ff:ff:ff:ff:ff
        inet 10.10.10.100/24 brd 10.10.10.255 scope global eth0
        inet6 fe80::a00:27ff:fe37:32de/64 scope link 
           valid_lft forever preferred_lft forever
    [root@host02 ~]# 
    [root@host02 ~]# netstat -rn
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
    10.10.10.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0
    169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
    0.0.0.0         10.10.10.1      0.0.0.0         UG        0 0          0 eth0
    [root@host02 ~]# 
    

Untuk belajar lagi tentang IP Forwarding & hubungannya dengan Firewall, saya lakukan beberapa tes berikut ini. Tes akan menggunakan ping (untuk mengirimkan ICMP paket) & tcpdump (untuk menganalisis lalu lintas IP paket). Tujuan akhirnya adalah supaya mesin centosdev01 bisa melakukan ping ke mesin host02.

TES#1 : IP Forwarding & Firewall OFF

Pada tes ini saya belum mengaktifkan IP Forwarding pada mesin host01. Untuk memeriksa apakah IP Forwarding aktif atau tidak saya bisa gunakan perintah seperti berikut ini :

[root@host01 ~]# sysctl net.ipv4.conf.all.forwarding
net.ipv4.conf.all.forwarding = 0
[root@host01 ~]# 
[root@host01 ~]# cat /proc/sys/net/ipv4/ip_forward 
0
[root@host01 ~]# 
[root@host01 ~]# 

Nilai 0 mengindikasikan IP Forwarding tidak aktif pada mesin host01.

Saya juga segaja mematikan Firewall (iptables) pada host01.

[root@host01 ~]# service iptables stop
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@host01 ~]# service iptables status
iptables: Firewall is not running.
[root@host01 ~]# 

Tes#1 ini akan dilakukan dari mesin centosdev01, mesin ini memiliki IP 192.168.10.50 & sudah punya static route untuk mengakses network 10.10.10.0. Dengan statik route ini, centosdev01 mengerti bila ingin mengakses 10.10.10.0 harus menghubungi mesin host01 di IP 192.168.10.1.

ttirtawi@centosdev01:~$ ifconfig br0
br0       Link encap:Ethernet  HWaddr F0:DE:F1:D3:E5:05
          inet addr:192.168.10.50  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::f2de:f1ff:fed3:e505/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:86985 errors:0 dropped:0 overruns:0 frame:0
          TX packets:45609 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:53822701 (51.3 MiB)  TX bytes:8343604 (7.9 MiB)

ttirtawi@centosdev01:~$
ttirtawi@centosdev01:~$ netstat -rn | grep 10.10.10
10.10.10.0      192.168.10.1    255.255.255.0   UG        0 0          0 br0
ttirtawi@centosdev01:~$ 

Mesin centosdev01 bisa melakukan ping ke IP 192.168.10.1 (adapter eth0-nya host01) :

ttirtawi@centosdev01:~$ ping 192.168.10.1
PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.
64 bytes from 192.168.10.1: icmp_seq=1 ttl=64 time=1.36 ms
64 bytes from 192.168.10.1: icmp_seq=2 ttl=64 time=1.20 ms
64 bytes from 192.168.10.1: icmp_seq=3 ttl=64 time=0.984 ms
64 bytes from 192.168.10.1: icmp_seq=4 ttl=64 time=1.17 ms
^C
--- 192.168.10.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3653ms
rtt min/avg/max/mdev = 0.984/1.183/1.365/0.137 ms
ttirtawi@centosdev01:~$

Mesin centosdev01 bisa juga melakukan ping ke IP 10.10.10.1 (adapter eth1-nya host01) :

ttirtawi@centosdev01:~$ ping 10.10.10.1
PING 10.10.10.1 (10.10.10.1) 56(84) bytes of data.
64 bytes from 10.10.10.1: icmp_seq=1 ttl=64 time=0.772 ms
64 bytes from 10.10.10.1: icmp_seq=2 ttl=64 time=0.849 ms
64 bytes from 10.10.10.1: icmp_seq=3 ttl=64 time=1.08 ms
64 bytes from 10.10.10.1: icmp_seq=4 ttl=64 time=1.30 ms
64 bytes from 10.10.10.1: icmp_seq=5 ttl=64 time=1.15 ms
^C
--- 10.10.10.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4325ms
rtt min/avg/max/mdev = 0.772/1.032/1.300/0.196 ms
ttirtawi@centosdev01:~$

Selain sukses mengirimkan paket ICMP, saya juga bisa mengakses host01 lewat SSH seperti contoh berikut ini :

ttirtawi@centosdev01:~$ ssh root@192.168.10.1
root@192.168.10.1's password:
Last login: Wed Jun 25 21:49:31 2014 from 192.168.10.13
[root@host01 ~]# uname -a
Linux host01.localdomain 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@host01 ~]#
[root@host01 ~]# logout
Connection to 192.168.10.1 closed.
ttirtawi@centosdev01:~$
ttirtawi@centosdev01:~$
ttirtawi@centosdev01:~$ ssh root@10.10.10.1
The authenticity of host '10.10.10.1 (10.10.10.1)' can't be established.
RSA key fingerprint is c1:a4:74:f5:5d:28:8d:5b:44:a7:66:c0:2c:a3:10:b7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.10.10.1' (RSA) to the list of known hosts.
root@10.10.10.1's password:
Last login: Wed Jun 25 21:55:15 2014 from 192.168.10.50
[root@host01 ~]#
[root@host01 ~]# logout
Connection to 10.10.10.1 closed.
ttirtawi@centosdev01:~$

Akan tetapi mesin centosdev01 gagal mengirimkan paket ICMP ke mesin host02. Proses ping ke IP 10.10.10.100 tidak mendapatkan respon sama sekali dari mesin host02 :

ttirtawi@centosdev01:~$ date; ping -c 5 10.10.10.100 ; date;
Wed Jun 25 22:23:32 WIB 2014
PING 10.10.10.100 (10.10.10.100) 56(84) bytes of data.

--- 10.10.10.100 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 14000ms

Wed Jun 25 22:23:46 WIB 2014
ttirtawi@centosdev01:~$

Saat saya menjalankan ping di mesin centosdev01 tadi saya juga mengaktifkan perintah tcpdump di mesin host01. Mengapa memeriksa paketnya di host01 dan bukan di host02? Menurut saya proses troubleshooting harus dilakuan secara sistematis. Karena saya tahu ketika centosdev01 mengirimkan paket apapun menuju network 10.10.10.0, request-nya akan dikirimkan melalui IP 192.168.10.1 yang tidak lain adalah IP milik host01. Oleh karenanya yang paling logis adalah memeriksa mesin host01 terlebih dahulu untuk memastikan isunya ada di mana.

Pada contoh ping tadi, centosdev01 mengirimkan 5 paket ICMP ke 10.10.10.100. Hasil analisis tcpdump juga tepat menunjukkan ada 5 paket ICMP yang diterima :

[root@host01 ~]# tcpdump 'icmp'  -i any
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
22:23:26.282722 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 25364, seq 1, length 64
22:23:27.283420 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 25364, seq 2, length 64
22:23:28.283272 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 25364, seq 3, length 64
22:23:29.283771 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 25364, seq 4, length 64
22:23:30.283256 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 25364, seq 5, length 64
^C
5 packets captured
5 packets received by filter
0 packets dropped by kernel
[root@host01 ~]#

Terlihat juga bahwa mesin host01 tidak melakukan apa-apa, tidak meneruskan ICMP request tersebut ke mana-mana. Sekilas tentang penggunaan tcpdump di atas, perintah tersebut artinya saya ingin supaya tcpdump membaca semua lalu lintas paket ICMP (tcpdump 'icmp') pada semua network interface (-i any).

TES#2 : IP Forwarding ON & Firewall OFF

Pada tes ini saya mengaktifkan IP Forwarding pada mesin host01 (servis iptables masih belum saya aktifkan). Untuk mengaktifkan IP Forwarding di RedHat Linux saya gunakan perintah seperti berikut ini :

[root@host01 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward 
[root@host01 ~]# cat /proc/sys/net/ipv4/ip_forward 
1
[root@host01 ~]# sysctl -a | grep -i net.ipv4.conf.all.forwarding
net.ipv4.conf.all.forwarding = 1
[root@host01 ~]# 

Cara di atas sifatnya sementara, artinya bila kita me-restart mesin host01 maka IP Forwardingnya menjadi tidak aktif lagi. Untuk memastikan IP Forwarding tetap aktif, kita perlu memodifikasi berkas /etc/sysctl.conf seperti berikut ini :

[root@host01 ~]# cat /etc/sysctl.conf  | grep -i ipv4.ip_forward
net.ipv4.ip_forward = 1
[root@host01 ~]# 

Kemudian saya coba lagi perintah ping yang sama dari mesin centosdev01. Sekarang centosdev01 sudah menerima respon ICMP dari IP 10.10.10.100 seperti tampilan di bawah ini :

ttirtawi@centosdev01:~$ date; ping -c 5 10.10.10.100 ; date;
Wed Jun 25 23:21:24 WIB 2014
PING 10.10.10.100 (10.10.10.100) 56(84) bytes of data.
64 bytes from 10.10.10.100: icmp_seq=1 ttl=63 time=1.25 ms
64 bytes from 10.10.10.100: icmp_seq=2 ttl=63 time=2.04 ms
64 bytes from 10.10.10.100: icmp_seq=3 ttl=63 time=1.54 ms
64 bytes from 10.10.10.100: icmp_seq=4 ttl=63 time=2.05 ms
64 bytes from 10.10.10.100: icmp_seq=5 ttl=63 time=1.99 ms

--- 10.10.10.100 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4007ms
rtt min/avg/max/mdev = 1.252/1.777/2.056/0.327 ms
Wed Jun 25 23:21:28 WIB 2014
ttirtawi@centosdev01:~$

Sama seperti pada contoh sebelumnya saya juga mengaktifkan tcpdump pada mesin host01, tapi kali ini saya juga mengaktifkan perintah tcpdump pada mesin host02. Berikut ini adalah tampilan perintah tcpdump pada kedua mesin :

[root@host01 ~]# tcpdump 'icmp' -i any
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
23:21:18.729546 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 1, length 64
23:21:18.729560 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 1, length 64
23:21:18.729896 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 1, length 64
23:21:18.729901 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 1, length 64
23:21:19.730649 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 2, length 64
23:21:19.730669 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 2, length 64
23:21:19.732245 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 2, length 64
23:21:19.732259 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 2, length 64
23:21:20.732173 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 3, length 64
23:21:20.732193 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 3, length 64
23:21:20.732660 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 3, length 64
23:21:20.732671 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 3, length 64
23:21:21.734331 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 4, length 64
23:21:21.734349 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 4, length 64
23:21:21.735075 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 4, length 64
23:21:21.735088 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 4, length 64
23:21:22.735181 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 5, length 64
23:21:22.735201 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 5, length 64
23:21:22.735892 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 5, length 64
23:21:22.735917 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 5, length 64
^C
20 packets captured
20 packets received by filter
0 packets dropped by kernel
[root@host01 ~]#

[root@host02 ~]# tcpdump 'icmp' -i any
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
23:21:18.782887 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 1, length 64
23:21:18.782909 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 1, length 64
23:21:19.784627 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 2, length 64
23:21:19.784660 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 2, length 64
23:21:20.785727 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 3, length 64
23:21:20.785752 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 3, length 64
23:21:21.787541 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 4, length 64
23:21:21.787583 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 4, length 64
23:21:22.788927 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 44068, seq 5, length 64
23:21:22.788972 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 44068, seq 5, length 64
^C
10 packets captured
10 packets received by filter
0 packets dropped by kernel
[root@host02 ~]#

Mari kita analisis satu persatu mulai dari hasil tcpdumpnya :

  • Perintah tcpdump di host02 mendeteksi ada 10 paket ICMP. Mengapa 10 bukankah centosdev01 hanya mengirimkan 5 paket ICMP? Karena host02 menjawab setiap ICMP request yang datang dengan ICMP response. Itulah mengapa ada 10 paket ICMP yang terdeteksi oleh tcpdump.
  • Perintah tcpdump di host01 mendeteksi ada 20 paket ICMP yang lalu lalang. Mengapa jumlahnya jauh lebih besar daripada paket yang diproses oleh host02? Karena untuk setiap ICMP yang datang dari centosdev01, host01 akan “menyerahkan” paket yang sama dari eth0 ke eth1 baru kemudian eth1 mengirimkannya keluar ke host02. Dan begitu juga sebaliknya; untuk paket ICMP response yang datang dari host02, host01 akan “menyerahkan” paket tersebut dari eth1 ke eth0 & selanjutnya eth0 mengirimkannya kembali ke centosdev01. Sehingga secara total akan ada 2x lipat paket yang lalu lalang di mesin host01.

TES#3 : IP Forwarding ON & Firewall ON

Pada tes ini saya segaja mengaktifkan Firewall di mesin host01 & host02. IP Forwarding masih aktif di mesin host01. Semua rule/policy masih belum diubah, masih menggunakan default setting.

[root@host01 ~]# service iptables start
iptables: Applying firewall rules:                         [  OK  ]
[root@host01 ~]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

[root@host01 ~]#
[root@host01 ~]# sysctl -a | grep -i net.ipv4.conf.all.forwarding
net.ipv4.conf.all.forwarding = 1
[root@host01 ~]# 

Lalu saya coba lagi lakukan ping dari mesin centosdev01. Kali ini proses ping ke IP 10.10.10.100 jadi gagal lagi tapi dengan error yang berbeda. Kalau pada Tes#1 tidak ada respon sama sekali, kali ini ada respon “Destination Host Prohibited”. Respon ini datang dari mesin host01 :

ttirtawi@centosdev01:~$ date; ping -c 5 10.10.10.100 ; date;
Wed Jun 25 23:23:35 WIB 2014
PING 10.10.10.100 (10.10.10.100) 56(84) bytes of data.
From 192.168.10.1 icmp_seq=1 Destination Host Prohibited
From 192.168.10.1 icmp_seq=2 Destination Host Prohibited
From 192.168.10.1 icmp_seq=3 Destination Host Prohibited
From 192.168.10.1 icmp_seq=4 Destination Host Prohibited
From 192.168.10.1 icmp_seq=5 Destination Host Prohibited

--- 10.10.10.100 ping statistics ---
5 packets transmitted, 0 received, +5 errors, 100% packet loss, time 4005ms

Wed Jun 25 23:23:39 WIB 2014
ttirtawi@centosdev01:~$

Dari hasil tcpdump di mesin host01 kita bisa lihat meskipun IP Forwarding aktif, tapi semua ICMP request tersebut terhalang oleh Firewall :

[root@host01 ~]# tcpdump 'icmp' -i any
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
23:23:29.298251 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 18981, seq 1, length 64
23:23:29.298322 IP 192.168.10.1 > 192.168.10.50: ICMP host 10.10.10.100 unreachable - admin prohibited, length 92
23:23:30.299418 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 18981, seq 2, length 64
23:23:30.299476 IP 192.168.10.1 > 192.168.10.50: ICMP host 10.10.10.100 unreachable - admin prohibited, length 92
23:23:31.300347 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 18981, seq 3, length 64
23:23:31.300387 IP 192.168.10.1 > 192.168.10.50: ICMP host 10.10.10.100 unreachable - admin prohibited, length 92
23:23:32.301293 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 18981, seq 4, length 64
23:23:32.301335 IP 192.168.10.1 > 192.168.10.50: ICMP host 10.10.10.100 unreachable - admin prohibited, length 92
23:23:33.302565 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 18981, seq 5, length 64
23:23:33.302607 IP 192.168.10.1 > 192.168.10.50: ICMP host 10.10.10.100 unreachable - admin prohibited, length 92
^C
10 packets captured
10 packets received by filter
0 packets dropped by kernel
[root@host01 ~]#

Kalau mengacu pada iptables status, bagian inilah yang menyebabkan IP Forwarding seolah-oleh tidak berfungsi :

[root@host01 ~]# service iptables status
.....
.....
Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited
.....
.....
[root@host01 ~]#

TES#4 : IP Forwarding ON, Firewall ON + Modifikasi 1 IPTABLES host01

Dari tes terakhir terlihat ICMP request terhalang oleh iptables-nya host01. Sekarang saya ingin mengulang test yang sama tapi dengan memodifikasi firewall terlebih dulu. Untuk menambahkan rule iptables, saya gunakan perintah seperti ini :

[root@host01 ~]# iptables -I FORWARD -s 192.168.10.0/24 -d 10.10.10.0/24 -j ACCEPT

Perintah iptables di atas bisa diterjemahkan seperti ini : tolong beri ijin lewat untuk setiap paket IP yang datang dari network 192.168.10.0/24 & perlu diteruskan (forward) ke network 10.10.10.0/24. Setelah ditambahkan rule tersebut sekarang status iptables-nya menjadi seperti ini :

[root@host01 ~]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     all  --  192.168.10.0/24      10.10.10.0/24
2    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

[root@host01 ~]#

Lalu saya ulang lagi proses ping dari mesin centosdev01 :

ttirtawi@centosdev01:~$ date; ping -c 5 10.10.10.100 ; date;
Wed Jun 25 23:27:17 WIB 2014
PING 10.10.10.100 (10.10.10.100) 56(84) bytes of data.

--- 10.10.10.100 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 13999ms

Wed Jun 25 23:27:31 WIB 2014
ttirtawi@centosdev01:~$

Hmm aneh, sekarang error “Destination Host Prohibited” sudah hilang tetap centosdev01 tidak menerima respon sama sekali dari host02.

Lalu saya lihat hasil tcpdump dari mesin host01 :

[root@host01 ~]# tcpdump 'icmp' -i any
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
23:27:11.934105 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 1, length 64
23:27:11.934145 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 1, length 64
23:27:11.934482 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 22054, seq 1, length 64
23:27:11.934510 IP 10.10.10.1 > 10.10.10.100: ICMP host 192.168.10.50 unreachable - admin prohibited, length 92
23:27:12.932914 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 2, length 64
23:27:12.932952 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 2, length 64
23:27:12.933250 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 22054, seq 2, length 64
23:27:12.933278 IP 10.10.10.1 > 10.10.10.100: ICMP host 192.168.10.50 unreachable - admin prohibited, length 92
23:27:13.934175 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 3, length 64
23:27:13.934209 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 3, length 64
23:27:13.935047 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 22054, seq 3, length 64
23:27:13.935096 IP 10.10.10.1 > 10.10.10.100: ICMP host 192.168.10.50 unreachable - admin prohibited, length 92
23:27:14.934132 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 4, length 64
23:27:14.934165 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 4, length 64
23:27:14.934906 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 22054, seq 4, length 64
23:27:14.934974 IP 10.10.10.1 > 10.10.10.100: ICMP host 192.168.10.50 unreachable - admin prohibited, length 92
23:27:15.933361 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 5, length 64
23:27:15.933385 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 5, length 64
23:27:15.933723 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 22054, seq 5, length 64
23:27:15.933750 IP 10.10.10.1 > 10.10.10.100: ICMP host 192.168.10.50 unreachable - admin prohibited, length 92
^C
20 packets captured
20 packets received by filter
0 packets dropped by kernel
[root@host01 ~]#

Memang betul ICMP request yang datang dari centosdev01 sudah diteruskan oleh host01, tapi giliran host01 yang menolak untuk meneruskan ICMP response (dengan error “admin prohibited”) dari ke host02 ke centosdev01. Ini bisa dicek juga dari hasil tcpdump di mesin host02 :

[root@host02 ~]# tcpdump 'icmp' -i any
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
23:27:11.993363 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 1, length 64
23:27:11.993418 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 22054, seq 1, length 64
23:27:11.993647 IP 10.10.10.1 > 10.10.10.100: ICMP host 192.168.10.50 unreachable - admin prohibited, length 92
23:27:12.992696 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 2, length 64
23:27:12.992728 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 22054, seq 2, length 64
23:27:12.992946 IP 10.10.10.1 > 10.10.10.100: ICMP host 192.168.10.50 unreachable - admin prohibited, length 92
23:27:13.993813 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 3, length 64
23:27:13.993865 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 22054, seq 3, length 64
23:27:13.994397 IP 10.10.10.1 > 10.10.10.100: ICMP host 192.168.10.50 unreachable - admin prohibited, length 92
23:27:14.994224 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 4, length 64
23:27:14.994282 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 22054, seq 4, length 64
23:27:14.994854 IP 10.10.10.1 > 10.10.10.100: ICMP host 192.168.10.50 unreachable - admin prohibited, length 92
23:27:15.993411 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 22054, seq 5, length 64
23:27:15.993441 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 22054, seq 5, length 64
23:27:15.993683 IP 10.10.10.1 > 10.10.10.100: ICMP host 192.168.10.50 unreachable - admin prohibited, length 92
^C
15 packets captured
15 packets received by filter
0 packets dropped by kernel
[root@host02 ~]#

Terlihat ICMP reply yang dari host01 terhalang lagi oleh firewall-nya host01.

TES#5 : IP Forwarding ON, Firewall ON + Modifikasi 2 IPTABLES host01

Melanjukan Tes#4 sekarang saya perlu memodifikasi sekali lagi firewall di host01 untuk mengijinkan ICMP reply dari host01 diteruskan ke centosdev01 :

[root@host01 ~]# iptables -I FORWARD -s 10.10.10.0/24 -d 192.168.10.0/24 -j ACCEPT

Kalau di Tes#4 saya tambahkan rule untuk mengijinkan ICMP request diteruskan ke host02, kali ini saya menambah rule untuk mengijinkan ICMP reply dari host02 diteruskan kembali sampai ke centosdev01.

[root@host01 ~]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  10.10.10.0/24        192.168.10.0/24     
2    ACCEPT     all  --  192.168.10.0/24      10.10.10.0/24       
3    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         

[root@host01 ~]# 

Dengan penambahan rule baru tadi, sekarang centosdev01 bisa sukses menerima ICMP response dari host02 :

ttirtawi@centosdev01:~$ date; ping -c 5 10.10.10.100 ; date;
Wed Jun 25 23:35:56 WIB 2014
PING 10.10.10.100 (10.10.10.100) 56(84) bytes of data.
64 bytes from 10.10.10.100: icmp_seq=1 ttl=63 time=1.78 ms
64 bytes from 10.10.10.100: icmp_seq=2 ttl=63 time=1.72 ms
64 bytes from 10.10.10.100: icmp_seq=3 ttl=63 time=1.64 ms
64 bytes from 10.10.10.100: icmp_seq=4 ttl=63 time=1.47 ms
64 bytes from 10.10.10.100: icmp_seq=5 ttl=63 time=1.41 ms

--- 10.10.10.100 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4009ms
rtt min/avg/max/mdev = 1.414/1.606/1.781/0.146 ms
Wed Jun 25 23:36:01 WIB 2014
ttirtawi@centosdev01:~$

[root@host01 ~]# tcpdump 'icmp' -i any
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
23:35:51.231061 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 1, length 64
23:35:51.231114 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 1, length 64
23:35:51.231668 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 1, length 64
23:35:51.231706 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 1, length 64
23:35:52.233623 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 2, length 64
23:35:52.233653 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 2, length 64
23:35:52.234198 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 2, length 64
23:35:52.234213 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 2, length 64
23:35:53.235304 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 3, length 64
23:35:53.235339 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 3, length 64
23:35:53.235733 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 3, length 64
23:35:53.235753 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 3, length 64
23:35:54.237099 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 4, length 64
23:35:54.237120 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 4, length 64
23:35:54.237484 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 4, length 64
23:35:54.237499 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 4, length 64
23:35:55.238437 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 5, length 64
23:35:55.238459 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 5, length 64
23:35:55.238788 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 5, length 64
23:35:55.238795 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 5, length 64
^C
20 packets captured
20 packets received by filter
0 packets dropped by kernel
[root@host01 ~]#

[root@host02 ~]# tcpdump 'icmp' -i any
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
23:35:51.300537 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 1, length 64
23:35:51.300598 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 1, length 64
23:35:52.303103 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 2, length 64
23:35:52.303139 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 2, length 64
23:35:53.304529 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 3, length 64
23:35:53.304568 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 3, length 64
23:35:54.306771 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 4, length 64
23:35:54.306810 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 4, length 64
23:35:55.308507 IP 192.168.10.50 > 10.10.10.100: ICMP echo request, id 50472, seq 5, length 64
23:35:55.308544 IP 10.10.10.100 > 192.168.10.50: ICMP echo reply, id 50472, seq 5, length 64
^C
10 packets captured
10 packets received by filter
0 packets dropped by kernel
[root@host02 ~]# 

Dari beberapa tes tersebut saya jadi makin yakin bahwa mengaktifkan IP Forwarding perlu mempertimbangkan kondisi Firewall yang sedang aktif. Tanpa pengaturan firewall yang benar, IP paket tetap tidak bisa diteruskan (di-forward) ke tujuan.

1 thought on “Sekilas Tentang IP Forwarding

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.