net prog1-net-8

17

Upload: maria-sawaby-nazehat

Post on 22-Jan-2018

185 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Net prog1-net-8

Technical Foundation of Computer Science 5Network Programming I

Maria Sawaby

Department of Communication and Operating System

June 10, 2015

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 1 / 17

Page 2: Net prog1-net-8

Contents

1 Basic networking primertracerouteping and fping

2 DNS lookup with fping

3 SFTP (secure ftp)

4 scp (secure copy)

5 Remote login with ssh

6 Password-less Auto login with SSH

7 Summary

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 2 / 17

Page 3: Net prog1-net-8

traceroute

traceroute displays the address of all intermediate gateways throughwhich the packet travelled to reach the destination

traceroute information helps us to understand how many hops eachpacket should take in order reach the destination

$traceroute google.com

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 3 / 17

Page 4: Net prog1-net-8

ping and fping

The most basic network command is ping. The ping command sendsspecial network ICMP ECHO REQUEST packets to a speci�ed host.

$ping -c 2 google.com

there is also fping which checks the availability of host and sendparallel requests to speci�ed hosts

maria@cs:~\$ fping -a 192.168.1.0/24 -g 2>/dev/null

192.168.1.1

192.168.1.103

192.168.1.110

192.168.1.102

2>/dev/null is used to dump error messages printed due tounreachable host to a null device

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 4 / 17

Page 5: Net prog1-net-8

ping and fping

you can also use:

fping -a 192.168.1.0/24 -g

OR:

fping -a 192.168.1.10 192.168.1.20 -g

the -a option will list or print all system alive's IP addresses

The -g option speci�es to generate a range of IP addresses fromslash-subnet mask notation speci�ed as IP/mask or start and end IPaddresses as in the example above

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 5 / 17

Page 6: Net prog1-net-8

DNS lookup with fping

fping has an option -d that returns host names by using DNS lookupfor each echo replyIt will print out host names rather than IP addresses on ping replies

maria@cs:~$ nano ip.list

maria@cs:~$ fping -a < ip.list

74.125.136.139

98.139.183.24

maria@cs:~$ fping -a -d 2>/dev/null <ip.list

ea-in-f139.1e100.net

ir2.fp.vip.bf1.yahoo.com

OR:

maria@cs:~$ fping -a -d <ip.list

192.168.1.103

ea-in-f139.1e100.net

ir2.fp.vip.bf1.yahoo.com

mrs04s10-in-f14.1e100.net

maria@cs:~$ cat ip.list

74.125.136.139

98.139.183.24

192.168.1.103

216.58.210.238

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 6 / 17

Page 7: Net prog1-net-8

Secure FTP

sftp is a �le transfer system which runs on top of ssh connection

It does not require an ftp server to be installed on the remote end toperform �le transfer but requires openssh server to be installed andrunning

maria@cs:~$ sftp maria@cs

maria@cs's password:

Connected to cs.

sftp> ls

...

you can use the following commands to work on remote host

cd, help, put, get, pwd ....

pressing help will show you all available commands

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 7 / 17

Page 8: Net prog1-net-8

scp (secure copy)

scp is a �le copy technique, which is a secure way to copy �lesfrom/to remote host

maria@cs:~$ scp /home/maria/test/A.txt maria@cs:/home/maria/Desktop

maria@cs's password:

A.txt 100% 36 0.0KB/s 00:00

maria@cs:~$

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 8 / 17

Page 9: Net prog1-net-8

scp

the format of the scp command is:

scp SOURCE DESTINATION

maria@cs:~$ scp maria@cs:/home/maria/test/B.txt Desktop

maria@cs's password:

B.txt 100% 38 0.0KB/s 00:00

maria@cs:~$ ls Desktop/

A.txt B.txt

maria@cs:~$

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 9 / 17

Page 10: Net prog1-net-8

Recursive copying with scp

by using scp we can recursively copy directories between two machineson a network with -r parameter

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 10 / 17

Page 11: Net prog1-net-8

remote login with ssh (secure shell)

ssh is an interesting system administration tool that enables to controlremote hosts by login with a shellyou may have to install openssh-server and openssh-client

to connect to a remote host using ssh:maria@cs:~$ ssh [email protected]

[email protected]'s password:

Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-24-generic x86_64)

* Documentation: https://help.ubuntu.com/

Last login: Mon Jun 1 22:52:39 2015 from localhost

maria@cs:~$ cd test

maria@cs:~/test$ exit

logout

Connection to 192.168.1.103 closed.

maria@cs:~$

don't be confused as both system (local and remote) have the samespeci�cations in the above example

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 11 / 17

Page 12: Net prog1-net-8

ssh

To run a command on the remote host and display its output on thelocalhost shell, use the following syntax:

maria@cs:~$ ssh [email protected] 'whoami'

[email protected]'s password:

test

maria@cs:~$

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 12 / 17

Page 13: Net prog1-net-8

Password-less Auto login with SSH

The SSH uses public key-based and private key-based encryptiontechniques for automatic authentication

authentication key is created using the ssh-keygen command

There are two steps towards the setup of automatic authenticationwith SSH

1 Creating the SSH key from the machine, which requires a login to aremote machine.

2 Transferring the public key generated to the remote host andappending it to ∼/.ssh/authorized_keys �le.

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 13 / 17

Page 14: Net prog1-net-8

Password-less Auto login with SSH

In order to create an SSH key, enter the ssh-keygen command:

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 14 / 17

Page 15: Net prog1-net-8

Password-less Auto login with SSH

Now ∼/.ssh/id_rsa.pub and ∼/.ssh/id_rsa has been generated

id_rsa.pub is the public key which should be appended to∼/.ssh/authorized_keys �le on remote server

id_rsa is the private key which is located on the local machine

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 15 / 17

Page 16: Net prog1-net-8

Summary

traceroute is used to display information about hops or intermidiategateways the packets are traveling to

ping and fping are used to check the availability of speci�ed hosts

sftp is a �le transfer system

scp is a secure way to copy �les to/from remote machines

ssh enables you to control remote hosts by login with a shell

ssh-keygen is used to create a public and private key pair to be usedto automatically login to a remote machine without begin promptedfor a password

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 16 / 17

Page 17: Net prog1-net-8

Lecture-8 (Network-Department) Net-Prog I June 10, 2015 17 / 17