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
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
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
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
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
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
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
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