Basic Network – Part IV

·  Sometimes DNS is overkill!!!

·  You might just need to resolve a handful of hostnames because you’re configuring a small private network that’s not connected to the Internet at large or because you want to set up a few names for local(or even remote) computers that aren’t in the global DNS database

·  For such situations, “/etc/hosts” may be just what you need

o  This file holds mappings of IP addresses to hostnames, on a one-line-per-mapping basis

o  Each mapping includes at least one name and sometimes more

o  See Example below:

·  In the example above:

o  Localhost is associated with the 127.0.0.1 address

o  Apollo.luna.edu and Apollo are tied to 192.168.7.23

o  The first of these linkages is standard; it should exists in any “/etc/hosts” file

o  The second linkage is an example that you can modify as you see fit

§  The first name is a full hostname, including the domain portion; subsequent names on the line are aliases, typically the hostname without its full domain specification

·  Once you’ve set up an “/etc/hosts” file, you can refer to computers listed in the file by name, whether or not those names are recognized by the DNS servers the computers uses

·  One major drawback to “/etc/hosts/” file is that it’s a purely local file; setting a mapping in one computer’s “/etc/hosts” file affects name lookups performed by that computer alone

o  Thus, to do good on an entire network, you must modify the “/etc/hosts” files on all of the computers on the network

·  Linux normally performs lookups in “etc/hosts” before it uses DNS

o  You can modify this behavior by editing the “/etc/nsswitch.conf” file, which configures the Name Service Switch(NSS) service

o  More specifically, you must adjust the “hosts” line . . . this line lists the order of the files and dns options

o  As Example: Review the “etc/nsswitch.conf” file using “cat”

·  In addition to “ /etc/hosts “, Linux supports a file called “/etc/networks”

o  “/etc/networks” works much like “/etc/hosts”, but it applies to network addresses, and it reverses the order of the names and the IP address on each line

Example:

·  This example sets up two linkages: the “loopback” name to the 127.0.0.0/8 network and “mynet” for the 192.168.7.0/24 network

·  It’s seldom necessary to edit this file

Network Ports

·  Contacting a specific computer is important, but one additional type of addressing is left:

o  Suppose you’re using a Web browser… The Web server computer may be running more servers than just a Web server…it may also be running an email server or an FTP server

o  Another number beyond the IP address enables you to direct traffic to a specific program

o  This number is a network port number, and programs that access a TCP/IP network typically do so through one or more ports

o  NOTE: Port numbers are features of the UDP and TCP protocols. Some protocols such as ICMP, don’t use port numbers

·  When servers start up, they tie themselves to specific ports, which by convention are associated with specific server programs

o  For instance, port 25 is associated with email servers

o  Port 80 is used by Web servers

o  See Table Below for other port numbers:

·  A client can direct its request to a specific port and expect to contact an appropriate server

·  The client’s own port number isn’t fixed; it’s assigned by the OS

o  Because the client initiates a transfer, it can include its own port number in the connection request, so clients don’t need fixed port numbers

o  Assigning client port numbers dynamically also enables one computer to easily run several instances of a single client because they won't compete for access to a single port

Table Below:

Additional Information:

·  Fortunately, for basic functioning, you need to do nothing to configure ports on a Linux system

·  You may have to deal with this issue if you run unusual servers, therefore, because you may need to configure the system to link the servers to the correct ports:

o  This can sometimes involve editing the “/etc/services” file, which maps port numbers to names. . .enabling you to use names in server configurations and elsewhere.

o  See “/etc/services” example file below:

·  The example shown above, consists of lines that begin with a name and end with a port number, including the type of protocol it uses (TCP or UDP)

Configuring Linux for a Local Network:

·  Now that you know something about how networking functions, the question should arise:

o  How do you implement networking in Linux?

o  Most Linux distributions provide you with the means to configure a network connection during system installation

·  In case a networking needs to be setup, what must you do to get the job done:

o  Actual configuration can be done using:

§  either the automatic DHCP tool OR

§  static IP addresses

Network Hardware Configuration:

·  Most fundamental part of network configuration is getting the network hardware up and running

·  In most cases, this task is fairly automatic--most distribution ship with system startup scripts that auto-detect the network card and load the correct driver module

·  If your network hardware isn't correctly detected, though, subsequent configuration won't work

o  To correct this problem, you must load your network hardware driver. .You can do this with the “modprobe” command:

o  # modprobe tulip

§  You must know the name of your network hardware’s kernel module(tulip in this example)

Configuring with DHCP:

·  One of the easiest ways to configure a computer to use a TCP/IP network is to use DHCP, which enables one computer on a network to manage the settings for many other computers

·  Here’s how it works:

o  Computer running a DHCP client boots up

o  It sends a broadcast in search of a DHCP server

o  The server replies(using nothing but the client’s hardware address) with the configuration information the client needs to enable it to communicate with other computers on the network—most important, the client’s IP address and netmask and the network’s gateway and DNS server address

o  The DHCP server may also give the client a hostname and provide various other details about the network

o  The client then configures itself with these parameters

o  The IP address isn’t assigned permanently; it’s referred to as a DHCP lease

o  If it’s not renewed, the DHCP server may give the lease to another computer

o  Therefore, from time to time, the client checks back with the DHCP server to renew its lease

·  3 DHCP clients are in common use on Linux

o  pump

o  dhclient

o  dhcpcd

·  All Linux distributions have a default DHCP client – the one that’s installed when you tell the system you want to use DHCP at system installation time

·  Those that ship with multiple DHCP clients typically enable you to swap out one for another simply by removing the old package and installing the new one

·  Ideally, the DHCP client runs at system bootup, normally handled by it’s own startup script or as part of the main network configuration startup file(typically a startup script called network or networking)

·  The system often uses a line in a configuration file to determine whether to run a DHCP client

o  For instance, Red Hat, Centos, and Fedora set this option in a file called “/etc/sysconfig/network-scripts/ifcfg-name”, where name is the name of the network interface, such as p2p1.

Example: BOOTPROTO=”dhcp”

·  If you need to manually run a DHCP client, you can usually do so by typing its name(as root), optionally followed by a network identifier, such as: dhclient eth0 to have the DHCP client attempt to configure “ eth0 “ with the help of any DHCP server it finds on that network

Configuring with Static IP Address:

·  If a network lacks a DHCP server, you must provide basic network configuration options manually

·  These options can be set using interactive commands… but to set them in the long term, you adjust a configuration file such as: /etc/sysconfig/network-scripts/ifcfg-name OR /etc/network/interfaces

Example “ ifcfg-name ” file, configured to use a static IP address:

·  Several specific items are required, or atleast helpful, for static IP address configuration:

o  IP Address: you can set the IP address manually via the ifconfig command or via the IPADDR item in config file

o  Network Mask: The netmask can be set manually via the ifconfig command or via the NETMASK item in config file

o  Gateway Address: You can manually set the gateway via the route command. .to set it permanently, you need to adjust a config file, which may be the same config file that holds other options or another file, such as /etc/sysconfig/network/routes

§  In either case, the option is likely to be called GATEWAY. The gateway isn’t necessary on a computer that isn’t connected to a wider network – that is, if the computer works only on a local network that contains no routers

o  DNS Settings: In order for Linux to use DNS to translate between IP addresses and hostnames, you must specify at least one DNS server in the “ /etc/resolv.conf “ file

§  Precede the IP address of the DNS server by the keyword “ nameserver “, as in # nameserver 192.168.29.1

§  You can include upto 3 nameserver lines in this file

§  Adjusting this file is all you need to do to set the name server addresses;

§  You can also set your computer’s local domain name in this file using the “domain” option, as in: # domain luna.edu to set the domain to “luna.edu

·  The network config file above may hold additional options, but most are related to others: Example of 8.1 above:

o  DEVICE=”p2p1” (specifies interface name)

o  BOOTPROTO=”static” (tells pc to assign a static IP address)

o  ONBOOT=”yes” (bring up interface when pc boots)

o  NETWORK and BROADCAST (derive from IPADDR and NETMASK, but can be changed if you understand the consequences)

·  The “ifconfig” program is critically important for setting both the IP address and netmask.

·  Example: ifconfig interface up addr netmask mask

·  Real ex: ifconfig eth0 192.168.29.39 netmask 255.255.255.0

o  The following command brings up “eth0” using the address 192.168.29.39 and the netmask 255.255.255.0

o  This command links the specified IP address to the device so the computer responds to the address and claims to be that address when sending data

o  If doesn’t set up a route for traffic beyond your current network…for that, you need to use the “route” command

o  For ex: route add default gw 192.168.29.1

§  Substitute your own gateway address for 192.168.29.1

·  To view interface configuration, issue the following command:

o  # Ifconfig eth0 (see results below)

·  When configured properly, “ifconfig” should show the following:

o  HWaddr

o  Inet addr

o  additional statistics

o  few or no errors, dropped packets or overruns for RX & TX packets

·  Ideally, few(if any) collisions should occur, but some are unavoidable if your network uses a hub rather than a switch

·  If collisions total more than a few percent of the total transmitted and received packets, consider replacing a hub or switch

·  To use “route” for diagnostic purposes, try the following:

o  # route –n (see results below):

·  -n option to route causes it to not attempt to find the hostnames associated with IP addresses.

·  hostnames are often useful, this lookup can be slow or fail altogether if you DNS configuration is broken, so using –n with route is sometimes necessary

·  The above “route” command shows the following:

o  that data destined for 192.168.29.0 (that is any computer with an IP address between 192.168.29.1 and 192.168.29.254) goes directly over eth0

o  the 127.0.0.0 network is a special interface that “loops back” to the originating computer

o  The last line shows the default route, which describes shat to do with everything that doesn’t match any other entry in the routing table. . .this line specifies the default route’s gateway system as 192.168.29.1

§  If it’s missing or misconfigured, some or all traffic destined for external networks, such as the Internet, won’t make it beyond your local network segment

·  The exact location of the configuration files differ from one distribution to another…

Configuring Routing:

·  Routers pass traffic from one network to another

·  You configure your Linux system to directly contact systems on the local network

·  You also give the computer a router’s address, which your system uses as a gateway to the Internet at large

·  Any traffic not destined for the local network is directed at this router, which passes it on to its destination

·  In practice, there are likely to be a dozen or more routers between you and most Internet sites…

·  Each router has at least two network interfaces and keeps a table of rules concerning where to send data based on the destination IP address

·  Your own Linux computer has such a table, but it’s probably very simple compared to those on major Internet routers

·  Linux can function as a router, which means it can link two or more networks together, directing traffic between them on the basis of its routing table

o  This task is handled in part by the “route” command

o  This command can be used to do much more that specify a single gateway system.

·  A simplified version of the “route” syntax:

o  Route {add | del} [-net | -host] target [netmask nm] [gw gw] ß [reject] [[dev] interface]