Previous Up Next

9  The Net and Unix

Unix is classically associated with networks, and has flourished as a networked operating system for decades (yes decades, stick that in your Microsoft pipe(tm) and smoke it). This document will teach you a few useful things to know about networked Unix systems, and a few useful programs for your use.

Another more in-depth introduction is available at:
http://en.tldp.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO/

9.1  Browsing the web

It’s possible to browse the web from a text only terminal. The reasons for this are many, but essentially this is helpful if there is a technical reason why the web-browser on the lab machine you’re logged into won’t work, and also if you just want to browse quickly, as text-only browsers don’t have to download pictures or flash-animations or anything like that. To use the web browser installed simply use the command:

% lynx www.google.com

Where “www.google.com” can be any URL you want, lynx will then load, and render the page. The options at the bottom of the screen will as usual tell you what keys do what, ‘h’ will give you more help, ‘q’ will quit, ‘g’ will allow you to enter a new URL, ‘G’ will allow you to enter a new URL but will leave the current one in the buffer (useful if you just want to put another page name on the end of the current domain for example).

Movement is by cursor keys if they’re working, the space bar will scroll down, ‘b’ will go back up, use the enter key to follow a link.

9.2  Downloading files

While lynx will allow you to download a file sometimes you already know the location of one, and perhaps you want to download one in the background while keeping lynx in the foreground. Or maybe you want to download a whole website, following links and downloading from them too. For all these purposes there is wget.

In the examples below http://www.somedomain.net/location-of-file is used, but wget supports http:// links and ftp:// links, as well as several other types. Also the examples below deal with one option flag at a time, these can be combined.

Full documentation on wget is available at:
http://www.gnu.org/software/wget/wget.html

% wget http://www.somedomain.net/location-of-file

This sort of command (replacing the “http://...” line with the location of something you want to download) will cause wget to download the file, however there is much more wget can do.

% wget -c http://www.somedomain.net/location-of-file

The ‘-c’ flag is the “continue” flag. If there is already a file called “location-of-file” in the current directory wget will assume you’re trying to continue its download and start the download from the network having jumped forwards the size of the file on disk (and will then append what it downloads to the end of the file). This is helpful if a download stops halfway through.

% wget --limit-rate=20k http://www.somedomain.net/location-of-file 

--limit-rate” does exactly what it says, it limits the rate at which wget will attempt to download a file to the amount listed after it. This is normally listed in ‘k’ (for kilobytes per second) or ‘m’ (for megabytes per second) and is designed so that if you are on a large connection (like the University’s) you don’t thrash smaller sites, or if you are on a smaller connection you don’t hog all the bandwidth.

% wget -b http://www.somedomain.net/location-of-file 

The ‘-b’ option will cause wget to automatically drop into the background, and save the file into its current directory, which can be handy for downloading multiple files.

% wget -i urlfile 

The ‘-i’ or “input file” option, will cause wget to read the file called “urlfile” (which should just be a series of URLs, one on each line) and download each file listed.

% wget -O filename http://www.somedomain.net/location-of-file

This will cause the file to be saved as the filename given just after the ‘-O’ option (the Output filename). If this name is ‘-’ (dash) then the file will be piped to standard output (see section 10.1).

9.3  Querying DNS (Domain Name System)

DNS deals with mapping domain names (for example “www.lancs.ac.uk”) to IP addresses (such as 148.88.8.1) so that the packets sent to either one get correctly routed to the right machine. The easiest tool available to users is “nslookup”. This is however in “/usr/sbin” on the central Unix server and so you will either need to add /usr/sbin to your path or use the command:

% /usr/bin/nslookup www.lancs.ac.uk 

It’s use can be fairly simple, and giving “nslookup” an IP address will cause it to try and look up the domain associated, giving it a domain will cause it to return the IP address(es) associated with that domain.

Full documentation is, as ever, in “man nslookup”.

9.4  Seeing network activity on the host

The following section is useful for anyone who wants to know details of current network connections to and from the machine they are logged into, however this is not required knowledge, and not all of the concepts will be explained, its just being documented so interested parties know the functionality is there.

At any time you can see what connections are being made to and from the Unix machine you are logged into by use of the following command:

% netstat -f inet 

netstat on its own will simply list all connections on all networks, this will list a lot of traffic on Unix sockets and loopback that aren’t really that interesting to anyone not maintaining the machine. The ‘-f’ option restricts netstat to looking at a family of traffic, and the “inet” family is all “Internet” traffic i.e. TCP and UDP traffic. However this will probably produce a prodigious amount of output and so the following is recommended to view it in less (as normal see section 10.1 for the reasons why):

% netstat -f inet | less 

And as usually scroll down with the space bar, up with ‘b’ and quit with ‘q’.

9.5  Seeing if another machine is running

The canonical way of seeing if another machine is running is to “ping” it. The ping command sends a few packets across the network to another machine, which is deemed “alive” if it responds. An example of using ping is seen below:

% /usr/sbin/ping www.google.com 

If the machine you give it the address of (in this example “www.google.com” but any machine can be used, even “unix.lancs.ac.uk” which you are logged into) is working and responding to pings (they can be switched off) the command will tell you it “is alive”. If it cannot reach the machine (usually because the Internet is broken between unix.lancs and the host, or the host is down) it will print “no answer from www.google.com” (or whatever machine you pinged).

It is worth noting that some systems are configured by their administrators to not respond to ping requests these days. This will either be because the administrators are trying to “stealth” the machine and hide it from viruses and port-scanners (Nb: This is not a totally effective method) or because they think it will increase the security of their machines. Either way it breaks RFC 1122 (http://www.faqs.org/rfcs/rfc1122.html) and should not be done.

Often a better method of doing this is the traceroute command. This will try to get to a host and print out a list of every network device it passes through along the way (so you can trace the route your packets will take). Its use is as follows:

% /usr/sbin/traceroute www.google.com 

9.6  Logging into remote machines

Assuming that you have accounts on other Unix machines you’ll probably want to know the best way to log into those machines from cent1. This is best accomplished with the “ssh” command (Secure SHell), the example below illustrates this:

% ssh frank@melody.lancs.ac.uk 

This returns to the earlier example (see section 8) of the Unix machine melody.lancs.ac.uk and its user account “frank”. The use of this command will log you into the machine just as if you were sat in front of it, and anything you could do there you can do via this remote login.

While the telnet command may also be used to log into machines running a telnet server its use is discouraged as it doesn’t encrypt your traffic (like ssh does) and thus your password may be sniffed off the network.

9.7  Copying files from remote machines

The best way these days to copy files between Unix machines is to use ssh, or at least a program that runs over it, called “scp” (literally SSH CoPy). This works just like the normal copy program but requires a slightly different syntax (see section 4.2.4), simply use:

% scp frank@melody.lancs.ac.uk:~/foo ./ 

This will copy the file called “foo” from the home directory of the account “frank” on the machine “melody.lancs.ac.uk” to the current directory (known as ‘./’). Of course to copy a file back the other way you’d use:

% scp bar frank@melody.lancs.ac.uk:~/ 

This will copy the file called “bar” from your current directory to frank’s home directory on melody.lancs.ac.uk.

scp can also be used to copy whole directories, which is fairly simple, for example:

% scp -r stuff frank@melody.lancs.ac.uk:~/ 

Use of the ‘-r’ (recursive) flag will copy the whole directory called “stuff” including all its contents to the home directory of frank on melody.

scp can do far more than this, and even do automated copies without passwords if you have the correct keys installed (see “man scp” as ever).


Previous Up Next