Minggu, 27 April 2008

VNET2: TUN/TAP

TUN/TAP adalah salah satu sarana virtual network point to point antara Linux host dan UML.

Di sini kita akan coba sambung host Jawa dengan IP=10.0.1.254 dan UML merapi IP=10.0.1.1. Untuk melakukan hal ini login sebagai user biasa di host, jalankan GUI, dan luncurkan terminal.


* LUNCURKAN UML DENGAN TUN/TAP
Luncurkan UML merapi (COW) sebagai berikut

tux@jawa:$ linux ubd0=merapi.cow eth0=tuntap,,,10.0.1.254 &

## Lihat syntax-nya
## eth0 = nama device di dalam UML
## tuntap = jenis koneksi
## 10.0.1.254 = alamat IP host

* ATUR NETWORK UML
Setelah UML jalan, silahkan login sebagai root. Lalu kita bisa atur networking-nya pakai netconfig

## Cara Manual
root@uml:$ ifconfig eth0 10.0.1.1 netmask 255.255.255.0 up

## Cara permanen di Vector Linux/Slackware
root@uml:$ netconfig

## Ikuti saja menunya, isikan
## Name = merapi
## domain = vnet
## Tipe IP = static
## IP = 10.0.1.1
## Netmask = 255.255.255.0
## Gateway = 10.0.1.254
## DNS = 10.0.1.254 (host Jawa, kalau ada DNS-nya)

## Kalau sudah reboot, atau jalankan
root@uml:# /etc/rc.d/rc.inet1

## Periksa network
root@uml# ifconfig
eth0 Link encap:Ethernet HWaddr FE:FD:0A:00:01:01
inet addr:10.0.1.1 Bcast:10.0.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:5

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:252 (252.0 b) TX bytes:252 (252.0 b)

Nah terlihat kalau network eth0 sudah UP.

* PERIKSA NETWORK HOST
Setelah UML jalan, luncurkan terminal lain untuk periksa apakah network host sudah siap sbb.

## jadi superuser
tux@jawa:$ su
password: ******

root@jawa:# ifconfig
eth0 Link encap:Ethernet HWaddr 00:20:ED:77:A5:B1
inet addr:10.0.0.1 Bcast:10.0.0.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:116 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:23515 (22.9 Kb)
Interrupt:11 Base address:0xc000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

tap0 Link encap:Ethernet HWaddr 00:FF:5E:F3:51:5B
inet addr:10.0.1.254 Bcast:10.255.255.255 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

Terlihat bahwa host punya device tap0 yang sudah UP dengan IP 10.0.1.254. Semantara itu terlihat juga bahwa host punya eth0. Itu device betulan yang terhubung ke network betulan (kantor). Abaikan saja eth0 ini.

* TESTING DARI UML
Coba ...

## Test ping
root@merapi:# ping -c 3 10.0.1.1
PING 10.0.1.254 (10.0.1.254): 56 octets data
64 octets from 10.0.1.254: icmp_seq=0 ttl=64 time=0.3 ms
64 octets from 10.0.1.254: icmp_seq=1 ttl=64 time=0.3 ms
64 octets from 10.0.1.254: icmp_seq=2 ttl=64 time=0.3 ms

--- 10.0.1.254 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.3/0.3/0.3 ms

## Nah, ping OK, berarti network sudah terhubung
## Test remote login dari UML ke host
root@merapi:# ssh tux@10.0.1.254
The authenticity of host '10.0.1.254 (10.0.1.254)' can't be established.
RSA key fingerprint is ec:80:09:da:90:da:a9:08:14:33:b6:d6:54:10:3d:03.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.1.254' (RSA) to the list of known hosts.
tux@10.0.1.254's password:
Linux 2.4.24-win4lin. Type vasm to enter setup menu.
tux@jawa:$

## Yohoo ... kita sudah di host Jawa
## Respond SSH tadi normal jika ini koneksi pertama
## Nanti koneksi selanjutnya tidak akan ditanya soal RSA lagi

Buat yang belum tahu, ssh itu client untuk login remote ke host unix (Linux, FreeBSD, MacOS, dll). Ini gantinya telnet yang lebih secure.

* SEBALIKNYA DARI HOST
Coba ...

tux@jawa:$ ping -c 3 10.0.1.1
PING 10.0.1.1 (10.0.1.1): 56 octets data
64 octets from 10.0.1.1: icmp_seq=0 ttl=64 time=0.2 ms
64 octets from 10.0.1.1: icmp_seq=1 ttl=64 time=0.2 ms
64 octets from 10.0.1.1: icmp_seq=2 ttl=64 time=0.2 ms

--- 10.0.1.1 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.2/0.2/0.2 ms

## Koneksi OK
## sekarang coba remote login
tux@jawa:$ ssh root@10.0.1.1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
ec:80:09:da:90:da:a9:08:14:33:b6:d6:54:10:3d:03.
Please contact your system administrator.
Add correct host key in /home/tux/.ssh/known_hosts to get rid of this message.
Offending key in /home/tux/.ssh/known_hosts:5
RSA host key for 10.0.1.1 has changed and you have requested strict checking.
Host key verification failed.

Lhadalah ... ada apa itu ? Tenang, itu respond yang normal dari SSH kalau 10.0.1.1 ganti mesin. Kalau kita main-main UML, itu kejadian lumrah. Mari kita betulkan ...

## Periksa isi $HOME/.ssh/known_hosts
tux@jawa:$ cat ~/.ssh/known_hosts
localhost ssh-rsa AAAAB3NzaC1yc2EAAAABIw... (dipotong)
papua.vnet,10.0.0.5 ssh-rsa AAAAB3NzaC1y... (dipotong)
10.0.1.1 ssh-rsa AAAAB3NzaC1yc2EAAAABIwA... (dipotong)

## Nah terlihat kalau 10.0.1.1 ini sudah punya entry lama.
## Hapus saja baris 10.0.1.1 itu pakai editor
## atau cara hacker ...
tux@jawa:$ grep -v 10.0.1.1 ~/.ssh/known_hosts | cat > ~/.ssh/known_host

## atau cara kasar :)
tux@jawa:$ rm ~/.ssh/known_hosts

## Coba SSH lagi
tux@jawa:$ ssh root@10.0.1.1
The authenticity of host '10.0.1.1 (10.0.1.1)' can't be established.
RSA key fingerprint is ec:80:09:da:90:da:a9:08:14:33:b6:d6:54:10:3d:03.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.1.1' (RSA) to the list of known hosts.
root@10.0.1.1's password: *****
Linux 2.4.22. Type vasm to enter setup menu.
root@merapi:#

## Silahkan main-main di konsole
## Kalau sudah puas, logout
root@merapi:# exit
logout
Connection to 10.0.1.1 closed.
tux@jawa#

Selesai sudah. Network TUN/TAP kita sudah beres. Anda bisa coba sendiri berbagai client dari Merapi untuk akses server di Jawa (kalau jalan), misalnya:

1. dig atau nslookup, kalau di host Jawa ada DNS (bind).
2. lynx untuk akses HTTP (apache)
3. ftp untuk akses FTP server (ProFTP).
4. smbclient untuk akses SAMBA (smnd, nmbd).

Tidak ada komentar: