SlideShare una empresa de Scribd logo
1 de 43
UNIX OS
Lecture IV
Simonas Kareiva
Vilnius University
Faculty of Mathematics
and Informatics
Preparation of the material was supported by the project „Increasing Internationality in Study
Programs of the Department of Computer Science II“, project number VP1–2.2–ŠMM-07-K-
02-070, funded by The European Social Fund Agency and the Government of Lithuania.
Lecture #4 outline (part I)
Introduction to TCP/IP and OSI. IP addressing
IP and MAC address relation
UNIX OS networking
ping and traceroute
arp, ifconfig and route
2
TCP/IP
Set of data transfer protocols (HTTP / FTP / DNS / …)
Created 1973-1974, installed 1983
Abstraction levels (see further)
Encapsulation
OSI model
3
4
5
In theory
Computer 2RouterRouterComputer 1
6
Real life (simplified)
Computer 2
Router
Router
Computer 1 Router
Router
Router
7
How does communication work?
Ethernet
Satellite
connecti
on/
optics/
etc.
WiFi
Application
Transport
Network
Connection
Application
Transport
Network
Connection
Network
Connection
Network
Connection
8
IP address and mask
192.168.1.112/22
11000000.10101000.00000001.11100000
255.255.252.0
192.168.1.0 - ?
192.168.3.225 - ?
9
Task
IP address is 10.250.1.48/19
Questions:
 What is the expression of this network mask in full format?
 What is the maximum number of computers that can be
connected to this network?
 What’s the class of this IP address?
10
Answer comes from ipcalc
> ipcalc 10.250.1.48/19
addresss: 10.250.1.48 00001010.11111010.000 00001.00110000
Netmask: 255.255.224.0 = 19 11111111.11111111.111 00000.00000000
Wildcard: 0.0.31.255 00000000.00000000.000 11111.11111111
=>
Network: 10.250.0.0/19 00001010.11111010.000 00000.00000000
HostMin: 10.250.0.1 00001010.11111010.000 00000.00000001
HostMax: 10.250.31.254 00001010.11111010.000 11111.11111110
Broadcast: 10.250.31.255 00001010.11111010.000 11111.11111111
Hosts/Net: 8190 Class A, Private Internet
11
Another IP writing method
#!/bin/sh
IPTONUM ()
{
IP=$1; IPNUM=0
for (( i=0 ; i<4 ; ++i )); do
((IPNUM+=${IP%%.*}*$((256**$((3-${i}))))))
IP=${IP#*.}
done
echo $IPNUM
}
NUMTOIP ()
{
echo -n $(($(($(($((${1}/256))/256))/256))%256)).
echo -n $(($(($((${1}/256))/256))%256)).
echo -n $(($((${1}/256))%256)).
echo $((${1}%256))
}
12
IP classes (historical)
Class First octet in
binary system
First octet
from-to
Network
identifier
Ammount of
networks
A 0XXXXXXX 0 - 127 a. 27
= 128
B 10XXXXXX 128 - 191 a.b. 214
= 16,384
C 110XXXXX 192 - 223 a.b.c. 221
=
2,097,152
13
MAC address
08:00:20:d1:b0:0a
 080020 – Sun Microsystems Inc.
 d1b00a – unique product ID
MAC / IP connection
DHCP
 static DHCP
 dynamic DHCP
14
Working in network with UNIX OS
talk jonas@developers.firma.lt
lynx www.delfi.lt
echo pse call| mail –s important evelina@pardavimai
ping 192.168.0.1
ifconfig
15
ifconfig
> ifconfig
eth0 Link encap:Ethernet HWaddr 00:22:15:88:9c:93
inet addr:82.135.156.42 Bcast:82.135.156.255 Mask:255.255.255.0
inet6 addr: fe80::222:15ff:fe88:9c93/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2038944517 errors:0 dropped:0 overruns:0 frame:0
TX packets:2634746425 errors:0 dropped:0 overruns:0 carrier:1
collisions:0 txqueuelen:1000
RX bytes:592322463 (592.3 MB) TX bytes:3453432517 (3.4 GB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:5318385 errors:0 dropped:0 overruns:0 frame:0
TX packets:5318385 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2254159344 (2.2 GB) TX bytes:2254159344 (2.2 GB)
16
ping
> ping 24.93.4.206
PING 24.93.4.206 (24.93.4.206): 56 data bytes
64 bytes from 24.93.4.206: icmp_seq=0 ttl=240 time=157.010 ms
64 bytes from 24.93.4.206: icmp_seq=1 ttl=240 time=151.762 ms
64 bytes from 24.93.4.206: icmp_seq=2 ttl=240 time=314.532 ms
ping: sendto: Network is down
ping: sendto: Network is down
ping: sendto: Network is down
^C
--- 24.93.4.206 ping statistics ---
6 packets transmitted, 3 packets received, 50% packet loss
round-trip min/avg/max/stddev = 151.762/207.768/314.532/75.524 ms
17
traceroute
> traceroute cisco.netacad.net
traceroute to cisco.netacad.net (128.107.229.50), 30 hops max, 40 byte packets
1 gw.ep.lt (82.135.156.254) 0.966 ms 0.940 ms 0.926 ms
2 212-59-21-193.static.telecom.lt (212.59.21.193) 2.727 ms 2.716 ms 2.703 ms
3 213-190-60-93.telecom.lt (213.190.60.93) 2.892 ms 2.880 ms 2.868 ms
4 war-b3-link.telia.net (213.248.85.89) 11.790 ms 11.779 ms 11.766 ms
5 hbg-bb2-link.telia.net (80.91.251.217) 37.136 ms 37.124 ms 37.112 ms
6 ldn-bb2-link.telia.net (80.91.249.14) 41.709 ms ldn-bb2-link.telia.net (80.91.250.151)
41.859 ms ldn-bb2-link.telia.net (80.91.254.7) 41.842 ms
7 ash-bb1-link.telia.net (80.91.251.209) 123.663 ms 123.964 ms ash-bb1-link.telia.net
(213.248.65.210) 125.426 ms
8 192.205.34.209 (192.205.34.209) 122.910 ms 123.278 ms *
9 cr1.wswdc.ip.att.net (12.122.135.14) 196.349 ms 195.994 ms 195.979 ms
10 cr2.phlpa.ip.att.net (12.122.4.53) 197.221 ms 199.154 ms 199.135 ms
11 cr2.cl2oh.ip.att.net (12.122.2.209) 215.193 ms 213.361 ms 213.550 ms
12 cr1.cl2oh.ip.att.net (12.122.2.125) 213.099 ms 221.672 ms 221.645 ms
13 cr1.cgcil.ip.att.net (12.122.2.205) 222.744 ms 222.733 ms 222.720 ms
14 cr1.sffca.ip.att.net (12.122.4.121) 221.392 ms 221.377 ms 221.366 ms
15 gar1.sj2ca.ip.att.net (12.123.15.1) 205.537 ms 203.746 ms 203.730 ms
16 12.118.124.10 (12.118.124.10) 228.697 ms 228.684 ms 228.673 ms
17 sjck-dmzbb-gw1.cisco.com (128.107.239.9) 190.264 ms 190.251 ms 190.652 ms
18 sjc12-dmzbb-gw1-g1-37.cisco.com (128.107.224.165) 302.883 ms 302.868 ms 302.650 ms
19 sjc12-dmzdc-gw1-gig5-2.cisco.com (128.107.224.22) 303.049 ms 303.037 ms 303.025 ms
20 * * *
21 * * *
22 * * *
18
arp
> arp -an
? (82.135.156.222) at 00:c0:02:2a:4e:6d [ether] on eth0
? (82.135.156.16) at 00:15:60:57:06:cd [ether] on eth0
? (82.135.156.83) at 00:0e:0c:4e:62:f8 [ether] on eth0
? (82.135.156.84) at 00:06:29:39:63:c3 [ether] on eth0
? (82.135.156.6) at 00:80:a3:8c:0d:72 [ether] on eth0
? (82.135.156.88) at 00:11:d8:94:a9:4a [ether] on eth0
? (82.135.156.21) at 00:18:f3:87:31:17 [ether] on eth0
? (82.135.156.15) at 00:0e:a6:34:37:a1 [ether] on eth0
? (82.135.156.23) at 00:0c:f1:ed:c8:56 [ether] on eth0
? (82.135.156.55) at 00:10:5a:5a:06:f1 [ether] on eth0
? (82.135.156.254) at 00:30:48:88:d9:1e [ether] on eth0
? (82.135.156.201) at 00:08:02:ef:fa:a4 [ether] on eth0
19
route
> route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
193.219.94.168 82.135.156.254 255.255.255.255 UGH 0 0 0 eth0
193.219.94.141 82.135.156.254 255.255.255.255 UGH 0 0 0 eth0
82.135.156.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 82.135.156.254 0.0.0.0 UG 100 0 0 eth0
20
Routing
Computer 2
172.16.0.2/28
Router 3
Router 1
Computer 1
192.168.1.1/24
Router 2
Computer 3
192.168.3.1/24
internet
21
22
23
24
Lecture #4 outline (part II)
Overview of UNIX command line tools:
 cut
 diff
 awk
 sed
 expand
 grep
 strings
 tr
 uniq
 zcat
25
cut
> echo aa:bb cc dd:ee | cut -d : -f 2
bb cc dd
> echo aa:bb cc dd:ee | cut -d " " -f 2
cc
> echo aa:bb cc dd:ee | cut -d " " -f 1,2
aa:bb cc
> echo aa:bb cc dd:ee | cut -d " " -f 1,2,3
aa:bb cc dd:ee
> cut -d : -f 1,5 /etc/passwd | tail -3
_installer:Installer
_atsserver:ATS Server
_unknown:Unknown User
26
diff
> echo "Firstnsecond" > 1.txt
> echo "Firstnthird" > 2.txt
> diff 1.txt 2.txt
2c2
< second
---
> third
> diff 1.txt 2.txt > diff.txt
> patch -p0 1.txt < diff.txt
patching file 1.txt
> cat 1.txt
First
third
27
expand
> printf "atbn"
a b
> printf "atbn" | hexdump
0000000 0961 0a62
0000004
> printf "atbn" | expand | hexdump
0000000 2061 2020 2020 2020 0a62
000000a
28
grep
> grep ^a /etc/passwd
alias:*:81:81:User &:/var/qmail/alias:/nonexistent
> grep ^c /etc/passwd
cyrus:*:60:60:the cyrus mail server:/nonexistent:/sbin/nologin
courier:*:465:465:Courier Mail
System:/var/spool/courier:/sbin/nologin
> grep -c nologin$ /etc/passwd
29
> tail -f httpd-error.log | grep denied
[Sun Oct 4 19:18:12 2012] [error] [client 78.60.155.45]
(13)Permission denied: cannot read directory for multi:
/users/eduardas/www/
> grep -E '(error|failure)' /var/log/console | grep -vc connect_to
1945
29
strings
> strings /var/log/wtmp | grep -A4 simonask
simonask
88.223.26.58
Jttypa
Jttypc
Jttypa
> strings /bin/sync | grep error
$FreeBSD: src/lib/libc/i386/sys/cerror.S,v 1.10 1999/08/27 23:59:38
peter Exp $
error:
Authentication error
Exec format error
Input/output error
Undefined error: 0
30
tr
> cat bug.lt | tr e 3
W3 ar3 us3r group of BSD syst3ms.
Th3 group was 3stablish3d in th3 summ3r of 2002.
It happ3n3d in small city of North Lithuania.
> cat bug.lt | tr '[a-z]' '[A-Z]'
WE ARE USER GROUP OF BSD SYSTEMS.
THE GROUP WAS ESTABLISHED IN THE SUMMER OF 2002.
IT HAPPENED IN SMALL CITY OF NORTH LITHUANIA.
31
uniq
> grep DNS ppp.log | awk '{ print $10 }' | sort | uniq
194.176.32.142
194.176.32.163
> grep Illegal cache.log | tail -1
2009/10/04 19:37:34| urlParse: Illegal character in hostname
'www,youtube.lt’
> grep Illegal cache.log | cut -d " " -f 8 | sort | uniq -c | sort
-rn | head
760 '[2a01:138:a001:201:'
57 '2a01%3a138%3aa001%3a201%3a%3a24'
57 '2a01%3a138%3aa001%3a201%3a%3a23'
57 '2a01%3a138%3aa001%3a201%3a%3a22'
57 '2a01%3a138%3aa001%3a201%3a%3a21'
12 '%20ssl.google-analytics.com'
7 'www,youtube,com'
4 'evi ka-pc'�
3 'www,youtube.lt'
3 'vista.%20liedm.lt’
32
zcat
> cat > test2.sh
#!/bin/sh
echo date
exit 0;
> gzip test2.sh
> cat test2.sh.Z
;??Jtest2.shSV?O???/??JM??WHI,I?J??,Q0???d?I>
> zcat test2.sh.Z
#!/bin/sh
echo date
exit 0;
33
sed
> echo day | sed s/day/night/
night
> echo "123 abc" | sed 's/[0-9]*/& &/'
123 123 abc
> echo left right | sed 's/([a-z]*) ([a-z]*)/2 1/'
right left
> sed '/start/,/stop/ s/#.*//'
?
34
sed
Compare:
 sed 's/([a-zA-Z]*) ([a-zA-Z]*) /1 /'
 sed 's/[a-zA-Z]* //2'
 sed 's/./&:/20'
 sed 's/^..................../&:/'
 sed -n 's/jonas/&/p' <file
 grep jonas file
 sed 'y/abcdef/ABCDEF/’
 tr abcdef ABCDEF
35
Exercise (sed)
#!/bin/sh
sed -n '
/begin/,/end/ {
s/#.*//
s/[ ^I]*$//
/^$/ d
p
}
’
36
sed
#!/bin/sh
# A way to clear the lines that start with #
# (comments) between words ‘begin’ and ‘end’
sed -n '
/begin/,/end/ {
s/#.*//
s/[ ^I]*$//
/^$/ d
p
}
'
37
sed (advanced)
> cat cat.txt
This is my cat
my cat's name is betty
This is my dog
my dog's name is frank
> sed 'N;s/n / /;P;D;' cat.txt
This is my cat my cat's name is betty
This is my dog my dog's name is frank
N – adds a second line to the buffer
s – substitution command
/n / - equivalence of a new line and space
/ / - substitution to one space
P – prints first line of buffer
D - deletes the buffer and continues to the next line
38
awk
> ls -l
-rwxrwxrwx@ 1 simonask staff 7497216 Rgs 14 15:59 UNIX_1.pps
> ls -l | awk ' BEGIN { print ”BylattSavininkas" } { print $9,
"tt", $3} END { print " - DONE -" } '
file Owner
UNIX_1.pps simonask
- DONE -
> date
Sunday, 2012 m. spalio 4 d. 20:21:58 EEST
> date | awk '{print $1}'
Sunday,
> date | awk '{print $2}'
2012
39
awk
BEGIN {
print ”enter number";
}
{
print ”Number’ ", $1, ” square is ", $1*$1;
print ”enter one more number";
}
END {
print ”Bye"
}
40
awk
awk '{print $2, $1}' read.txt
awk '{print NR "t" $0}’ read.txt
awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"sn",$0}'
Compare this:
 head -10
 awk 'NR < 11’
 awk '!/search/' read.txt
 grep –v search read.txt
41
Excercises
ls -d *.sh | sed 's/(.*).sh$/cp "&" 1/' | sh
____________________________________________________________
STR="`sed <<<"$STR" "s/(.)/1('s*
+s*')?/g;s/('s*
+s*')?$//"`"
____________________________________________________________
find ${1-.} -type d -print | env LC_ALL='C' sort -if |
sed -e "s,^${1-.},," 
-e "/^$/d" 
-e "s,[^/]*/([^/]*)$,`-----1," 
-e "s,[^/]*/,| ,g"
42
#!/usr/bin/perl -w # camel code
use strict;
$_='ev
al("seek040D
ATA,0, 0;");foreach(1..3)
{<DATA>;}my @camel1hump;my$camel;
my$Camel ;while( <DATA>){$_=sprintf("%-6
9s",$_);my@dromedary 1=split(//);if(defined($
_=<DATA>)){@camel1hum p=split(//);}while(@dromeda
ry1){my$camel1hump=0 ;my$CAMEL=3;if(defined($_=shif
t(@dromedary1 ))&&/S/){$camel1hump+=1<<$CAMEL;}
$CAMEL--;if(d efined($_=shift(@dromedary1))&&/S/){
$camel1hump+=1 <<$CAMEL;}$CAMEL--;if(defined($_=shift(
@camel1hump))&&/S/){$camel1hump+=1<<$CAMEL;}$CAMEL--;if(
defined($_=shift(@camel1hump))&&/S/){$camel1hump+=1<<$CAME
L;;}$camel.=(split(//,"040..m`{/J047134}L^7FX"))[$camel1h
ump];}$camel.="n";}@camel1hump=split(/n/,$camel);foreach(@
camel1hump){chomp;$Camel=$_;y/LJF7173175`047/061062063
064065066067070/;y/12345678/JL7F175173047`/;$_=reverse;
print"$_040$Cameln";}foreach(@camel1hump){chomp;$Camel=$_;y
/LJF7173175`047/12345678/;y/12345678/JL7F1751730 47`/;
$_=reverse;print"040$_$Cameln";}';;s/s*//g;;eval; eval
("seek040DATA,0,0;");undef$/;$_=<DATA>;s/s*//g;( );;s
;^.*_;;;map{eval"print"$_"";}/.{4}/g; __DATA__ 124
1 501450401651631450401571 460401 410
40143141 1551451 540401 51155 141
1471450 40151156 040141 16316 3
157143 15114116 41511 57156
040167 1511641 50040 1201
45162 15404015 1163 04014
10401 641621 41144 145
15514 1162 15304 0157
146 04011 7047 1221
4515 11541 54171 040
046 01210116 316
315 714315 114
116 4145163 054
040 11115614 3056
040 12516314514 4040
1671 511641 500 40160
145162 155151
163163 1511
57156056
43

Más contenido relacionado

La actualidad más candente

Load balancing n_fail_over
Load balancing n_fail_overLoad balancing n_fail_over
Load balancing n_fail_over
miissie
 
Practice exam #2
Practice exam #2Practice exam #2
Practice exam #2
Kris Mofu
 
Dynamic Routing IGRP
Dynamic Routing IGRPDynamic Routing IGRP
Dynamic Routing IGRP
Kishore Kumar
 
Eigrp on a cisco asa firewall configuration
Eigrp on a cisco asa firewall configurationEigrp on a cisco asa firewall configuration
Eigrp on a cisco asa firewall configuration
3Anetwork com
 
Us4031328 conferencing arrangement for use in a pcm system
Us4031328 conferencing arrangement for use in a pcm systemUs4031328 conferencing arrangement for use in a pcm system
Us4031328 conferencing arrangement for use in a pcm system
satyanpitroda
 

La actualidad más candente (20)

Integrated Service Digital Network
Integrated Service Digital NetworkIntegrated Service Digital Network
Integrated Service Digital Network
 
OSPF 3
OSPF 3OSPF 3
OSPF 3
 
Load balancing n_fail_over
Load balancing n_fail_overLoad balancing n_fail_over
Load balancing n_fail_over
 
Switching 2
Switching 2Switching 2
Switching 2
 
Dynamic Routing RIP
Dynamic Routing RIPDynamic Routing RIP
Dynamic Routing RIP
 
Practice exam #2
Practice exam #2Practice exam #2
Practice exam #2
 
Wan Interface Configuration
Wan Interface ConfigurationWan Interface Configuration
Wan Interface Configuration
 
Dynamic Routing IGRP
Dynamic Routing IGRPDynamic Routing IGRP
Dynamic Routing IGRP
 
Asa pixfwsm multicast tips and common problems
Asa pixfwsm multicast tips and common problemsAsa pixfwsm multicast tips and common problems
Asa pixfwsm multicast tips and common problems
 
Cisco switch catalyst 2960 x datasheet
Cisco switch catalyst 2960 x datasheetCisco switch catalyst 2960 x datasheet
Cisco switch catalyst 2960 x datasheet
 
Dynamic routing EIGRP
Dynamic routing EIGRPDynamic routing EIGRP
Dynamic routing EIGRP
 
R1
R1R1
R1
 
Day 13.1..1 catalyst switch
Day 13.1..1 catalyst switchDay 13.1..1 catalyst switch
Day 13.1..1 catalyst switch
 
Eigrp on a cisco asa firewall configuration
Eigrp on a cisco asa firewall configurationEigrp on a cisco asa firewall configuration
Eigrp on a cisco asa firewall configuration
 
EDS-10/40G Ethernat Delay Simulator
EDS-10/40G Ethernat Delay SimulatorEDS-10/40G Ethernat Delay Simulator
EDS-10/40G Ethernat Delay Simulator
 
Ccna2 ass
Ccna2 assCcna2 ass
Ccna2 ass
 
1
11
1
 
Initial Configuration of Router
Initial Configuration of RouterInitial Configuration of Router
Initial Configuration of Router
 
Us4031328 conferencing arrangement for use in a pcm system
Us4031328 conferencing arrangement for use in a pcm systemUs4031328 conferencing arrangement for use in a pcm system
Us4031328 conferencing arrangement for use in a pcm system
 
Konfig routing eigrp
Konfig routing eigrpKonfig routing eigrp
Konfig routing eigrp
 

Destacado (10)

SATHYA RESUME 2
SATHYA RESUME 2SATHYA RESUME 2
SATHYA RESUME 2
 
Company Profile_Riscossa
Company Profile_RiscossaCompany Profile_Riscossa
Company Profile_Riscossa
 
Introducing David Usher
Introducing David UsherIntroducing David Usher
Introducing David Usher
 
козацька славадодаток л.
козацька славадодаток л.козацька славадодаток л.
козацька славадодаток л.
 
Website Design hyderabad
Website Design hyderabadWebsite Design hyderabad
Website Design hyderabad
 
презентация1
презентация1презентация1
презентация1
 
7 klas informatika_morze_2015
7 klas informatika_morze_20157 klas informatika_morze_2015
7 klas informatika_morze_2015
 
Sathyaraj. M. S. Resume
Sathyaraj. M. S.  ResumeSathyaraj. M. S.  Resume
Sathyaraj. M. S. Resume
 
мультимедійна презентація історія ств.книги.додаток щ
мультимедійна презентація історія ств.книги.додаток щмультимедійна презентація історія ств.книги.додаток щ
мультимедійна презентація історія ств.книги.додаток щ
 
інформатика підручник для 4 класу авт. ломаковська г. в. проценко г. о. рив...
інформатика   підручник для 4 класу авт. ломаковська г. в. проценко г. о. рив...інформатика   підручник для 4 класу авт. ломаковська г. в. проценко г. о. рив...
інформатика підручник для 4 класу авт. ломаковська г. в. проценко г. о. рив...
 

Similar a Unix 4 en

Network operating systems
Network operating systemsNetwork operating systems
Network operating systems
Ankit Kumar
 
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...
Anne Nicolas
 
Kernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPFKernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPF
Brendan Gregg
 
USENIX ATC 2017 Performance Superpowers with Enhanced BPF
USENIX ATC 2017 Performance Superpowers with Enhanced BPFUSENIX ATC 2017 Performance Superpowers with Enhanced BPF
USENIX ATC 2017 Performance Superpowers with Enhanced BPF
Brendan Gregg
 

Similar a Unix 4 en (20)

Linux networking
Linux networkingLinux networking
Linux networking
 
Handy Networking Tools and How to Use Them
Handy Networking Tools and How to Use ThemHandy Networking Tools and How to Use Them
Handy Networking Tools and How to Use Them
 
Quic illustrated
Quic illustratedQuic illustrated
Quic illustrated
 
Day2
Day2Day2
Day2
 
Ccna pres
Ccna presCcna pres
Ccna pres
 
Debugging linux issues with eBPF
Debugging linux issues with eBPFDebugging linux issues with eBPF
Debugging linux issues with eBPF
 
Network operating systems
Network operating systemsNetwork operating systems
Network operating systems
 
Network operating systems
Network operating systemsNetwork operating systems
Network operating systems
 
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...
Kernel Recipes 2017 - Performance analysis Superpowers with Linux BPF - Brend...
 
Kernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPFKernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPF
 
USENIX ATC 2017 Performance Superpowers with Enhanced BPF
USENIX ATC 2017 Performance Superpowers with Enhanced BPFUSENIX ATC 2017 Performance Superpowers with Enhanced BPF
USENIX ATC 2017 Performance Superpowers with Enhanced BPF
 
BGP zombie routes
BGP zombie routesBGP zombie routes
BGP zombie routes
 
C&C Botnet Factory
C&C Botnet FactoryC&C Botnet Factory
C&C Botnet Factory
 
Linux router
Linux routerLinux router
Linux router
 
Networking
NetworkingNetworking
Networking
 
Howto ethereal-wireshark-trace en
Howto ethereal-wireshark-trace enHowto ethereal-wireshark-trace en
Howto ethereal-wireshark-trace en
 
How to use mtr 2
How to use mtr 2How to use mtr 2
How to use mtr 2
 
Linux 系統管理與安全:進階系統管理系統防駭與資訊安全
Linux 系統管理與安全:進階系統管理系統防駭與資訊安全Linux 系統管理與安全:進階系統管理系統防駭與資訊安全
Linux 系統管理與安全:進階系統管理系統防駭與資訊安全
 
Lab telematicos
Lab telematicosLab telematicos
Lab telematicos
 
Lab telematicos
Lab telematicosLab telematicos
Lab telematicos
 

Unix 4 en

  • 1. UNIX OS Lecture IV Simonas Kareiva Vilnius University Faculty of Mathematics and Informatics Preparation of the material was supported by the project „Increasing Internationality in Study Programs of the Department of Computer Science II“, project number VP1–2.2–ŠMM-07-K- 02-070, funded by The European Social Fund Agency and the Government of Lithuania.
  • 2. Lecture #4 outline (part I) Introduction to TCP/IP and OSI. IP addressing IP and MAC address relation UNIX OS networking ping and traceroute arp, ifconfig and route 2
  • 3. TCP/IP Set of data transfer protocols (HTTP / FTP / DNS / …) Created 1973-1974, installed 1983 Abstraction levels (see further) Encapsulation OSI model 3
  • 4. 4
  • 5. 5
  • 7. Real life (simplified) Computer 2 Router Router Computer 1 Router Router Router 7
  • 8. How does communication work? Ethernet Satellite connecti on/ optics/ etc. WiFi Application Transport Network Connection Application Transport Network Connection Network Connection Network Connection 8
  • 9. IP address and mask 192.168.1.112/22 11000000.10101000.00000001.11100000 255.255.252.0 192.168.1.0 - ? 192.168.3.225 - ? 9
  • 10. Task IP address is 10.250.1.48/19 Questions:  What is the expression of this network mask in full format?  What is the maximum number of computers that can be connected to this network?  What’s the class of this IP address? 10
  • 11. Answer comes from ipcalc > ipcalc 10.250.1.48/19 addresss: 10.250.1.48 00001010.11111010.000 00001.00110000 Netmask: 255.255.224.0 = 19 11111111.11111111.111 00000.00000000 Wildcard: 0.0.31.255 00000000.00000000.000 11111.11111111 => Network: 10.250.0.0/19 00001010.11111010.000 00000.00000000 HostMin: 10.250.0.1 00001010.11111010.000 00000.00000001 HostMax: 10.250.31.254 00001010.11111010.000 11111.11111110 Broadcast: 10.250.31.255 00001010.11111010.000 11111.11111111 Hosts/Net: 8190 Class A, Private Internet 11
  • 12. Another IP writing method #!/bin/sh IPTONUM () { IP=$1; IPNUM=0 for (( i=0 ; i<4 ; ++i )); do ((IPNUM+=${IP%%.*}*$((256**$((3-${i})))))) IP=${IP#*.} done echo $IPNUM } NUMTOIP () { echo -n $(($(($(($((${1}/256))/256))/256))%256)). echo -n $(($(($((${1}/256))/256))%256)). echo -n $(($((${1}/256))%256)). echo $((${1}%256)) } 12
  • 13. IP classes (historical) Class First octet in binary system First octet from-to Network identifier Ammount of networks A 0XXXXXXX 0 - 127 a. 27 = 128 B 10XXXXXX 128 - 191 a.b. 214 = 16,384 C 110XXXXX 192 - 223 a.b.c. 221 = 2,097,152 13
  • 14. MAC address 08:00:20:d1:b0:0a  080020 – Sun Microsystems Inc.  d1b00a – unique product ID MAC / IP connection DHCP  static DHCP  dynamic DHCP 14
  • 15. Working in network with UNIX OS talk jonas@developers.firma.lt lynx www.delfi.lt echo pse call| mail –s important evelina@pardavimai ping 192.168.0.1 ifconfig 15
  • 16. ifconfig > ifconfig eth0 Link encap:Ethernet HWaddr 00:22:15:88:9c:93 inet addr:82.135.156.42 Bcast:82.135.156.255 Mask:255.255.255.0 inet6 addr: fe80::222:15ff:fe88:9c93/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2038944517 errors:0 dropped:0 overruns:0 frame:0 TX packets:2634746425 errors:0 dropped:0 overruns:0 carrier:1 collisions:0 txqueuelen:1000 RX bytes:592322463 (592.3 MB) TX bytes:3453432517 (3.4 GB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:5318385 errors:0 dropped:0 overruns:0 frame:0 TX packets:5318385 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2254159344 (2.2 GB) TX bytes:2254159344 (2.2 GB) 16
  • 17. ping > ping 24.93.4.206 PING 24.93.4.206 (24.93.4.206): 56 data bytes 64 bytes from 24.93.4.206: icmp_seq=0 ttl=240 time=157.010 ms 64 bytes from 24.93.4.206: icmp_seq=1 ttl=240 time=151.762 ms 64 bytes from 24.93.4.206: icmp_seq=2 ttl=240 time=314.532 ms ping: sendto: Network is down ping: sendto: Network is down ping: sendto: Network is down ^C --- 24.93.4.206 ping statistics --- 6 packets transmitted, 3 packets received, 50% packet loss round-trip min/avg/max/stddev = 151.762/207.768/314.532/75.524 ms 17
  • 18. traceroute > traceroute cisco.netacad.net traceroute to cisco.netacad.net (128.107.229.50), 30 hops max, 40 byte packets 1 gw.ep.lt (82.135.156.254) 0.966 ms 0.940 ms 0.926 ms 2 212-59-21-193.static.telecom.lt (212.59.21.193) 2.727 ms 2.716 ms 2.703 ms 3 213-190-60-93.telecom.lt (213.190.60.93) 2.892 ms 2.880 ms 2.868 ms 4 war-b3-link.telia.net (213.248.85.89) 11.790 ms 11.779 ms 11.766 ms 5 hbg-bb2-link.telia.net (80.91.251.217) 37.136 ms 37.124 ms 37.112 ms 6 ldn-bb2-link.telia.net (80.91.249.14) 41.709 ms ldn-bb2-link.telia.net (80.91.250.151) 41.859 ms ldn-bb2-link.telia.net (80.91.254.7) 41.842 ms 7 ash-bb1-link.telia.net (80.91.251.209) 123.663 ms 123.964 ms ash-bb1-link.telia.net (213.248.65.210) 125.426 ms 8 192.205.34.209 (192.205.34.209) 122.910 ms 123.278 ms * 9 cr1.wswdc.ip.att.net (12.122.135.14) 196.349 ms 195.994 ms 195.979 ms 10 cr2.phlpa.ip.att.net (12.122.4.53) 197.221 ms 199.154 ms 199.135 ms 11 cr2.cl2oh.ip.att.net (12.122.2.209) 215.193 ms 213.361 ms 213.550 ms 12 cr1.cl2oh.ip.att.net (12.122.2.125) 213.099 ms 221.672 ms 221.645 ms 13 cr1.cgcil.ip.att.net (12.122.2.205) 222.744 ms 222.733 ms 222.720 ms 14 cr1.sffca.ip.att.net (12.122.4.121) 221.392 ms 221.377 ms 221.366 ms 15 gar1.sj2ca.ip.att.net (12.123.15.1) 205.537 ms 203.746 ms 203.730 ms 16 12.118.124.10 (12.118.124.10) 228.697 ms 228.684 ms 228.673 ms 17 sjck-dmzbb-gw1.cisco.com (128.107.239.9) 190.264 ms 190.251 ms 190.652 ms 18 sjc12-dmzbb-gw1-g1-37.cisco.com (128.107.224.165) 302.883 ms 302.868 ms 302.650 ms 19 sjc12-dmzdc-gw1-gig5-2.cisco.com (128.107.224.22) 303.049 ms 303.037 ms 303.025 ms 20 * * * 21 * * * 22 * * * 18
  • 19. arp > arp -an ? (82.135.156.222) at 00:c0:02:2a:4e:6d [ether] on eth0 ? (82.135.156.16) at 00:15:60:57:06:cd [ether] on eth0 ? (82.135.156.83) at 00:0e:0c:4e:62:f8 [ether] on eth0 ? (82.135.156.84) at 00:06:29:39:63:c3 [ether] on eth0 ? (82.135.156.6) at 00:80:a3:8c:0d:72 [ether] on eth0 ? (82.135.156.88) at 00:11:d8:94:a9:4a [ether] on eth0 ? (82.135.156.21) at 00:18:f3:87:31:17 [ether] on eth0 ? (82.135.156.15) at 00:0e:a6:34:37:a1 [ether] on eth0 ? (82.135.156.23) at 00:0c:f1:ed:c8:56 [ether] on eth0 ? (82.135.156.55) at 00:10:5a:5a:06:f1 [ether] on eth0 ? (82.135.156.254) at 00:30:48:88:d9:1e [ether] on eth0 ? (82.135.156.201) at 00:08:02:ef:fa:a4 [ether] on eth0 19
  • 20. route > route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 193.219.94.168 82.135.156.254 255.255.255.255 UGH 0 0 0 eth0 193.219.94.141 82.135.156.254 255.255.255.255 UGH 0 0 0 eth0 82.135.156.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 82.135.156.254 0.0.0.0 UG 100 0 0 eth0 20
  • 21. Routing Computer 2 172.16.0.2/28 Router 3 Router 1 Computer 1 192.168.1.1/24 Router 2 Computer 3 192.168.3.1/24 internet 21
  • 22. 22
  • 23. 23
  • 24. 24
  • 25. Lecture #4 outline (part II) Overview of UNIX command line tools:  cut  diff  awk  sed  expand  grep  strings  tr  uniq  zcat 25
  • 26. cut > echo aa:bb cc dd:ee | cut -d : -f 2 bb cc dd > echo aa:bb cc dd:ee | cut -d " " -f 2 cc > echo aa:bb cc dd:ee | cut -d " " -f 1,2 aa:bb cc > echo aa:bb cc dd:ee | cut -d " " -f 1,2,3 aa:bb cc dd:ee > cut -d : -f 1,5 /etc/passwd | tail -3 _installer:Installer _atsserver:ATS Server _unknown:Unknown User 26
  • 27. diff > echo "Firstnsecond" > 1.txt > echo "Firstnthird" > 2.txt > diff 1.txt 2.txt 2c2 < second --- > third > diff 1.txt 2.txt > diff.txt > patch -p0 1.txt < diff.txt patching file 1.txt > cat 1.txt First third 27
  • 28. expand > printf "atbn" a b > printf "atbn" | hexdump 0000000 0961 0a62 0000004 > printf "atbn" | expand | hexdump 0000000 2061 2020 2020 2020 0a62 000000a 28
  • 29. grep > grep ^a /etc/passwd alias:*:81:81:User &:/var/qmail/alias:/nonexistent > grep ^c /etc/passwd cyrus:*:60:60:the cyrus mail server:/nonexistent:/sbin/nologin courier:*:465:465:Courier Mail System:/var/spool/courier:/sbin/nologin > grep -c nologin$ /etc/passwd 29 > tail -f httpd-error.log | grep denied [Sun Oct 4 19:18:12 2012] [error] [client 78.60.155.45] (13)Permission denied: cannot read directory for multi: /users/eduardas/www/ > grep -E '(error|failure)' /var/log/console | grep -vc connect_to 1945 29
  • 30. strings > strings /var/log/wtmp | grep -A4 simonask simonask 88.223.26.58 Jttypa Jttypc Jttypa > strings /bin/sync | grep error $FreeBSD: src/lib/libc/i386/sys/cerror.S,v 1.10 1999/08/27 23:59:38 peter Exp $ error: Authentication error Exec format error Input/output error Undefined error: 0 30
  • 31. tr > cat bug.lt | tr e 3 W3 ar3 us3r group of BSD syst3ms. Th3 group was 3stablish3d in th3 summ3r of 2002. It happ3n3d in small city of North Lithuania. > cat bug.lt | tr '[a-z]' '[A-Z]' WE ARE USER GROUP OF BSD SYSTEMS. THE GROUP WAS ESTABLISHED IN THE SUMMER OF 2002. IT HAPPENED IN SMALL CITY OF NORTH LITHUANIA. 31
  • 32. uniq > grep DNS ppp.log | awk '{ print $10 }' | sort | uniq 194.176.32.142 194.176.32.163 > grep Illegal cache.log | tail -1 2009/10/04 19:37:34| urlParse: Illegal character in hostname 'www,youtube.lt’ > grep Illegal cache.log | cut -d " " -f 8 | sort | uniq -c | sort -rn | head 760 '[2a01:138:a001:201:' 57 '2a01%3a138%3aa001%3a201%3a%3a24' 57 '2a01%3a138%3aa001%3a201%3a%3a23' 57 '2a01%3a138%3aa001%3a201%3a%3a22' 57 '2a01%3a138%3aa001%3a201%3a%3a21' 12 '%20ssl.google-analytics.com' 7 'www,youtube,com' 4 'evi ka-pc'� 3 'www,youtube.lt' 3 'vista.%20liedm.lt’ 32
  • 33. zcat > cat > test2.sh #!/bin/sh echo date exit 0; > gzip test2.sh > cat test2.sh.Z ;??Jtest2.shSV?O???/??JM??WHI,I?J??,Q0???d?I> > zcat test2.sh.Z #!/bin/sh echo date exit 0; 33
  • 34. sed > echo day | sed s/day/night/ night > echo "123 abc" | sed 's/[0-9]*/& &/' 123 123 abc > echo left right | sed 's/([a-z]*) ([a-z]*)/2 1/' right left > sed '/start/,/stop/ s/#.*//' ? 34
  • 35. sed Compare:  sed 's/([a-zA-Z]*) ([a-zA-Z]*) /1 /'  sed 's/[a-zA-Z]* //2'  sed 's/./&:/20'  sed 's/^..................../&:/'  sed -n 's/jonas/&/p' <file  grep jonas file  sed 'y/abcdef/ABCDEF/’  tr abcdef ABCDEF 35
  • 36. Exercise (sed) #!/bin/sh sed -n ' /begin/,/end/ { s/#.*// s/[ ^I]*$// /^$/ d p } ’ 36
  • 37. sed #!/bin/sh # A way to clear the lines that start with # # (comments) between words ‘begin’ and ‘end’ sed -n ' /begin/,/end/ { s/#.*// s/[ ^I]*$// /^$/ d p } ' 37
  • 38. sed (advanced) > cat cat.txt This is my cat my cat's name is betty This is my dog my dog's name is frank > sed 'N;s/n / /;P;D;' cat.txt This is my cat my cat's name is betty This is my dog my dog's name is frank N – adds a second line to the buffer s – substitution command /n / - equivalence of a new line and space / / - substitution to one space P – prints first line of buffer D - deletes the buffer and continues to the next line 38
  • 39. awk > ls -l -rwxrwxrwx@ 1 simonask staff 7497216 Rgs 14 15:59 UNIX_1.pps > ls -l | awk ' BEGIN { print ”BylattSavininkas" } { print $9, "tt", $3} END { print " - DONE -" } ' file Owner UNIX_1.pps simonask - DONE - > date Sunday, 2012 m. spalio 4 d. 20:21:58 EEST > date | awk '{print $1}' Sunday, > date | awk '{print $2}' 2012 39
  • 40. awk BEGIN { print ”enter number"; } { print ”Number’ ", $1, ” square is ", $1*$1; print ”enter one more number"; } END { print ”Bye" } 40
  • 41. awk awk '{print $2, $1}' read.txt awk '{print NR "t" $0}’ read.txt awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"sn",$0}' Compare this:  head -10  awk 'NR < 11’  awk '!/search/' read.txt  grep –v search read.txt 41
  • 42. Excercises ls -d *.sh | sed 's/(.*).sh$/cp "&" 1/' | sh ____________________________________________________________ STR="`sed <<<"$STR" "s/(.)/1('s* +s*')?/g;s/('s* +s*')?$//"`" ____________________________________________________________ find ${1-.} -type d -print | env LC_ALL='C' sort -if | sed -e "s,^${1-.},," -e "/^$/d" -e "s,[^/]*/([^/]*)$,`-----1," -e "s,[^/]*/,| ,g" 42
  • 43. #!/usr/bin/perl -w # camel code use strict; $_='ev al("seek040D ATA,0, 0;");foreach(1..3) {<DATA>;}my @camel1hump;my$camel; my$Camel ;while( <DATA>){$_=sprintf("%-6 9s",$_);my@dromedary 1=split(//);if(defined($ _=<DATA>)){@camel1hum p=split(//);}while(@dromeda ry1){my$camel1hump=0 ;my$CAMEL=3;if(defined($_=shif t(@dromedary1 ))&&/S/){$camel1hump+=1<<$CAMEL;} $CAMEL--;if(d efined($_=shift(@dromedary1))&&/S/){ $camel1hump+=1 <<$CAMEL;}$CAMEL--;if(defined($_=shift( @camel1hump))&&/S/){$camel1hump+=1<<$CAMEL;}$CAMEL--;if( defined($_=shift(@camel1hump))&&/S/){$camel1hump+=1<<$CAME L;;}$camel.=(split(//,"040..m`{/J047134}L^7FX"))[$camel1h ump];}$camel.="n";}@camel1hump=split(/n/,$camel);foreach(@ camel1hump){chomp;$Camel=$_;y/LJF7173175`047/061062063 064065066067070/;y/12345678/JL7F175173047`/;$_=reverse; print"$_040$Cameln";}foreach(@camel1hump){chomp;$Camel=$_;y /LJF7173175`047/12345678/;y/12345678/JL7F1751730 47`/; $_=reverse;print"040$_$Cameln";}';;s/s*//g;;eval; eval ("seek040DATA,0,0;");undef$/;$_=<DATA>;s/s*//g;( );;s ;^.*_;;;map{eval"print"$_"";}/.{4}/g; __DATA__ 124 1 501450401651631450401571 460401 410 40143141 1551451 540401 51155 141 1471450 40151156 040141 16316 3 157143 15114116 41511 57156 040167 1511641 50040 1201 45162 15404015 1163 04014 10401 641621 41144 145 15514 1162 15304 0157 146 04011 7047 1221 4515 11541 54171 040 046 01210116 316 315 714315 114 116 4145163 054 040 11115614 3056 040 12516314514 4040 1671 511641 500 40160 145162 155151 163163 1511 57156056 43