You are on page 1of 4

Linux Networking Basics http://doc.vic.computerbank.org.au/tutorials/Tutorial3/print.

html

Home / Tutorials / Linux Networking Basics

Linux Networking Basics

Learning to use the command-line interface - Session 3: Accessing other


computers and getting network information
Kylie Davies
<kylied@projectx.com.au>
Andrew Stone
Revision History
Revision 1.0
9 October 2002
Abstract
In this session we will take a look at networking commands you can use to get network information and those that
will enable access to other computers.
Table of Contents
What is Networking?
What is a network of computers?
Network settings and getting network information
Configuration
Information
Using the ping command
Accessing other computers
ssh - secure shell
Copying files with scp - secure copy
What is Networking?
Networking is where one computer or device can communicate with other (or many other) computers via a network
protocol such as TCP/IP.
What is a network of computers?
A network of computers occurs where two or more computers are connected by some means. Computers can be
connected by network cable, both coaxial and cat 5. For this to happen both computers need a network card.
Computers can also connect via a serial cable connection. For this to happen both computers need a spare serial
port. Computers can now use wireless network technology.
Computers also connect via other devices such as a cable modem, serial modem, internal modem, ADSL modem
and others.
Network settings and getting network information
Within Unix/Linux there are many tools and commands that will allow you to access network information and
configuration (settings).
Configuration
The most basic configuration files are hostname and hosts located in /etc . The hostname of the computer is where
you can specify a name for the computer. The /etc/hosts file is where the hostname is cross-referenced with an IP
address for the network interface.
The interfaces file, in /etc/network/ is used to configure the network interfaces on your machine. It is also used to
specify network (IP) addresses for identification on a network.
Information
To find out how your network interfaces are configured you can use the ifconfig command. This command needs to
be run as root.
kylie@thinking:~# ifconfig
This the output of the ifconfig command:
eth0 Link encap:Ethernet HWaddr 00:60:97:91:99:A6
inet addr:211.28.121.178 Bcast:211.28.121.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:25520 errors:6 dropped:0 overruns:6 frame:6
TX packets:8550 errors:0 dropped:0 overruns:0 carrier:1
collisions:217 txqueuelen:100
RX bytes:8158632 (7.7 MiB) TX bytes:961071 (938.5 KiB)
Interrupt:3 Base address:0x300

1 of 4 12/18/2008 12:43 PM
Linux Networking Basics http://doc.vic.computerbank.org.au/tutorials/Tutorial3/print.html

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:148 errors:0 dropped:0 overruns:0 frame:0
TX packets:148 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8068 (7.8 KiB) TX bytes:8068 (7.8 KiB)

Where eth0 refers to the cable connection. The inet addr is my IP address.
The lo refers to the local loopback interface, the ability of the computer to communicate with itself.
Using the ping command
The ping command sends a packet across the network to the remote computer you specify. When ping responds, it
confirms that the remote machine is responding to requests and there is a valid, functional route to the remote
computer. If ping does not respond, it may be because your machine has no network connectivity, the Internet
connection is down, or the web site on the Internet is down.
Pinging a machine on the internal network at Computerbank
In the following example, the ping command is used to see whether the 'toast' machine on the Computerbank is
accepting ping requests. Press the Ctrl-C keys to terminate ping requests.
kylie@prometheus:~$ ping toast
The above command produces the following output:
PING toast.cbv.prv (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: icmp_seq=0 ttl=244 time=0.6 ms
64 bytes from 192.168.1.1: icmp_seq=1 ttl=244 time=0.6 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=244 time=0.6 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=244 time=0.6 ms
--- toast.cbv.prv ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.6/0.6/0.6 ms
This output tells us that our machine has network connectivity and the 'toast' machine is accepting ping requests.
Pinging a machine on the Internet
The following example is a ping request to www.yahoo.com.au . Press the Ctrl-C keys to terminate ping requests.
kylie@prometheus:~$ ping www.yahoo.com.au
The following output is produced:
PING au.rc.yahoo.com (202.3.14.151): 56 data bytes
64 bytes from 202.3.14.152: icmp_seq=0 ttl=244 time=1754.4 ms
64 bytes from 202.3.14.152: icmp_seq=1 ttl=244 time=1496.0 ms
64 bytes from 202.3.14.152: icmp_seq=2 ttl=244 time=1586.1 ms
64 bytes from 202.3.14.152: icmp_seq=3 ttl=244 time=1645.8 ms
--- au.rc.yahoo.com ping statistics ---
5 packets transmitted, 4 packets received, 20% packet loss
round-trip min/avg/max = 1496.0/1620.5/1754.4 ms
The above example tells us that the Internet connection at Computerbank is up and the www.yahoo.com.au web
site is accepting requests.
Accessing other computers
ssh - secure shell
Secure shell provides a method to securely access another computer. ssh is secure in that the connection between
the two computers is encrypted. The first time you ssh to a computer a key will be set up.
You can use ssh to access another computer using two different methods:
* IP number
* Hostname
Generally if you want to access your home computer (one that is connected by cable modem or serial modem) you
will need to supply an IP number. If you want to ssh to a computer on a network such as the one at Computerbank
- a hostname is fine. If all else fails use the IP number method. If the ssh program is not installed it won't work.
To ssh you need to specify a username@hostname (or IP address: 234.45.123.14)
Example first time use of ssh to access another computer on the Internet
kylie@thinking:~$ ssh computerbank@digital.linux.org.au
The authenticity of host 'digital.linux.org.au (202.0.185.5)' can't be established.
RSA key fingerprint is b6:0a:98:bc:ab:1f:74:cd:d4:bc:5c:c1:e3:1a:de:18.
Are you sure you want to continue connecting (yes/no)?

2 of 4 12/18/2008 12:43 PM
Linux Networking Basics http://doc.vic.computerbank.org.au/tutorials/Tutorial3/print.html

Type the word 'yes' at the prompt.


The following message is displayed:
Warning: Permanently added 'digital.linux.org.au,202.0.185.5' (RSA) to the list of known hosts.
computerbank@digital.linux.org.au's password:
Enter the password for the computerbank user account on the digital.linux.org.au machine.
The following prompt is displayed providing you entered the correct password.
computerbank@digital:~$
Example of use to access another computer at Computerbank
kylie@prometheus:~$ ssh omnix
OR
kylie@prometheus:~$ ssh kylie@omnix
OR
kylie@prometheus:~$ ssh kylie@'omnix's IP address'
all work fine.
Enter Kylie's password at the prompt:
kylie@omnix's password:
This produces the following prompt:
kylie@omnix:~$
When you access computers within the Computerbank network your files go with you. This is because we run a
network file system that supports logins from any computer on the Computerbank internal network.
If you access another computer from a console you will be able to run text-based programs such as lynx.
Exporting the GUI (graphical user interface) of another computer using ssh
In order to run another computer's graphical applications both computers need to be configured correctly. If the
computer you are trying to run programs from is not set up to do this it will not work and you will get an error
message. The ssh command also needs a special argument: -X
To run StarOffice at Computerbank you must access omnix. omnix is the Computerbank StarOffice application
server. It has been specifically set up (with lots of RAM) to do this.
kylie@prometheus:~$ ssh -X omnix
Kylie must enter her password at the prompt:
kylie@omnix's password:
Once logged in to omnix machine, the following command executes StarOffice:
kylie@omnix:~$ Office51/bin/soffice &
PID {3567}
kylie@omnix:~$
Providing StarOffice has been correctly set up for your user account it will display on your screen while running on
the other computer.
Copying files with scp - secure copy
With scp you can copy files across a network. In a similar way to ssh, scp provides an encrypted way to copy files
to hosts both remotely and locally on a network.
You can copy files into your own or into another user's directory. Files can be copied anywhere on the internal
network or the Internet providing you know the IP address of the destination machine. If you are copying files into
another user's directory be sure to have them present as they will be required to enter their password.
When copying files to another user using scp, the file permissions change.
Example of copying files over the Internet
Let's say I am at Computerbank and I want to copy files to digital.linux.org.au as the user 'computerbank'. The file
is /var/www/cbankwebsite/index.html
kylie@prometheus:~$ scp /var/www/cbankwebsite/index.htmlcomputerbank@digital.linux.org.au:~
/computerbank/
Enter the computerbank user account password for the remote machine:
computerbank@digital.linux.org.au's password:
You should see the following output if all went well:
index.html 100% |*| 16180 00:00
Example of copying a file on the Computerbank network to another user
kylie@omnix:~$ scp foobar.txt foo@omnix:
foo@omnix's password:
Foobar.txt 100% |*| 6180 00:00
By default a file is copied into the home directory if no file path is given.
The colon absolutely has to be there for scp to work.

3 of 4 12/18/2008 12:43 PM
Linux Networking Basics http://doc.vic.computerbank.org.au/tutorials/Tutorial3/print.html

©GNU Free Documentation License - Copying and distribution of these web pages is permitted in any
medium, provided this notice is preserved.
Computerbank Victoria Inc., 483 Victoria St, West Melbourne, Victoria, Australia. 3003 ARBN 096 258 543

4 of 4 12/18/2008 12:43 PM

You might also like