Networking in Linux

John F. Moore

Revision History
Revision 1.0 Oct 2012 JFM

Table of Contents

1. Linux Networking Term defined.
2. Intro to Linux Networking
3. How to Configure your network
3.1. Network Manager on Ubuntu
3.2. Networking on the Command line
3.2.1. Is the network connected?
3.2.2. OK I have an IP address do I have a route?
3.2.3. I have a route, do I have a Name Server?
3.2.4. How can I tell if I have any network cards available
3.2.5. How can I set a static IP address for eth0
3.2.6. How can I set a gateway IP address for eth0
3.2.7. How to check if DNS is working
3.2.8. How to check if you can access the internet
3.2.9. Is the gateway computer alive
3.2.10. Who owns that Internet name
3.2.11. How fast is my network connection
4. Example of a Packet transfer
5. Linux Networking Books
5.1. Linux Networking Clearly Explained
5.2. Linux Netorking Cookbook

1. Linux Networking Term defined.

  • IP: An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication. An IP address serves two principal functions: host or network interface identification and location addressing. Its role has been characterized as follows: "A name indicates what we seek. An address indicates where it is. A route indicates how to get there." IP Address
  • IPv4: Internet Protocol version 4 (IPv4) is the fourth revision in the development of the Internet Protocol (IP) and the first version of the protocol to be widely deployed. Together with IPv6, it is at the core of standards-based internetworking methods of the Internet. As of 2012 IPv4 is still the most widely deployed Internet Layer protocol. IPv4 For those of you interested the next generation if IP addresses will be known as IPv6
  • Subnet Mask: A subnetwork, or subnet, is a logically visible subdivision of an IP network.[1] The practice of dividing a network into two or more networks is called subnetting. Subnet Mask
  • DNS: The Domain Name System (DNS) is a hierarchical distributed naming system for computers, services, or any resource connected to the Internet or a private network. It associates various information with domain names assigned to each of the participating entities. A Domain Name Service resolves queries for these names into IP addresses for the purpose of locating computer services and devices worldwide. By providing a worldwide, distributed keyword-based redirection service, the Domain Name System is an essential component of the functionality of the Internet. Domain Name Service
  • Gateway: The Gateway Address (or Default Gateway) is a router interface connected to the local network that is used to send packets out of the local network. Gateway Address
  • Network Interface: A network interface controller (also known as a network interface card, network adapter, LAN adapter and by similar terms) is a computer hardware component that connects a computer to a computer network. Network Interface Controller
  • Wired: A local area network that communicates over a wire, as opposed to a wireless network.
  • Static IP: A fixed IP address as opposed to a Dynamic IP address.
  • Wireless: A wireless local area network (WLAN) links two or more devices using some wireless distribution method (typically spread-spectrum or OFDM radio), and usually providing a connection through an access point to the wider internet. This gives users the mobility to move around within a local coverage area and still be connected to the network. Most modern WLANs are based on IEEE 802.11 standards, marketed under the Wi-Fi brand name. Wireless LAN
  • DHCP: The Dynamic Host Configuration Protocol (DHCP) is a network protocol that is used to configure network devices so that they can communicate on an IP network. A DHCP client uses the DHCP protocol to acquire configuration information, such as an IP address, a default route and one or more DNS server addresses from a DHCP server. The DHCP client then uses this information to configure its host. Once the configuration process is complete, the host is able to communicate on the internet. Dynamic Host Configuration Protocol
  • Wireless Security: Wireless security is the prevention of unauthorized access or damage to computers using wireless networks. The most common types of wireless security are Wired Equivalent Privacy (WEP) and Wi-Fi Protected Access (WPA). WEP is one of the least secure forms of security. A network that is secured with WEP has been cracked in 3 minutes by the FBI.[1] WEP is an old IEEE 802.11 standard from 1999 which was outdated in 2003 by WPA or Wi-Fi Protected Access. WPA was a quick alternative to improve security over WEP. The current standard is WPA2; some hardware cannot support WPA2 without firmware upgrade or replacement. WPA2 uses an encryption device which encrypts the network with a 256 bit key; the longer key length improves security over WEP. Wireless LAN Security

2. Intro to Linux Networking

As a starting point lets review a document from "The Linux Documentation Project" named Introduction to Linux/Networking for our introduction to Linux Networking.

 

When it comes to networking, Linux is your operating system of choice, not only because networking is tightly integrated with the OS itself and a wide variety of free tools and applications are available, but for the robustness under heavy loads that can only be achieved after years of debugging and testing in an Open Source project.

 
  --The Linux Documentation Project Introduction to Linux/Networking

3. How to Configure your network

3.1. Network Manager on Ubuntu

We are going to start by looking at the network manager from Ubuntu 12.04 as a starting point.

Ubuntu Network Manager

This is the opening screen of the network manager. You will notice that we are looking at the page for Wired connections. There are also tabs for Wireless, Mobile Broadband, VPN, and DSL. For this talk we are only going to deal with the wired and part of the wireless tab.

Next lets look at the entry Auto Ethernet when you choose to edit it.

Auto Ethernet Wired Tab

This tab is displaying the Device MAC address:. This is a hardware serial number which is supposed to be globally unique. I say supposed to be because some modems allow you to set the MAC Media Access Control address.

The next item of interest is the MTU. This is a packet size setting, which is normally best left to Automatic because the maximum transmission unit (MTU) is not needed except for some uses by a modem.

Now we will look at the IPv4 page.

Auto Ethernet in DHCP mode

This page is where we specify how the ip address, gateway, DNS, and search domains are set. In this example you will notice the method is set for Automatic (DHCP). By using Dynamic Host Configuration Protocol (DHCP) we let the computer decide what values to use when connecting to the network. This method is convenient when the network routers are set up correctly.

But suppose you want to use fixed values for your network addresses. In many businesses it is common to use fixed IP values for the servers. So here is a page showing the setup for a Static IP.

Static IP configuration page

Let have a look at the items on this page one by one:

  • Method: Manual This specifies that we are going to be entering the values manually.
  • Addresses: This is the section which contains three fields of interest.

    • Address: 192.168.1.28 This is the IP address this computer will use.
    • Netmask: 255.255.255.0 This tells the network how many addresses are use on this Subnetwork.
    • Gateway: 192.168.1.70 This is the computer that allow access to the addresses outside the network. Often this Gateway is the address of the computer that is used to send packets out of the local network.
  • DNS Servers: 192.168.1.10 192.168.1.70 … This is a list of which computers provide Domain Name System (DNS). These addresses are listed in the order of importance.
  • Search domains: lions-wing.net This is the domain of the computer.

3.2. Networking on the Command line

Now we have see how to setup the network when we have a graphical interface. But what happens if we only have a command line.

In this tutorial we will be combining troubleshooting and network configuration so hang on for a wild ride. But first let me say that this is only my take on how to perform the tasks.

I am going to use a series of question and answers because that is the best method I know for troubleshooting network issues. I will assume you have logged into the computer and have a bash shell prompt. I am going to use the devices eth0 for a wired connection and wlan0 for a wireless connection.

3.2.1. Is the network connected?

First step is to check if you have a working connection. To do this we will start by looking for an IP address.

ifconfig eth0

or

ip addr show eth0

will display IP information. If you were looking for a wireless IP address use wlan0 instead of eth0.

3.2.2. OK I have an IP address do I have a route?

Checking for a route to the gateway use

route eth0

or

ip route

3.2.3. I have a route, do I have a Name Server?

cat /etc/resolv.conf

will display the name server information.

3.2.4. How can I tell if I have any network cards available

iwconfig

will display the network cards, especially the wireless cards. In the future the command will be iw list but that does not work yet on my network card.

3.2.5. How can I set a static IP address for eth0

ifconfig eth0 192.168.2.2 netmask 255.255.255.0

or

ip addr add 192.168.2.2/24 dev eth0

will set eth0 to the ip address 192.168.2.2 with a netmask of 255.255.255.0/24.

3.2.6. How can I set a gateway IP address for eth0

route add default gw 192.168.1.70

or

ip route add default via 192.168.1.70

Sets the gateway for the eth0 card to eth0.

3.2.7. How to check if DNS is working

nslookup www.google.com

This command will attempt to convert the name www.google.com to an IP address. If DNS is working you will get back an IP address. If this command fails, you need to assign some nameserver addressed in the field /etc/resolv.conf.

nslookup
server 8.8.8.8
www.google.com

This will attempt to use the name server 8.8.8.8 to look up the IP address of Google. This is google’s name server so we would hope it knows where to find Google.

3.2.8. How to check if you can access the internet

ping -c4 www.google.com
ping -c4 168.100.1.2

The ping command allows you to sent a simple packet to a computer which responds by returning the ping. In the first case you are using a name server to look up www.google.com and then send a ping request. In the second case, you are supplying the IP address so no name server look up is needed.

3.2.9. Is the gateway computer alive

ip route
ping -c4 <ip address of gateway>

This allows you to make sure your computer can talk to the gateway computer. Sometimes DHCP will give you a gateway address which is not active or not in your subnet.

3.2.10. Who owns that Internet name

whois <URL>

When you get a strange link in an email, you can check if the owner of the name is someone you want to talk to. If there is no information available for the URL it is a good bet this is a malware address.

3.2.11. How fast is my network connection

Here are three web sites which can help answer this question

This last site What Is My IP has a number of tools to look up more information on the Web.

4. Example of a Packet transfer

This document GNU/Linux Networking Tutorial for Newbies is a good source of information, although it is detailed.

5. Linux Networking Books

5.1. Linux Networking Clearly Explained

Linux Networking Clearly Explained deals with setting up a Modem and other low level networking issues.

 

Your Linux networking journey starts with the fundamentals— setting up your modem and creating an Internet connection. This chapter fully surveys the knowledge you will need to create such a connection successfully.

 
  --Bryan Pfaffenberger Linux Networking Clearly Explained

This book covers the details needed for PPP, and modem communications. Even though this is no longer needed by most people, it is still of use to some, so I included it here.

5.2. Linux Netorking Cookbook

Linux Networking Cookbook is a how to from O’Reilly

 

So there you are, staring at your computer and wondering why your Internet connection is running slower than slow, and wishing you knew enough to penetrate the endless runaround you get from your service provider. Or, you’re the Lone IT Staffer in a small business who got the job because you know the difference between a switch and hub, and now you’re supposed to have all the answers. Or, you’re really interested in networking, and want to learn more and make it your profession. Or, you are already knowledgeable, and you simply have a few gaps you need to fill. But you’re finding out that computer networking is a subject with reams and reams of reference material that is not always organized in a coherent, useful order, and it takes an awful lot of reading just to figure out which button to push.

 
  --Carla Schroder Linux Networking Cookbook

This book has several interesting chapters, for those of you dealing with sophisticated networking this book has answers and explanations.

Here is a list of the sections in the book.

  1. Introduction to Linux Networking
  2. Building a Linux Gateway on a Single-Board Computer
  3. Building a Linux Firewall
  4. Building a Linux Wireless Access Point
  5. Building a VoIP Server with Asterisk
  6. Routing with Linux
  7. Secure Remote Administration with SSH
  8. Using Cross-Platform Remote Graphical Desktops
  9. Building Secure Cross-Platform Virtual Private Networks with OpenVPN
  10. Building a Linux PPTP VPN Server
  11. Single Sign-on with Samba for Mixed Linux/Windows LANs
  12. Centralized Network Directory with OpenLDAP
  13. Network Monitoring with Nagios
  14. Network Monitoring with MRTG
  15. Getting Acquainted with IPv6
  16. Setting Up Hands-Free Network Installations of New Systems
  17. Linux Server Administration via Serial Console
  18. Running a Linux Dial-Up Server
  19. Troubleshooting Networks