Linux Networking Services

From Colwiki.org

Revision as of 20:32, 4 July 2009 by Pwest (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

Introduction

This module will cover the implementation of Network configuration in linux including Network Interface Notation, Host configuration, Start and Stop Networking, Routing and Troubleshooting Network connections in Linux Upon completion of this module you will be able to:


Outcomes

  • Configure Linux Network access.
  • Start and Stop Networking Services
  • Configure Linux Routing
  • Troubleshooting Network Connections



Terminologies

Port: In the TCP and UDP protocols used in computer networking, a port is a special number present in the header of a data packet that is used to map data to a particular process running on a computer. Socket: In computer networking, an Internet socket (or commonly, a network socket or socket) is the endpoint of a bidirectional communication flow across an Internet Protocol-based computer network, such as the Internet. Internet sockets (in plural) are an application programming interface (API) in an operating system, used for inter-process communication. Internet sockets constitute a mechanism for delivering incoming data packets to the appropriate application process or thread, based on a combination of local and remote IP addresses and port numbers. Each socket is mapped by the operational system to a communicating application process or thread.



Configuring Linux Networking

The network interface card (NIC) must be supported by the kernel. To determine which card you are using you can get information from dmesg, /proc/interrupts, /sbin/lsmod. or /etc/modules.conf

Dmeg.PNG

Linuxtulip.PNG

Catproc.PNG

Sbin.PNG

From the example above we see that the Ethernet card’s chipset is Tulip, the i/o address is 0xf800 and the IRQ is 10. This information can be used either if the wrong module is being used or if the resources (i/o or IRQ) are not available. This information can either be used to insert a module with a different i/o address (using the modprobe or insmod utilities) or can be saved in /etc/modules.conf (this will save the settings for the next bootup).


Host Information

The following files are used to store networking information.

  • etc/resolv.conf contains a list of DNS servers

nameserver 192.168.1.108

nameserver 192.168.1.1

search linuxit.org

  • /etc/HOSTNAME is used to give a name to the computer
  • One can also associate a name to a network interface. This is done in differently across distributions.
  • /etc/hosts contains your machine's IP number as well as a list of known hosts


Donot.PNG

  • /etc/sysconfig/network defines if networking must be started. (can also contain the HOSTNAME variable)

Networking.PNG

  • /etc/sysconfig/network-scripts/ifcfg-eth0 The configuration parameters for eth0

Device.PNG

Stop and Start Networking

From the command line The main tool used to bring up the network interface is /sbin/ifconfig. Once initialised the kernel module aliased to eth0 in /etc/modules.conf (e.g tulip.o) is loaded and assigned an IP and netmask value. As a result the interface can be switched on and off without loosing this information as long as the kernel module is inserted. Examples: Using ifconfig.

Sbinif.PNG

Sbinifconfig.PNG

Another tool is /sbin/ifup. This utility reads the system’s configuration files in /etc/sysconfig/ and assigns the stored values for a given interface. The script for eth0 is called ifcfg-eth0 and has to be configured. If a boot protocol such as DHCP is defined then ifup will start the interface with that protocol.

Examples: Using ifup.

Sbinifup.PNG

  • Using the network script

At boot time the ethernet card is initialised with the /etc/rc.d/init.d/network script. All the relevant networking files are sourced in the /etc/sysconfig/ directory. In addition the script also reads the sysctl options in /etc/sysctl.conf, this is where you can configure the system as a router (allow IP forwarding in the kernel). For example the line:

net.ipv4.ip_forward = 1 will enable ip forwarding and the file /proc/sys/net/ipv4/ip_forward will contain a one. The network script is started with the following command /etc/rc.d/init.d/network restart

  • Renewing a DHCP lease

The following tools can query the DHCP server for a new IP:

pump

dhcpclient

A client daemon exists called dhcpcd (do not confuse this with the DHCP server daemon dhcpd)

Routing

Add a static route to the network 10.0.0.0 through the device eth1 and use 192.168.1.108 as the gateway for that network:

/sbin/route add -net 10.0.0.0 gw 192.168.1.108 dev eth1

A noticeable difference when using ifup is the system’s routing table. This is because either the /etc/sysconfig/network file is read, where a default gateway is stored, or the DHCP server has sent this information together with the IP number. The routing tables are configured, checked and changed with the /sbin/route tool.

Routing examples:

Add a default gateway:

/sbin/route add default gw 192.168.1.1 eth0

Listing the kernel routing table:

Sbinroute.PNG

Default Gateway:

In the last listing, the Destination field is a list of networks. In particular, 0.0.0.0 means ‘anywhere’. With this in mind, there are two IP’s in the Gateway field. Which one is the default gateway?

To avoid having to enter static routes by hand special daemons gated or routed are run to dynamically update routing tables across a network If you belong to the 192.168.10.0 network and you add a route to the 192.168.1.0 network you may find that machines in the latter network are not responding. This is because no route has been set from the 192.168.1.0 network back to your host!! This problem is solved using dynamic routing.

Permanent Static Routes

If you have several networks with more than one gateway you can use the /etc/sysconfig/static-routes (instead of routing daemons). These routes will be added at boot time by the network script.

A routing scenario:

Routing.PNG

Routing possibility

Routingp.PNG

Common Network Tools

Here is a short list of tools helpful when trouble shouting network connections.

ping host:

This tool sends an ICMP ECHO_REQUEST datagram to a host and expects an ICMP ECHO_RESPONSE.

Options for ping: -b ping a broadcast address -c N send N packets -q quiet mode: display only start and end messages

netstat:

You may get information on current network connections, the routing table or interface statistics depending on the options used.

Options for netstat: -r same as /sbin/route -I display list of interfaces -n don’t resolve IP addresses -p returns the PID and names of programs (only for root) -v verbose -c continuous update

Example: Output of netstat –-inet –n :


► Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 192.168.1.10:139 192.168.1.153:1992 ESTABLISHED

tcp 0 0 192.168.1.10:22 192.168.1.138:1114 ESTABLISHED

tcp 0 0 192.168.1.10:80 192.168.1.71:18858 TIME_WAIT


In the above listing you can see that the local host has established connections on ports 139, 22 and 80.

arp: Display the kernel address resolution cache.

Arp.PNG

Example:

arp

► Address HWtype HWaddress Iface

  192.168.1.71     ether   00:04:C1:D7:CA:2D    eth0

traceroute:

Displays the route taken from the local host to the destination host. Traceroute forces intermediate routers to send back error messages (ICMP TIME_EXCEEDED) by deliberately setting the tty (time to live) value too low. After each TIME_EXEEDED notification traceroute increments the tty value, forcing the next packet to travel further, until it reaches its’ destination.

Example:

CMD:	/usr/sbin/traceroute -n  www.redhat.com

► traceroute: Warning: www.redhat.com has multiple addresses; using 216.148.218.197

traceroute to www.redhat.com (216.148.218.197), 30 hops max, 38 byte packets

-w sec set the timeout on returned packets to sec

1 192.168.1.1 0.440 ms 0.347 ms 0.341 ms

---- snip ---

14 12.122.2.145 112.116 ms 110.908 ms 112.002 ms

15 12.122.2.74 156.629 ms 157.028 ms 156.857 ms

16 12.122.255.222 156.867 ms 156.641 ms 156.623 ms

17 216.148.209.66 159.982 ms 157.462 ms 158.537 ms

18 216.148.218.197 157.395 ms 156.789 ms 156.080 ms


Options for traceroute:

-f ttl change the initial time to live value to ttl instead of 1

-n do not resolve IP numbers

-v verbose



Summary

The primary objective of this module was to give anoverview of the networking capabilities of the Linux operating system. Although one of the strengths of Linux is that plenty of information exists for nearly every component of it, most of this information is focused on implementation. New Linux users, particularly those coming from a Windows environment, are often unaware of the networking possibilities of Linux.

In this module you learned how to configure networking for your Linux box and to troubleshoot your Linux network connections a skill you will oftenly use as a system and network administrator within the Linux Environment



Assignment

  1. In the Routing Scenario section of this chapter give the routing table for the LAN’s gateway.
  2. Start your network interface manually

ifconfig eth0 192.168.0.x List the kernel modules. Make sure that the eth0 module is loaded (check /etc/modules.conf).

  1. Stop the network interface with:

(i) ifconfig eth0 down Verify that you can bring the interface back up without entering new information: (ii) ifconfig eth0 up

  1. Stop the interface and remove the kernel module (rmmod module). What happens if you repeat step 3(ii)?
  1. Divide the class into two networks A (192.168.1.0) and B (10.0.0.0).
  • Try accessing machines across networks

o Choose an existing machine to be the gateway (on either network) o On the gateway machine only! do the following: -- allow IP forwarding:

echo 1 > /proc/sys/net/ipv4/ip_forward

-- bring up an aliased interface (this will work as a second interface). If you are on the 192.168.1.0 network then do the following ifup eth0:1 10.0.0.x (where x is a an available IP). add a route to the new network forcing it to use the eth0:1 device

-- add a route to the other network using the gateway machine (you will need to know either the eth0 or eth0:1 setting of this gw depending on which network you are on)


Image:somerights20.png This work is licenced under a Creative Commons - By Attribution Licence - Share Alike License.

News & Events