Deneme yazısı
LINUX IP ROUTE (ip_route )
linux te yonlendirme icin tablolar vardir. on tanimli olarak iki adet tablo mevcuttur
local : network ayarlari yapildiktan sonra sistem tarafindan olusturulur. direk erisebilicegimiz networkler ve broadcast adresleri ip rule show ile bakildiginda ilk asamada tum trafik bu table a yonlendirilir fkat direk erisimler sadece yazildigindan aykiri durumlar match edilemez ve bir sonraki table a gonderilir.
main : en sonda paketler bu table a gelir route -n ciktisi budur. bildigimiz route add -del vs buna ekleme yapar. local gibi tum istekler buraya yonledirilir fakat en sonda buradada bir esleme yapilmazsa network e ulasilamaz hatasi verir. bu durumalar icin default gw ayarlanmali .
digerleri : /etc/iproute2/rt_tables dosyasinda hangi tablolarin oldugu gorulebilir.
bir paketin hedefine ulasmasi icin olmazsa olmaz sey routingtir. paketi hangi interface den ne sekilde verecegini bilmesi gerekir.
nat paketin ip headerinin degistirilmesi islemidir. paketin routinglerde belirtilen yerlere ulastirilirken geri donebilmesi icin gereklidir.
bir ornekte aciklayacak olursak :

bizim ip adresimiz 192.168.10.6 gw 192.168.10.1 , gw bizi natlamayip paketlerimizi oldugu gibi verirse pketler bize geri donmeyecekti.
192.168.0.71 makinesinin routin tablosu asagidaki gibidir.
root@paterson:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.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 1000 0 0 eth0
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
bu durumda ping attigimizda paket natlanmadigindan 192.168.10.6 ip adresinden gelecek , routing tablosuna gore gw (192.168.0.1) e gonderilmesi gereken bir paket oldugundan paket bize geri gelemeycektir.
tcpdump gosterimi .
kendi makinemden ping atiyorum sonuc asagida
root@erhan-ubuntu:/home/erhan# ping 192.168.0.71
PING 192.168.0.71 (192.168.0.71) 56(84) bytes of data.
— 192.168.0.71 ping statistics —
3 packets transmitted, 0 received, 100% packet loss, time 2008ms
gatewayim olan 192.168.10.1 de tcpdump ile dinledigimde 3 ping paketini 6 paket olarak gosteriyor. yani her ping icin 2 tcpdump ciktisi. tcpdump her interface icin tanima uygun olan ciktilari verir.
[root@orkim root]# tcpdump -i any -nn icmp
tcpdump: WARNING: Promiscuous mode not supported on the “any” device
tcpdump: listening on any
09:47:15.634777 192.168.10.6 > 192.168.0.71: icmp: echo request (DF)
09:47:15.634824 192.168.10.6 > 192.168.0.71: icmp: echo request (DF)
09:47:16.643130 192.168.10.6 > 192.168.0.71: icmp: echo request (DF)
09:47:16.643156 192.168.10.6 > 192.168.0.71: icmp: echo request (DF)
09:47:17.643224 192.168.10.6 > 192.168.0.71: icmp: echo request (DF)
09:47:17.643248 192.168.10.6 > 192.168.0.71: icmp: echo request (DF)
gelen isteklerin hicbirinin cevabi donmuyor oysaki ping in ulastigi pc de tcpdump ciktisi asagidaki gibidir.
root@paterson:~# tcpdump -i any -tnn icmp
tcpdump: WARNING: Promiscuous mode not supported on the “any” device
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 96 bytes
IP 192.168.10.6 > 192.168.0.71: ICMP echo request, id 36893, seq 1, length 64
IP 192.168.0.71 > 192.168.10.6: ICMP echo reply, id 36893, seq 1, length 64
IP 192.168.10.6 > 192.168.0.71: ICMP echo request, id 36893, seq 2, length 64
IP 192.168.0.71 > 192.168.10.6: ICMP echo reply, id 36893, seq 2, length 64
IP 192.168.10.6 > 192.168.0.71: ICMP echo request, id 36893, seq 3, length 64
IP 192.168.0.71 > 192.168.10.6: ICMP echo reply, id 36893, seq 3, length 64
gelen her 3 request paketine replay dondu , fakat bize degil kendi gw i olan 192.168.0.1 e gonderdi cevaplar.
paket yukardaki gibi natlanmamistir ve ulastigimiz server in gw adresi bizim gw olarak kullandigimiz cihazdan farklidir. gw i bizim ulastigimiz gw olan 192.168.0.133 olarak degistirisek
root@paterson:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.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 1000 0 0 eth0
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
root@paterson:~# route del default
root@paterson:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.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 1000 0 0 eth0
root@paterson:~# route add default gw 192.168.0.133
root@paterson:~#
root@paterson:~#
root@paterson:~#
root@paterson:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.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 1000 0 0 eth0
0.0.0.0 192.168.0.133 0.0.0.0 UG 0 0 0 eth0
yukarida gw degistigi pinglerimizin basarili olmasina yeter.
root@erhan-ubuntu:/home/erhan# ping 192.168.0.71
PING 192.168.0.71 (192.168.0.71) 56(84) bytes of data.
64 bytes from 192.168.0.71: icmp_seq=1 ttl=63 time=0.460 ms
64 bytes from 192.168.0.71: icmp_seq=2 ttl=63 time=0.427 ms
64 bytes from 192.168.0.71: icmp_seq=3 ttl=63 time=0.423 ms
— 192.168.0.71 ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.423/0.436/0.460/0.029 ms
yukaridaki durumlar snat yapildigi bir durumda olusmaz. yani
iptables -t nat -A POSTROUTING -s 192.168.10.0/255.255.255.0 -o eth0 -j SNAT –to-source 192.168.0.133
girilmesi durumunda 192.168.0.69 ip adresli pc paketlerin 192.168.0.133 ten geldigini gorup kendi networkunde oldugundan gw kullanmadan geri gonderecektir.
fakat dnat islemi ile ulasmak istedigimizde paketlerin gw e gonderilmesi durumu olusur.
iptables -t nat -A PREROUTING -d 192.168.0.133 -p tcp -m tcp –dport 80 -j DNAT –to-destination 192.168.0.69
yani yukaridaki komut ile 192.168.10.1 in 5000. portuna telnet cektigimizde paketler 192.168.0.69 a ulasacaktir fakat paketlerin kaynak adresi 192.168.10.6
oldugundan SYN nin ACK sini 192.168.0.1 e gonderecektir.
192.168.0.69 :
root@acar:~# nc -l -p 5000
tcpdump -i any -nn port 5000
14:23:35.790915 IP 192.168.10.6.52544 > 192.168.0.69.5000: S 967002117:967002117(0) win 5840 <mss 1460,sackOK,timestamp 4
14:23:35.791148 IP 192.168.0.69.5000 > 192.168.10.6.52544: S 855957238:855957238(0) ack 967002118 win 5792 <mss 1460,sackOK,
14:23:38.787645 IP 192.168.10.6.52544 > 192.168.0.69.5000: S 967002117:967002117(0) win 5840 <mss 1460,sackOK,timestamp 4
14:23:38.787705 IP 192.168.0.69.5000 > 192.168.10.6.52544: S 855957238:855957238(0) ack 967002118 win 5792 <mss 1460,sackOK,
yukarida cevap deonuyormus gibi gorunuyor fakat son ack gelmiyor bunun sebebi syn icin gonderilen ack 192.168.0.1 gatewayine gonderiliyor
bunu daha net bizim gatewaymiz 192.168.10.1 den de gorebilirz.
192.168.10.1:
[root@orkim root]# tcpdump -i any -nn port 5000
tcpdump: WARNING: Promiscuous mode not supported on the “any” device
tcpdump: listening on any
14:26:16.555245 192.168.10.6.52544 > 192.168.10.1.5000: S 967002117:967002117(0) win 5840 <mss 1460,sackOK,
14:26:16.555304 192.168.10.6.52544 > 192.168.0.69.5000: S 967002117:967002117(0) win 5840 <mss 1460,sackOK
14:26:19.552153 192.168.10.6.52544 > 192.168.10.1.5000: S 967002117:967002117(0) win 5840 <mss 1460,sackOK,
14:26:19.552197 192.168.10.6.52544 > 192.168.0.69.5000: S 967002117:967002117(0) win 5840 <mss 1460,sackOK,
her paketi ve natlanmis halini yorida goruyoruz paket 192.168.0.69 a ulastiginda kaynak ip adresi 192.168.10.6 alorak
gorunuyor. kaynak ip kendi networkunde olmadigindan paketi gw e gonderiyor.
buradaki test te tem cihazlar linu ve tcpdump oldugundan olan olaylari kolayca gorebiliyoruz . peki ya bu durumun
boyle oldugundan nasil emin olabilriz (bu paetlerin geri donmemesi cihazin kapali oldugu durumlarda aradaki veya uzerindeki
firewall un droplamasi veya paketin hedefine hic ulasamasi durumlarda da ayni durum olur.
192.168.10.1 den 192.168.0.69 a telnet cekersek 192.168.0.133 olarak gonderecek ve gw kullanmayacak
ve cevap verecek durumda ise bize cevabi geri gonderecektir.
192.168.10.1 (192.168.0.133 ) :
[root@orkim root]# telnet 192.168.0.69 5000
Trying 192.168.0.69…
Connected to 192.168.0.69 (192.168.0.69).
Escape character is ‘^]’.
telnet basarili bir sekilde gerceklesti bu durmda 192.168.0.69 da 5000 den hizmet veren bir servis var (netcat -l -p 5000)
192.168.10.6 dan erisim icin yapmamiz gereken orkim firewall u uzerinde bir snat ekleyip
paketlerin 192.168.0.0/24 netorkune giderken 192.168.0.133 olarak gitmesini saglamaktir.
iptables -t nat -I POSTROUTING -s 192.168.10.6 -o eth0 -j SNAT –to-source 192.168.0.133
[root@orkim root]# tcpdump -i any -nn port 5000
tcpdump: WARNING: Promiscuous mode not supported on the “any” device
tcpdump: listening on any
192.168.10.6.39888 > 192.168.10.1.5000: S 1950299584:1950299584(0) win 5840 <mss 1460,sackOK,
192.168.0.133.39888 > 192.168.0.69.5000: S 1950299584:1950299584(0) win 5840 <mss 1460,sackOK,
192.168.0.69.5000 > 192.168.0.133.39888: S 459558931:459558931(0) ack 1950299585 win 5792 <mss 1460,sackOK,
192.168.10.1.5000 > 192.168.10.6.39888: S 459558931:459558931(0) ack 1950299585 win 5792 <mss 1460,sackOK,
192.168.10.6.39888 > 192.168.10.1.5000: . ack 1 win 183 <nop,nop,timestamp 5199281 4546115> (DF) [tos 0x10]
192.168.0.133.39888 > 192.168.0.69.5000: . ack 1 win 183 <nop,nop,timestamp 5199281 4546115> (DF) [tos 0x10]
burdan su sonucu cikariyoruz :